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

diagram of the building described here

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.

4A draft:
4A final:

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).

Emblem class has these methods

Do 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).

4B draft:
4B final:

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

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

4C draft:
4C final: