Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Programming With Java A Problem Solving Approach

Authors: John Dean

3rd International Edition

1260575241, 9781260575248

More Books

Students also viewed these Programming questions