B - The Paint Job Class The Student Painters Company paints dorm rooms . The roo
ID: 3754493 • Letter: B
Question
B - The Paint Job Class
The Student Painters Company paints dorm rooms . The rooms have one window and one door. The room is rectangular. The walls are always 8 feet tall. The doorway is 80 inches tall by 32 inches wide and the window is 4 feet by 5 feet. Student Painters charge $100 for labor plus the cost of the paint to paint a room. A gallon of paint cost $31.95 and will cover 300 square feet. All four walls (minus the window and door) and the ceiling are painted.
Write a PaintJob class to model a paint job for Student Painters.
PaintJob has a constructor that takes the length and width of the room given as doubles (in that order).
public PaintJob(double length, double width) Do not do any calculations in the constructor. Just initialize the instance variables.
Provide these methods:
public double getLength() Gets the length of the room in this PaintJob
public double getWidth() Gets the width of the room to paint
public void setDimensions(double theLength, double theWidth) sets a new length and width for the room
public double getSurfaceArea() Gets the surface area to paint. (Does not include the area of the door or window.)
public double getCostOfPaint() Gets the cost of the paint for the job. Do not calculate surface area in this method. Call getSurfaceArea() Charge for the factional gallons use. The leftover paint can be used on another job
public double getJobCost() Gets the cost of this PaintJob. Do not calculate surface area or the cost of the paint in this method. Call other methods.
You will need to convert the square inches for the door to square feet. There are 144 square inches in a square foot.
Provide Javadoc
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;
public static final double WINDOW_HEIGHT_IN_FEET = 5;
public static final double WINDOW_WIDTH_IN_FEET = 4;
You also need to define and use constants for the cost of labor, the cost of a gallon of paint, and the number of square feet a gallon will cover. Make these constants accessible to any class. (public static final ...)
Don't use any magic numbers in the code.
Explanation / Answer
/**
* @version 1.1 (current version number of program)
* @author (author name)
*/
public class PaintJob {
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;
public static final double WINDOW_HEIGHT_IN_FEET = 5;
public static final double WINDOW_WIDTH_IN_FEET = 4;
public static final double COST_OF_LABOR_IN_DOLLAR = 100.0;
public static final double COST_OF_GALLON_OF_PAINT_IN_DOLLAR = 31.95;
public static final double SQUAR_FEET_PER_GALLON = 300.0;
/**
* The length and width of the dormitory room
*/
private double length;
private double width;
/**
* constructor PaintJob has a constructor that takes the length and width of the room given as doubles
* @param length
* @param width
*/
public PaintJob(double length, double width) {
this.length=length;
this.width=width;
}
/**
* @return the length of the dormitory room
*/
public double getLength() {
return length;
}
/**
* @return the width of the dormitory room
*/
public double getWidth() {
return width;
}
/**
* @param theLength set a new length to the dormitory room
* @param theWidth set a new width to the dormitory room
*/
public void setDimensions(double theLength, double theWidth) {
this.length=theLength;
this.width=theWidth;
}
/**
* Gets the surface area to paint. (Does not include the area of the door or window.)
* @return the surface area of the room; It includes the area of the ceiling and excludes the area of the window and the door
*/
public double getSurfaceArea() {
double areaOfWalls =0.0;
double areaOfCieling =0.0;
double areaOfDoorsAndWindows=0.0;
areaOfCieling = length*width;
areaOfDoorsAndWindows = ((DOOR_WIDTH_IN_INCHES*DOOR_HEIGHT_IN_INCHES)/SQ_INCHES_PER_SQ_FOOT) + WINDOW_HEIGHT_IN_FEET * WINDOW_WIDTH_IN_FEET;
areaOfWalls = WALL_HEIGHT_IN_FEET*2*(length+width) ;
return areaOfWalls-areaOfDoorsAndWindows +areaOfCieling ;
}
/**
* @return the cost of painting the room in dollars
*/
public double getCostOfPaint() {
return (getSurfaceArea()*COST_OF_GALLON_OF_PAINT_IN_DOLLAR)/SQUAR_FEET_PER_GALLON;
}
/**
*
* @return the total cost of painting the room, It includes the cost of the paint and the labor cost combined
*/
public double getJobCost() {
return getCostOfPaint() + COST_OF_LABOR_IN_DOLLAR;
}
/** Main method
* @param args
*/
public static void main(String[] args) {
PaintJob paintJob = new PaintJob(25, 20);
System.out.println(paintJob.getJobCost());
paintJob.setDimensions(30, 25);
System.out.println(paintJob.getJobCost());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.