Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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. BowlingBall - density : double + BowlingBall(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

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

Step: 3

blur-text-image

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

What is the difference between training and development?

Answered: 1 week ago