<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;

/**
 * A classroom with seats arranged in rows and columns for students to sit in,
 * which tracks which students are in the room for contact tracing.
 * 
 * Due to physical distancing rules, capacity limits are strictly enforced.
 * 
 * @author Ted Bauer, Ashneel Das, Lucia Gomez, Shirley Huang, Annabel Lin,
 *         Changyuan Lin, Sam Sorenson, Bryan Tabor, Michael Xing, Vivi Ye
 */
@SuppressWarnings("ALL")
public class Room {

	/**
	 * The number of rows of seats.
	 */
	private final int numRows;

	/**
	 * The number of seats in each row.
	 */
	private final int numCols;

	/**
	 * The number of people currently in the room.
	 * 
	 * &lt;p&gt;
	 * Class Invariant: 0 &lt;= numberOfPeople &lt;= numRows * numCols
	 */
	private int numberOfPeople = 0;

	/**
	 * The names of people seated at each seat in this Room, represented by row,
	 * then by column. Null represents an empty seat.
	 *
	 * &lt;p&gt;
	 * Class Invariant: A row is completely filled before the next is used, and all
	 * empty seats in a row are at the end. &lt;br&gt;
	 * More formally, if people[x][y] == null, then for all z where y &lt; z &lt;
	 * people[x].length, people[x][z] == null, and for all a where x &lt; a &lt;
	 * people.length, people[a][b] == null for all b.
	 * 
	 * &lt;p&gt;
	 * Class Invariant: There are numRows rows, each with numCols seats. &lt;br&gt;
	 * More formally, people.length == numRows and people[x].length == numCols for
	 * all valid x.
	 */
	private String[][] people;

	/**
	 * Constructor: a Room with n rows and m columns of seats.
	 * 
	 * @param n Number of rows of seats
	 * @param m Number of columns of seats
	 * @throws IllegalArgumentException if n or m are negative
	 */
	public Room(int n, int m) {
		if (n &lt; 0 || m &lt; 0) {
			throw new IllegalArgumentException();
		}
		people = new String[n][m];
		numRows = n;
		numCols = m;
	}

	/**
	 * Puts a person in the room.
	 *
	 * @param name The name of the person entering
	 * @throws IllegalStateException if the room is full
	 */
	public void enter(String name) {
		if (numberOfPeople == numRows * numCols) {
			throw new IllegalStateException();
		}
		people[numberOfPeople / numCols][numberOfPeople % numCols] = name;
		numberOfPeople++;
	}

	// TODO: Write documentation for this method
	public boolean isPersonInRoom(String name) {
		for (String[] row : people) {
			for (String person : row) {
				if (person == name) {
					return true;
				}
			}
		}
		return false;
	}

	// TODO: Write documentation for this method
	public void leave(String name) {
		numberOfPeople--;
		for (int i = 0; i &lt; numRows; i++) {
			for (int j = 0; j &lt; numCols; j++) {
				if (people[i][j] == name) {
					people[i][j] = null;
				}
			}
		}
	}

	/**
	 * Move everyone in the current room to another identical room.
	 * 
	 * @return A new Room with all the people from this room.
	 */
	public Room moveToOtherRoom() {

		// Clone this room
		Room newRoom = new Room(numRows, numCols);
		newRoom.people = people.clone();

		// Remove people currently in this room
		for (String[] row : people) {
			Arrays.fill(row, null);
		}

		return newRoom;
	}

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