4A
At Java Inc, we want to sell a large helium balloon printed with the words "Java Rules." It is up to you to figure out what price to charge so that we make $2 profit per balloon. The balloon itself cost $5.50. We buy a tank of helium for $235.00. The tank holds 300 cubic feet.
Write a class HeliumBalloon
public HeliumBalloon
( double theRadius) where radius is given in inches
public void setRadius(double newRadius)
sets the radius to the given valuepublic double getRadius()
gets the radiuspublic double volume(
) gets the volume. (Remember the problem with integer division.)public double costOfGoods()
gets what the balloon costs us to manufacture. Do not put code to calculate volume in this method. Call the volume method to do the calculation for youpublic double retailPrice()
gets the price we will charge the customer. Do not put code to calculate volume or the cost of the goods in this method. Call the costOfGoods method to do that for you.Use these constants:
public static final int CUBIC_INCHES_PER_CUBIC_FOOT = 1728;
public static final double PROFIT = 2.0;
Also define and use constants for PRICE_OF_BALLOON
, PRICE_OF_TANK
, and VOLUME_OF_TANK_IN_CUBIC_FEET
.
Provide Javadoc
For the draft, define the instance variable, the constructor, getRadius, setRadius, and the constants. You should only have one instance variable. Provide Javadoc
Formula for volume of a sphere (in case you need it)
4B
Write an application Vegetable
. (An application has a main method.)
Create a Scanner
object and do the following..
System.out.print("Enter your favorite vegetable: ");
(The vegetable might be more than one word.)System.out.print("On average, how many serving of vegetables do you eat per day?: ");
System.out.print("How many times a week do you eat vegetables?: ");
Only create one Scanner.
For the draft, create the Scanner and do the first three steps.
4C
Write a class StringsRUs
that creates a Scanner
and does the following:
System.out.print("Favorite author? ");
The name may be several wordsHint: To get just the first name, you need to know the index of the first space. You can find the index of the first space with the indexOf method. str.indexOf(" ") will return the index of the first space or -1 if there are no spaces in str. You can assume there is at least one space so you do not need to worry about -1 for this problem. After you find the index of the fist space, you can use substring to get the first name.
For the draft, do the first two steps.