/** House.java -- If we can tile/carpet a room, we may also be interested * in doing an entire house. For the purpose of this program, a house * is just a collection of rooms. * The typical way we'll implement a "list" is by using the built-in * class "ArrayList" from the Java API in the java.util package. * By default, an ArrayList is a list of objects, but in this program, * we know that the list will contain rooms, so we will declare our * list to be of this type: ArrayList * Attributes: ArrayList of rooms * Operations: ability to add a room to the house * compute total cost to tile/carpet the house. */ import java.util.*; public class House { private ArrayList rooms; /** When someone creates a house, it will initially contain an empty * list of rooms. Later, we'll add rooms to the house one by one. */ public House() { rooms = new ArrayList(); } public void addRoom(Room r) { rooms.add(r); } /** findCarpetCost - find the cost to carpet the entire house, * taking as a parameter the rate per square foot. * Simply go thru every room in the house and add up all their * individual costs. * (Note - the 2 statements in the for-loop could be combined.) */ public double findCarpetCost(double rate) { double totalCost = 0.00; for (int i = 0; i < rooms.size(); ++i) { Room r = rooms.get(i); totalCost += r.getCarpetCost(); } return totalCost; } /** findTileCost - this function is analogous to carpet. * (I've decided to write the for-loop body a little differently * so you can see a different way of expressing the same thing.) */ public double findTileCost(double rate) { double totalCost = 0.00; for (int i = 0; i < rooms.size(); ++i) { totalCost += roms.get(i).getTileCost(); } return totalCost; } // to do: toString() }