Question: please include comments Purpose: This lab focuses on inheritance and the use of the super reference. Task: Create a project called Bowling Ball_FirstName_LastName or Lab4_FirstName_LastName.

 please include comments Purpose: This lab focuses on inheritance and the

please include comments

use of the super reference. Task: Create a project called Bowling Ball_FirstName_LastName

Purpose: This lab focuses on inheritance and the use of the super reference. Task: Create a project called Bowling Ball_FirstName_LastName or Lab4_FirstName_LastName. This project will consist of the following files: the Ball class provided on Blackboard as well as the Bowling Ball and Bowling BallDemo classes you will implement. Remember to include comments summarizing the various components of this lab. Bowling Ball - density : double + Bowling Ball(radius : double, color : String, density : double) + setDensity(density : double) : void + getDensity() : double + toString(): String 1. Review the UML class diagram for Bowling Ball. Keep in mind that this class will inherit from the Ball class. 2. In the Bowling Ball class, declare the density field specified in the UML class diagram. Initialize the density to 0. 3. In the Bowling Ball class, write a method definition for each of the four methods specified in the UML class diagram. a. BowlingBall's constructor makes a call to the super class's constructor to set the radius and color fields based on the passed in values for each of those fields. The density field is then set in Bowling Ball's constructor based on the passed in value for density b. The setter sets the density field to the passed in value for density. c. The getter returns the density field. d. The toString method returns the following String given a radius of 10, a color of "purple", and a density of 1.5: The ball is purple and has a radius of 10.0. It also has a density of 1.5. Note that the first sentence is what is returned by the Ball class's toString method. 4. In the Bowling BallDemo class, add the main method for the program. The main method will accomplish the following set of steps: a. Declare three Bowling Ball objects with the following values: all three objects have a radius of 10.8, the colors are red, green, and blue, and the densities are 0.67, 0.99, and 1.33, in that order. b. Print all three objects to the console using the toString method. The following is the expected output from the main method: This ball is red and has a radius of 10.8. It also has a density of 0.67. This ball is green and has a radius of 10.8. It also has a density of 0.99. This ball is blue and has a radius of 10.8. It also has a density of 1.33. public class Ball { private double radius = 0; private String color = null; public Ball(double radius, String color) { this.radius = radius; this.color = color; } public void setRadius(double radius) { this.radius = radius; } public void setColor(String color) { this.color = color; } public double getRadius() { return this.radius; } public String getColor() { return this.color; } public String toString() { return "This ball is " + this.color + " and has a radius of " + this.radius + "."; } }

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 Databases Questions!