Question
Task: Create a project called Inventory_FirstName_LastName or Lab7_FirstName_LastName. This project will consist of two classes: an Item class that you implement as well as the
Task: Create a project called Inventory_FirstName_LastName or Lab7_FirstName_LastName. This project will consist of two classes: an Item class that you implement as well as the Inventory class provided on Blackboard. Remember to include comments in the Item class as well as the relevant parts of the Inventory class.
1. Review the UML class diagram provided above for the Ball class. Keep in mind the inclusion of the equals, copy, and toString methods.
2. In the Ball class, declare the radius and color fields specified in the UML class diagram. Initialize the radius to 0 and the color to null.
3. In the Ball class, write a method definition for each of the eight methods specified in the UML class diagram.
a. The constructor sets the radius to the value of newRadius and the color to the value of newColor.
b. Each of the setters sets the radius and color to the value of newRadius and newColor, respectively.
c. Each of the getters returns the radius and color, respectively.
d. The equals method returns a boolean indicating if the calling object and the passed in object are equivalent. Two Ball objects are considered equivalent if the radius and color are equal.
e. The copy method returns a copy of the Ball object the method is being called on.
f. The toString method returns a String specifying the radius and color of a Ball object. You can use the following output as a reference, assuming this object has a radius of 12.5 and a color of green.
4. In the BallDemo class, add the main method for the program. The main method will accomplish the following set of steps:
a. Construct two objects of the Ball class. The first has a radius of 5.0 and a color of red. The second has a radius of 7.5 and a color of blue.
b. Use two print statements to print the two objects to the console.
c. Use if-ese statements along with the equals method to compare the two objects and print a statement indicating if the two objects are equal or not. Refer to the output at the end of the directions to see an example.
d. Construct another object using the copy method to make a copy of the first object (the one with a radius of 5.0 and a color of red).
e. Use another print statement to print that newly constructed object to the console.
f. Use if-else statements along with the equals method to compare that newly constructed object and the first object (that it is a copy of) and print a statement indicating if the two objects are equal or not.
The following is the expected output from the main method:
Ball -radius: double - color : String + Ball (newRadius : double, newColor : String) + setRadius(newRadius : double) : void + setColor(newColor : String) : void + getRadius() : double + getColor() : String + equals(otherBall : Ball) : boolean + copy(): Ball + toString(): String This ball is red and has a radius of 5.0. This ball is blue and has a radius of 7.5. The balls are not equal. This ball is red and has a radius of 5.0. The balls are equal
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started