Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help I need this code to be done in JAVA The Balloon class Design, code and test a class named Balloon. The class contains: Constants

Help I need this code to be done in JAVA

The Balloon class

Design, code and test a class named Balloon. The class contains:

Constants

-a constant named PI, set to 3.1415926

Instance variables

-an instance variable named color to hold the color of a balloon (e.g. "red", "blue", "yellow")

-an instance variable named size e.g. 12.34

Methods

constructor

-a two parameter constructor that sets a new balloons color and size

inflate()

-takes one parameter. Adds this amount to the size of the balloon

volume()

-calculates and returns the current volume of the balloon. Formula for this is 4/3size3. (HINTS: be careful to avoid rounding error as you translate the formula into Java. And you can use size * size * size for size3)

one more method, give it a clear, meaningful name

-a getter method that returns the color of a balloon

The Tester class

Write a Tester class containing only a single main() method, that must implement the following steps in order:

-use Scanner to read a color from the keyboard (hint: use next())

-then read a size from the keyboard

-create a new Balloon object with these properties

-inflate this balloon by 5.0 units

-output the color of the balloon in the format following. You are required to call a Balloon method as you do this

-output the volume of the balloon, 2 decimal places required, in the format following

As an example, a run of your program would look something like:

Enter color: blue Enter size: 5.5

For the blue balloon Volume is now: 4849.05

Hints

You are writing two new classes named Balloon and Tester.

-identify instance variables and data types

-identify methods, design algorithms, think about parameters and return values

-the Balloon constructor has two parameters. Remember to say the data type for each of these two formal parameters when writing this method. In Tester, to call this constructor, list the two actual parameter values

-(BTW, when creating a new Balloon object manually in BlueJ during testing, the first param to the constructor is a String. You have to type double quotes around the value you enter here e.g. green)

-finish one method before starting the next

Required IMPORTANT

Failure to meet these requirements will cost you points:

-PI must be declared as a constant in the Balloon class

-every class and method you write must have a comment

-again, you are required to call a Balloon method as you output the color of the balloon from Tester

-again, volume must be output to 2 decimal places

-when your program is tested and correct, you must run it for a red balloon of size 99.0 and save these results as your output.txt output file

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

From Zero To Data Hero With Chatgpt

Authors: Andrew Wu

1st Edition

B0CQRJPXD9, 979-8989523009

More Books

Students also viewed these Databases questions