University of Toronto - Fall 2000
Department of Computer Science

Week 6 - Midterm Review

Review for Midterm

1. Given the following Hotel class, fill in the missing methods, as
described.

class Hotel {
	private String name;		// Name of Hotel
	private int numRooms;		// Current number of rooms filled
	private int capacity;		// Number of rooms in hotel
	private double roomRate;	// Daily rate for each room

	public Hotel (String name, double rate, int capacity)  {
		this.name = name;
		this.roomRate = rate;
		this.capacity = capacity;
	}

	// checkIn: this method checks guests into one room in the hotel.
	// It prints an error if all rooms are already filled.
	public




	}

	// checkOut: this method checks guests out of one room in the hotel.
	// It prints an error if there are no rooms currently filled.
	public




	}

	// isVacancy: this method returns 'true' if there is a vacancy in
	// this hotel, otherwise it returns 'false'.
	public




	}

	// getIncome: this method returns how much money the hotel will
	// collect for the currently filled rooms.
	public




	}
}




2. The local bookstore has a special program to increase their sales.
They keep track of each buyer and how many books they have purchased.
Each time a buy makes a book purchase, the the number of bonus points
can be calculated based on how many books they buy.  The buyers can
redeem these bonus points for gifts at any time.

For each purchase, the points are calculated using this formula:
the first three books purchased are worth 2 points each, the next
three books are worth 3 points each, and all books over six are worth
4 points each.

class Buyer {
	private String name;		// Name of book buyer
	private int numBooks;		// Total number of books purchased
	private int points;			// Current number of points

	public Buyer (String name)  {
		this.name = name;
	}

	// purchaseBooks: this method allows this buyer to purchase 
	// 'numBooks' more books.  The bonus points for this purchase are
	// calulated and added to this buyer's current number of points.
	public














	}
	
	// usePoints: this method allows this buyer to use 'pointsToUse' of
	// their bonus points.  Print error if this buyer does not have enough
	// bonus points currently available.
	public








	}
}













3. Draw the Memory Model diagram

class Hotel {
	private Room rm1;		// Hotel room 1
	private Room rm2;		// Hotel room 2

	public Hotel () {
		rm1 = new Room (4);
		rm2 = new Room (2);
	}

	public void checkIn (int roomNumber, int numGuests) {
		if (roomNumber == 1) {
			rm1.checkIn (numGuests);
		} else {
			rm2.checkIn (numGuests);
		}
	}
}

class Room {
	private int numPeople;		// How many people are in the room
	private int maxPeople;		// How many people will the room hold

	public Room (int max) {
		this.maxPeople = max;
		this.numPeople = 0;
	}

	public void checkIn (int num) {
		if (num + numPeople <= maxPeople) {
			numPeople += num;
		} else {
			System.out.println ("Room full");
		}
	}
}

public class Agency {
	public static void main (String[] args) {
		Hotel h = new Hotel ();
		h.checkIn (4, 2);
	}
}