CS46A Spring 18

4A

Create a class SodaCan that represents a soda can. Provide Javadoc comments for the class, every public method, every parameter, and every return value.

A SodaCan has a radius and height measured in inches. It also has a current contents which is the number of fluid ounces currently in the can.

Provide 2 constructors:

When a SodaCan is created, it is filled to capacity, that is, the contents is the volume of the can expressed in fluid ounces.

In the constructor, in addition to initializing the height and radius, you also need to calculate the capacity and initialize the contents to that value.

To calculate the capacity

Provide these accessor methods:

Also provide these methods (the first is a mutator and the second is an accessor):

Use the constants that are defined for you in the starter class

For the draft , provide the three instance variables, the no-argument constructor, the getHeight(), and getRadius() methods. Remember that instance variables should be private.

4A draft:
4A final:

4B

Write an application InputApplication. (An application has a main method.)

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 StringManipulation to create a Scanner and do 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.

For the draft, do the first two steps.

4C draft:
4C final: