/* An "enhanced" Room class -- a room has: length, width, height. * We have 3 different constructors, which makes for greater flexibility when * we want to create a Room object. * Then we have the operations for calculating the cost to paint the room. */ import java.io.*; // tell compiler we'll need I/O public class Room { private double length; private double width; private double height; // Default constructor -- If we want to create a Room object, but don't // specify the size, then we'll ask the user. public Room() throws IOException { BufferedReader kbd = new BufferedReader (new InputStreamReader(System.in)); System.out.print("What is the length of the room (in feet)? "); length = Double.parseDouble(kbd.readLine()); System.out.print("What is the width of the room (in feet)? "); width = Double.parseDouble(kbd.readLine()); System.out.print("What is the height of the room (in feet)? "); height = Double.parseDouble(kbd.readLine()); } // Initial-value constructor -- Just set the room attributes equal to // the values of the parameters coming in. public Room(double l, double w, double h) { length = l; width = w; height = h; } // Copy constructor. Create a room object exactly like an existing one // called "r". public Room(Room r) { length = r.length; width = r.width; height = r.height; } // Finally, operations to help us find the cost to paint the room. public double getAreaWalls() { return 2.0 * (length * height + width * height); } public double getAreaCeiling() { return length * width; } public double getCost() { return 0.03 * getAreaWalls() + 0.05 * getAreaCeiling(); } }