4A
The Wallpaper Pros company hangs wallpaper in small offices. The offices have one door and no window. Each office is rectangular. The walls are always 8 feet tall. The door way is 80 inches tall by 32 inches wide. A roll of wallpaper costs $40 and is 27 inches wide 33 feet long. Wallpaper Pros charges $1.10 per square foot for labor plus the cost of the paper. All four walls (minus the door) and the ceiling are covered with wallpaper.
Write a WallpaperJob
class to model a wallpapering job for Wallpaper Pros
WallpaperJob
has a constructor that takes the length and width of the room (in that order).
public WallpaperJob(double length, double width)
Do not do any calculations in the constructor. Just initialize the instance variables. Do not use unnecessary instance variables to store the result of the methods.Provide these methods:
public double getLength()
Gets the length of the room in this WallpaperJob
public double getWidth()
Gets the width of the room to wallpaperpublic void setDimensions(double theLength, double theWidth)
sets a new length and width for the roompublic double getArea()
Gets the area to wallpaper. (All four walls (minus the door) plus the ceiling) public double getCostOfWallpaper()
Gets the cost of the wallpaper for the job. Do not calculate area of the room in this method. Call getArea()
public double getJobCost()
Gets the cost of this WallpaperJob
. Do not calculate area or the cost of the wallpaper in this method. Call other methods in the class.Provide Javadoc
You will need to convert the square inches to square feet. There are 144 square inches in a square foot. You must use a constant.
Here are some constants you must use
public static final int SQ_INCHES_PER_SQ_FOOT = 144;
public static final double WALL_HEIGHT_IN_FEET = 8;
public static final double DOOR_HEIGHT_IN_INCHES = 80;
public static final double DOOR_WIDTH_IN_INCHES = 32;
You also need to define and use constants for the number of inches in a foot, the cost of labor per square foot, the cost of a roll of wallpaper, and the width and length of the roll of paper.. Make these constants accessible to any class. (public static final ...) Don't use any magic numbers in the code.
For the draft, define the constants and instance variables. Write the constructor and the setDimensions
, getLength
and getWidth
methods. Provide Javadoc for these methods and constructor and the class itself.
4B
Write an application WallpaperJobInvoice
. (It will have a main method.) WallpaperJobInvoice
will print an invoice for a wallpaper job from 4a.
WallpaperJob
using the class you wrote in 4a using the length and width the user enteredFor the draft, do steps 1,2. 6, and 7
For the final, you will need to submit WallpaperJob again here, but do not make any changes to it.
4C
Updated instructions 9/15
Write an application StringsAndThings
. (It will need a main method.)
Create a Scanner
object and do the following.
Hint: 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. After you find the index of the fist space, you can use substring to get the first name.
Only create one Scanner
.
For the draft, create the Scanner and do the first three steps