Question: Write the class, Potion.java following this UML Diagram and doing the following: Potion -name: String -strength: double +Potion() +Potion(name: String, strength: double) +getName(): String

Write the class, Potion.java following this UML Diagram and doing the following:

Write the class, Potion.java following this UML Diagram and doing the following: Potion -name: String -strength: double +Potion() +Potion(name: String, strength: double) +getName(): String +getStrength(): double +setName(name: String) +setStrength(strength: double) +toString(): String +validStrength(strength: double): boolean +equals(p: Potion): boolean 1. Create two instance variables, name (a String) and strength (a double). 2. Write the default constructor. 3. Write the non-default constructor. 4. Write two accessor methods, one for each instance variable. 5. Write two mutator methods, one for each instance variable. 6. Write a method that will return the entire as a single string (the toString method). 7. Write a method that will return true if the strength is between 0 and 10. 8. Write a method that will compare this instance to another Potion (the equals method). 9. Now write an application class that instantiates two instances of Potion. One instance should use the default constructor and the other should use the non-default constructor. Display the values of each object by calling the toString method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!