CS46A Fall 18

4A


You have all probably seen a snow globe - a glass ball containing a winter scene and filled with a liquid and white particles. When turned upside down, the white particles float to the bottom. When turned right-side up again, the particles drift down looking like snow.

a snow globe

Write a class SnowGlobe to model this behavior. There is no starter file but there is a tester

20% of the volume of the object will be filled with white particles while 50% will be filled with a liquid. The other 30% is the things in the scene.

The snow costs $1.25 per cubic centimeter

Provide 2 constructors. Both constructors have the same name, SnowGlobe. The compiler tells them apart because they have different parameter lists. This is called overloading):

It has methods

Define and use constants for the percent and the cost per cubic centimeter of the snow. That means you should not hard code .20 or 1.25 in the methods. you should use constants. Define them as class constants at the top of the class with the instance variables.

Provide Javadoc for the class, the constructor and methods

Formulas
Volume of a Sphere: v = 4/3 π r3 Use the constant from the Math class for pi. (Caution: remember about integer division. What is 4/3?)

For the draft , provide the instance variable, the no-argument constructor, the setRadius(), and getRadius() methods. Remember that instance variables should be private. Provide the Javadoc.

4A draft:
4A final:

4B

Complete the application InputApplication.

Create a Scanner object and do the following..

Only create one Scanner.

For the draft, create the Scanner and do the first three steps.

4B draft:
4B final:

4C

Write a class StringStuff which creates a Scanner and then does the following:

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.

There is no starter file

For the draft, do the first three steps.

4C draft:
4C final: