Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: Create a project called LabBall Add 2 files: Ball.java and BallApp.java ( BallApp.java includes the main method ) Once you added the appropriate class

image text in transcribed

Description:

Create a project called LabBall

Add 2 files: Ball.java and BallApp.java ( BallApp.java includes the main method )

Once you added the appropriate class headers with empty class body and the empty main method compile and run to ensure that the project is set up properly

In Ball.java implement class Ball as described above

Implement input validation in the setter. Only allow the size of the ball to be >= 0. If the size passed as an argument is negative, leave the field value unchanged (no action required).

Method roll should print rolling . . .

Method bounce should print how often the ball is bouncing depending on the parameter value g. bouncing 3 times or bouncing 1 times (yes, there is a grammar mistake. No need to worry about it. If you like a challenge though, feel free to remove the extra 's') Hint: this is a fill-in-the-blank situation and you can use printf to display the desired output

In BallApp.java in the main method do the following

Create an instance of Ball called myBall. It should have size 5

Print the size of the ball (use a label)

Make the ball roll

Make the ball bounce 14 times

Increase the size of the ball to size 7

Print the size of the ball (a second time)

Notice: The size is printed twice. First we used the label "Ball with size " and then we used just "size: ". Labels are used to make the output clear and easy to read and understand. In the first line we included the information that the size we are displaying is the size of a ball. In the last line this information was no longer helpful and thus dropped.

Expected Output: Ball with size 5 rolling . . . bouncing 14 times size: 7

What is the code for this?

Ball - size: double + getSize 0 double + setSize (s: double) +roll + bounce (numberOfBounces: int)

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

Describe three standard therapies for cancer treatment?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago