/** 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 add(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. */ public double findCarpetCost(double rate) { double totalCost = 0.00; for (int i = 0; i < rooms.size(); ++i) { totalCost += rooms.get(i).findCarpetCost(rate); } return totalCost; } /** findTileCost - this function is analogous to carpet. */ public double findTileCost(double rate) { double totalCost = 0.00; for (int i = 0; i < rooms.size(); ++i) { totalCost += rooms.get(i).findTileCost(rate); } return totalCost; } }