Remember not to create packages. Use the default package
5A
You have a business painting the insides of planetariums with a special, expensive paint. A planetarium is a circular room with a domed roof (a hemisphere) You charges $95.50 a gallon for paint and a gallon will cover 40 square feet. (If we need a fractional gallon of paint, we only charge for what we use since we can use the remainder on another job)
You paint both the cylinder and the hemisphere.
You charge $100 per square yard for labor plus the cost of the paint.
Your job in this program is to finish the class, PaintJob
which can be used to calculate the price you need to charge the customer.
The constructor takes the height and radius of the cylindrical part of the room as parameters in that order. (Call them height and radius so the provided methods will work)
You will write methods:
public void setHeight(double theHeight)
- providedpublic void setRadius(double theRadius)
- providedpublic double getSurfaceArea()
- get the surface area to paint, cylinder and domepublic double getPaintCost()
- you must use the getSurfaceArea
method in this calculation. Only calculate surface area once in the codepublic double getLaborCharge()
- you must use the getSurfaceArea
method in this calculation. Only calculate surface area once in the codepublic double getCustomerPrice()
- you must use the other methods in this calculation. Only calculate surface area, paint cost, and labor in one placeProvide Javadoc for the class, the constructor, every method, every parameter and every return value..
Declare and use constants for the price of a gallon of paint, the number of square feet it will cover, and the price you charge per square yard as constants.
Declare a constant using public static final ...
Notice you will need to convert units from square feet to square yards to calculate the labor cost. Use the constant provided in the starter file.
5B
Stamps R Us makes rubber stamps consisting of a person's initials. You are to write a class Stamp
. A Stamp
has instance variables of a first name, middle initial (one letter. No period), and last name.
There is no starter file. You will write the whole class.
The Stamp
class has two constructors (This is called overloading).
public Stamp(String theFirst, String theMiddleInitial, String theLast)
initializes the instance variables with the values of the parameters. (theMiddleInitial will be exactly 1 character long)public Stamp(String theFirst, String theLast)
initializes the first and last names to the given parameters and initializes the middle initial to the empty String (two double quotes with no space like this "")Stamp
class has these methods
public String getFirst()
public String getMiddleInitial()
public String getLast()
public int characterCount()
the number of characters in the full name - not counting spacespublic String getInitials()
gets the initials comprising the Stamp (first initial, middle initial, last initial) with no spacesDo not use an if statement. You do not need it.
Provide full Javadoc (the class, the constructors, and the methods)
5C
Write a class AmazonOrder
which keeps track of the items a person orders on Amazon. We want to be able to add an item of a specific cost and remove an item of a specific cost. We also want to able able to get the subtotal, total and a string representation of the contents of the AmazonOrder
AmazonOrder
has a no-argument constructor which initializes the instance variables (subtotal to 0, contents to the empty string)
It has the following methods:
public void add(double cost)
adds this cost to the subtotal for this AmazonOrder
and records the item added in the contents (see below)public void remove(double cost)
subtracts this cost from the subtotal for this AmazonOrder
and records the item removed in the contents (see below)public double getSubtotal()
gets the subtotal for this AmazonOrder
getTotal()
Gets the total which is the subtotal plus tax. The tax is 8.5%. Define 8.5 as a constant in the method. (not as an instance variablegetContents()
returns the string representation of the cost of the items added to and removed from in the order and the total cost. Be sure to call getTotal(). Do not calculate the total in this method.reset()
returns the object to its original state where no items are in the order. The string representing the items in the order will be set to the empty string and the subtotal will be set to 0To add to the order: add the string Add Item or Remove Item, a colon, a space, and then the value of the transaction and a newline
The format of the string returned by getContents
:
Add Item: 2.59
Add Item: 8.25
Remove Item: 2.59
Total: 8.95125
The total is displayed at the end.
NOTE: I should get the same output if I call getContents() twice in a row.
You need to provide a Javadoc comment for your all methods, the constructor and the class itself.