Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Room class (see Room.java) represents a room in a building. The instance variables (see below) associated with this class are capacity (maximum number of

The Room class (see Room.java) represents a room in a building. The instance variables (see below) associated with this class are capacity (maximum number of occupants in a room) and occupants (names of persons that are in the room). You can assume names are unique. We provided a toString() method for this class; do not modify it.

Room.java

public class Room implements Comparable { private int capacity; private ArrayList occupants;

/* * Initializes the capacity with the parameter value * and creates an ArrayList of string references */ public Room(int capacity) { throw new UnsupportedOperationException("Implement this method"); }

/* * Adds the specified name to the occupants ArrayList if the maximum capacity has * not been reached. If the name is added the method returns true; if the maximum * capacity has been reached, the method returns false (and no name is added). If * the name already exists, the name is not added and the method will return false. * The method will throw an IllegalArgumentException (with any error message) if the * parameter is null or blank according to the String class method isBlank(). */ public boolean addOccupant(String name) { throw new UnsupportedOperationException("Implement this method"); }

/* * Get method for capacity. */ public int getCapacity() { throw new UnsupportedOperationException("Implement this method"); }

/* * Copy constructor. Changes to the copy should not affect the original. */ public Room(Room room) { throw new UnsupportedOperationException("Implement this method"); }

/* * Get method for occupants that returns a copy of the occupants ArrayList */ public ArrayList getOccupants() { throw new UnsupportedOperationException("Implement this method"); }

/* * Returns the number of occupants (names added to the occupants ArrayList). */ public int getNumberOfOccupants() { throw new UnsupportedOperationException("Implement this method"); }

/* * The Room class implements the Comparable interface. The compareTo method will * return a negative value if the number of occupants in the current object is * less than the parameter, 0 if they are the same, and positive otherwise */ public int compareTo(Room room) { throw new UnsupportedOperationException("Implement this method"); }

/* * Implement the equals method where two rooms are considered the same if they have the * same number of occupants and the same occupants. The occupants can appear in any order * in the occupants ArrayLists. For example, if room1 added two occupants, Rose, Mike * (in that order) and room2 added Mike, Rose (in that order), the rooms are considered * equal. You can use any String class methods. */ public boolean equals(Object obj) { throw new UnsupportedOperationException("Implement this method"); }

/* Provided: Do not modify */ @Override public String toString() { String answer = "Capacity: " + capacity + ", ";

return answer += "Occupants: " + occupants; } }

StudentTest.Java

@Test public void test() { fail("Not yet implemented"); }

SampleDriverRoom.java

public class SampleDriverRoom {

public static void main(String[] args) { StringBuffer results = new StringBuffer(); int capacity = 10; Room roomOne = new Room(capacity); roomOne.addOccupant("Diana"); roomOne.addOccupant("Alejandro"); roomOne.addOccupant("Sierra"); results.append(roomOne).append(" "); results.append("Capacity: " + roomOne.getCapacity() + " "); results.append("Occupants: " + roomOne.getOccupants() + " "); results.append("Number of Occupants: " + roomOne.getNumberOfOccupants()); System.out.println(results); } }

Output

Capacity: 10, Occupants: [Diana, Alejandro, Sierra] Capacity: 10 Occupants: [Diana, Alejandro, Sierra] Number of Occupants: 3

Thank you I will thumbs up just need student test that test each method and room java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

\(x

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago