In: Computer Science
This is the Painting.javasource file for you to modify (bluelines are my additions):
public class Painting
{
public static void main(String[] args)
{
double width, length, wallArea, ceilingArea;
final double HEIGHT = 8;
System.out.println("Calculation of Paint Requirements");
System.out.print("Enter room length: ");
length = Keyboard.nextDouble();
// these 2 lines will make a nice function, promptDouble,
// then replace those 2 lines with this single line:
// length = promptDouble("Enter room length: ");
System.out.print("Enter room width: ");
width = Keyboard.nextDouble();
// these 2 lines should be replaced in the same way:
// width = promptDouble("Enter room width: ");
wallArea = 2 * (length + width) * HEIGHT; // ignore doors
// this line should use a perimeterfunction instead, as in:
// wallArea = perimeter(length, width) * HEIGHT;
ceilingArea = length * width;
// this line should use a new function called area,
// similar to perimeter, like so:
// ceilingArea = area(length, width);
System.out.println("The wall area is " + wallArea +
" square feet.");
System.out.println("The ceiling area is " + ceilingArea +
" square feet.");
}
}
Your job in this Lab is to write these three functions and make the above changesin the Java program Painting.java.
import java.util.Scanner; public class Painting { public static Scanner Keyboard = new Scanner(System.in); public static double promptDouble(String s) { System.out.print(s); return Keyboard.nextDouble(); } public static double perimeter(double length, double width) { return 2 * (length + width); } public static double area(double length, double width) { return length * width; } public static void main(String[] args) { double width, length, wallArea, ceilingArea; final double HEIGHT = 8; System.out.println("Calculation of Paint Requirements"); length = promptDouble("Enter room length: "); width = promptDouble("Enter room width: "); wallArea = perimeter(length, width) * HEIGHT; ceilingArea = area(length, width); System.out.println("The wall area is " + wallArea + " square feet."); System.out.println("The ceiling area is " + ceilingArea + " square feet."); } }