This repository has been archived on 2026-10-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-03-11 12:33:03 -07:00

35 lines
936 B
Java

import java.util.ArrayList;
public class OccupancyInfo
{
private ArrayList<Room> rooms;
// no two Room objects in rooms have the same room number
/** Returns an ArrayList containing the number of every room which is not occupied
* in the order in which these appear in the ArrayList rooms.
*/
public ArrayList<Integer> availableRoomNumbers()
{
/* Implement your answer to part (b) here */
ArrayList<Integer> result = new ArrayList<Integer>();
for(Room room : rooms) {
if(!room.isOccupied()) {
result.add(room.getNumber());
}
}
return result;
}
/* Methods for previous parts of this question are not shown */
/* CLASS MEMBERS FOR TESTING */
/* DO NOT MODIFY ANY OF THE CONSTRUCTORS OR METHODS BELOW*/
public OccupancyInfo(ArrayList<Room> r)
{ rooms = r; }
public ArrayList<Room> getRooms()
{ return rooms; }
}