Add files via upload

This commit is contained in:
Aesthetiful authored and GitHub committed 2024-03-11 12:33:03 -07:00
1 parent 1e19e7f773
commit 943f152ce6
12 files changed
+377 -170

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import java.util.ArrayList;
public class OccupancyInfo
{
private ArrayList<Room> rooms;
// no two Room objects in rooms have the same room number
/** Attempts to check-in a new guest into a given room number. If a room exists in
* the database with the room number requested, and the room is unoccupied, a guest
* with the name given is checked-in to that room: the room is marked as occupied,
* and the guestName variable in the Room object is set to the name given.
* @param name the name of the guest attempting to check-in
* @param number the room number into which the guest is to be checked-in
* @return -1 if no room with the requested number exists;
* 0 if the room requested is occupied;
* 1 if the check-in is successful
*/
public int checkIn(String name, int number)
{
/* Implement your answer to part (a) here */
for(Room room : rooms) {
if(room.getNumber() == number) {
return room.checkInNewGuest(name) ? 1 : 0;
}
}
return -1;
}
/* Methods for subsequent 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; }
}
+48
View File
@@ -0,0 +1,48 @@
/* COMPLETE WORKING CLASS PROVIDED */
/* DO NOT MODIFY THE IMPLEMENTATION OF THIS CLASS*/
public class Room
{
private int roomNumber;
private boolean occupied;
private String bookingName;
/** Attempts to check a new guest into the room. If the room is not occupied (the
* variable occupied is false), changes bookingName to name and sets
* occupied to true.
* Otherwise does not change the values of the member variables.
* @param name the name of the guest checking in as a String
* @return true if the check-in was successful and bookingName was changed
* false otherwise
*/
public boolean checkInNewGuest(String name)
{
if(occupied) return false;
bookingName = name;
occupied = true;
return true;
}
/** @return the room number
*/
public int getNumber()
{ return roomNumber; }
/** @return true if the room is occupied; false otherwise.
*/
public boolean isOccupied()
{ return occupied; }
public Room (int rn, boolean o, String bn){
roomNumber = rn;
occupied = o;
bookingName = bn;
}
public String toString(){
return roomNumber+"; "+occupied+"; "+bookingName;
}
}
+35
View File
@@ -0,0 +1,35 @@
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; }
}
+48
View File
@@ -0,0 +1,48 @@
/* COMPLETE WORKING CLASS PROVIDED */
/* DO NOT MODIFY THE IMPLEMENTATION OF THIS CLASS*/
public class Room
{
private int roomNumber;
private boolean occupied;
private String bookingName;
/** Attempts to check a new guest into the room. If the room is not occupied (the
* variable occupied is false), changes bookingName to name and sets
* occupied to true.
* Otherwise does not change the values of the member variables.
* @param name the name of the guest checking in as a String
* @return true if the check-in was successful and bookingName was changed
* false otherwise
*/
public boolean checkInNewGuest(String name)
{
if(occupied) return false;
bookingName = name;
occupied = true;
return true;
}
/** @return the room number
*/
public int getNumber()
{ return roomNumber; }
/** @return true if the room is occupied; false otherwise.
*/
public boolean isOccupied()
{ return occupied; }
public Room (int rn, boolean o, String bn){
roomNumber = rn;
occupied = o;
bookingName = bn;
}
public String toString(){
return roomNumber+"; "+occupied+"; "+bookingName;
}
}