4A
Java Builders, Inc. provides prefabricated buildings in different sizes shaped like the image below. Each building consists of a cube adjacent to a rectangular solid.
The smaller yellow cube has a side of x
The larger red rectangular solid has dimensions of 2x, x, and x
One thing we want to know is how much it costs to paint the building. Paint cost $32.27 per gallon. A gallon of paint covers 400 square feet of exterior wall.
Complete the JavaBuilding class.
A JavaBuilding has a constructor that takes the side of the cube (x in the diagram) as a parameter.
It has the following methods
public double getSurfaceArea() Gets the exposed surface area that will need to be painted. The top has solar panels. The bottom is on the ground so the top and bottom do not need paint. Also there is no paint on the area where the two parts of the building touch.public double getCost()Gets the cost of painting the building. Do not calculate the surface area here. Call the getSurfaceArea method.public void increaseSide(double amount) increases the value of the side of the square by a given amount - The shape always maintains the same proportions Provide Javadoc.
Provide constants for price per gallon and square foot coverage. You would define a constant for square foot coverage like this
public static final int SQUARE_FEET_PER_GALLON = 400;
For the draft: Write the constructor to initialize the instance variable. Do not use unnecessary instance variable. Code the methods as stubs. Supply Javadoc. Remember that the Javadoc of a stub describes what will be returned in the final version not the draft.
4B
Things like towels, shirts, and glassware are often personalized with a person's initials (emblem). You are to write a class Emblem. An Emblem 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 Emblem class has two constructors (This is called overloading).
public Emblem(String theFirst, String theMiddleInitial, String theLast) initializes the instance variables with the values of the parameters. (theMiddleInitial will be exactly 1 character long)public Emblem(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 "")Emblem 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 getFullName() gets the full name with spaces separating the names. Note: When the there is no middle initial, there will be 2 spaces between first and last name. That is okay.public String getEmblem() gets the initials comprising the Emblem (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)
To get the first letter of a string word use charAt (not substring)
char firstLetter = word.charAr(0);
For the draft, provide the instance variables, the first constructor and implement getFirst, getMiddleInitial, and getLast methods. Include the Javadoc for the implemented elements (class, constructor, and the three methods).
4C
You are going to enhance the ShoppingCart from last homework1. Add the functionality needed to keep track of the items in the cart and to calculate the total cost including tax. Provide methods to return the string representation of the items in the cart and the total.
You will need a String instance variable (perhaps called contents). Be sure to initialize it in the constructor to the empty string
You will need to modify the add and remove methods to record the action. To add a line to the contents, form a String consisting of the word "Add Item: " + cost + "\n". Concatenate the new string to the end of the current contents. (Notice the newline character at the end)
Add the following methods
getTotal() Gets the total which is the subtotal plus tax. The tax is 8.5%. Define 8.5 as a constant in the method.getContents() returns the string representation of the cost of the items in the cart 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 cart. The string representing the items in the cart will be set to the empty string and the subtotal will be set to 0 The format of the string returned by getContents
Add Item: 2.59
Add Item: 8.25
Remove Item: 2.59
Total: 8.95125
Notice this prints either Add Item or Remove Item, a colon, a space, and then the cost for each transaction and displays the total at the end. I should get the same output if I call getContents() twice in a row.
1If you do not have a good working version of ShoppingCart from the earlier homework, you can use the code in the solution posted in Canvas
You need to provide a Javadoc comment for your new methods.
For the draft, provide the getTotal method and its Javadoc