<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.Arrays;

/**
 * &lt;p&gt;
 * An instance maintains the length and width of an office hours room in Rhodes
 * Hall as well as the students in the room.
 * &lt;/p&gt;
 * 
 * &lt;p&gt;
 * Adapted from a CS 2110 recitation exercise. Please note that 2110 uses
 * different style and documentation guidelines from 2112. This class is not
 * necessarily an example to be emulated in your own assignments.
 * &lt;/p&gt;
 * 
 * @author David Gries (CS 2110) and staff
 * @author Ashneel Das, Lucia Gomez, Sam Sorenson, Michael Xing, Vivi Ye
 */
public class Room {
	/**
	 * Class Invariant: The length of the room. If the room is square, this is also
	 * the width.
	 */
	private Double length;
	/**
	 * Class Invariant: The width of the room if the room is a rectangle. If the
	 * room is a square, width should be null.
	 */
	private Double width;
	/**
	 * A counter representing the number of people currently in the room
	 */
	private int numberOfPeople = 0;
	/**
	 * The names of people in this Room. Null represents an empty spot in the room.
	 */
	private String[] people;

	/**
	 * Constructor: a Room with length l and width w.
	 * 
	 * @param l Length of the room
	 * @param w Width of the room
	 * @param n Capacity of the room
	 * @throws IllegalArgumentException if length, width, or capacity is negative
	 */
	public Room(double l, double w, int n) {
		if (l &lt; 0 || w &lt; 0 || n &lt; 0) {
			throw new IllegalArgumentException();
		}
		length = l;
		width = w;
		people = new String[n];
	}

	/** = the length of the Room */
	public double getLength() {
		return length;
	}

	/** = the width of the Room */
	public double getWidth() {
		if (length == width) {
			// Class invariant broken
			throw new IllegalStateException();
		} else if (width == null) {
			return length;
		}
		return width;
	}

	/**
	 * Puts a person in the room
	 *
	 * @param name the name of the person entering
	 */
	public void enter(String name) {
		people[numberOfPeople] = name;
		numberOfPeople++;
	}

	/**
	 * Removes a person from the room
	 * 
	 * @param name the name of the person leaving (or getting kicked * out of) the
	 *             room
	 */
	public void leave(String name) {
		numberOfPeople--;
		for (int i = 0; i &lt; people.length; i++) {
			if (people[i] == name) {
				people[i] = null;
			}
		}
	}

	/**
	 * Check if a person is in the room
	 * 
	 * @param name The name of the person
	 * @return Whether they are in the room
	 */
	public boolean isPersonInRoom(String name) {
		for (String s : people) {
			if (s == name) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Return a copy of this room
	 * 
	 * @return A copy of this room
	 */
	private Room copy() {
		Room r = new Room(length, width, people.length);
		r.people = people;
		return r;
	}

	/**
	 * Move everyone in the current room to a bigger office hours room.
	 * 
	 * @return a new Room with each dimension twice of this room and all the people
	 *         from this room.
	 */
	public Room moveToBiggerRoom() {

		// Clone this room
		Room newRoom = this.copy();

		// Increase its size
		newRoom.length = length * 2;
		if (width != null) {
			newRoom.width = width * 2;
		}

		// Remove people currently in this room
		Arrays.fill(people, null);

		return newRoom;
	}

}
</pre></body></html>