Running PaintJobTester.java
Surface Area: 4398.23 Expected: 4398.23 Paint Cost: 10500.77 Expected: 10500.77 Labor: 48869.22 Expected: 48869.22 Total: 59369.99 Expected: 59369.99 Total: 29685.00 Expected: 29685.00
CheckStyle
PaintJob.java:
Okpass
Student files
PaintJob.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | /**
* Describes a PaintJob of a cylindrical room
* with a domed roof
*
*/
public class PaintJob
{
//add instance variables
private double height;
private double radius;
private double surfaceArea;
public static final int SQ_FT_PER_SQ_YARD = 9;
//add other constants
public static final double COST_PER_GALLON_OF_PAINT = 95.5;
public static final double SQUARE_FEET_PER_GALLON = 40;
public static final double LABOR_COST_PER_SQUARE_YARD = 100.0;
//add constructor
/**
* Construcs a PaintJob wihthe given height and radius
* @param theHeight the height of the cylinder
* @param theRadius the radius of the sphere
*/
public PaintJob(double theHeight, double theRadius)
{
height = theHeight;
radius = theRadius;
}
//add required methods
/**
* Gets the surface area of te room to paint
* @return the surface area of te room to paint
*/
public double getSurfaceArea()
{
surfaceArea = 2 * Math.PI * radius * height + 2 * Math.PI * radius * radius;
return surfaceArea;
}
/**
* Gets the cost of the paint for this paint job
* @return the cost of the paint for this paint job
*/
public double getPaintCost()
{
surfaceArea = 2 * Math.PI * radius * height + 2 * Math.PI * radius * radius;
double paintCost = surfaceArea
/ SQUARE_FEET_PER_GALLON * COST_PER_GALLON_OF_PAINT;
return paintCost;
}
/**
* Gets the cost of the labor for this PaintJob
* @return the cost of the labor for this PaintJob
*/
public double getLaborCharge()
{
double squareYards = getSurfaceArea() / SQ_FT_PER_SQ_YARD;
return squareYards * LABOR_COST_PER_SQUARE_YARD;
}
/**
* Gets the price to charge the customer
* @return the price to charge the customer
*/
public double getCustomerPrice()
{
return getPaintCost() + getLaborCharge();
}
/**
* sets a new height for room in this paint job
* @param theHeight the new height
*/
public void setHeight(double theHeight)
{
height = theHeight;
}
/**
* sets a new radius for room in this paint job
* @param theRadius the new radius
*/
public void setRadius(double theRadius)
{
radius = theRadius;
}
}
|
Provided files
PaintJobTester.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/**
* Tester for the PainJob class
*/
public class PaintJobTester
{
public static void main(String[] args)
{
//arguments are height then radius
PaintJob job1 = new PaintJob(15.0, 20.0);
System.out.printf("Surface Area: %4.2f\n",job1.getSurfaceArea());
System.out.println("Expected: 4398.23");
System.out.printf("Paint Cost: %4.2f\n",job1.getPaintCost());
System.out.println("Expected: 10500.77");
System.out.printf("Labor: %4.2f\n",job1.getLaborCharge());
System.out.println("Expected: 48869.22");
System.out.printf("Total: %4.2f\n",job1.getCustomerPrice());
System.out.println("Expected: 59369.99");
job1.setRadius(10.0);
job1.setHeight(25.0);
System.out.printf("Total: %4.2f\n",job1.getCustomerPrice());
System.out.println("Expected: 29685.00");
}
}
|
Score
6/6