(Solved) : Object Oriented Java Java Programming Language Import Javautilarraylist Class Represents O Q42375805 . . .

$9.00

It is Object Oriented Java

JAVA PROGRAMMING LANGUAGE

import java.util.ArrayList;

/**
* A class that represents a one room hotel and allows reservationsto be made
* and cancelled for the month of December.
*
* *
*/
public class Hotel {
private final int DAY_COUNT = 31;
private ArrayList reservations;

public Hotel() {
reservations = newArrayList(DAY_COUNT);
for (int i = 0; i < DAY_COUNT;i++) {
reservations.add(null);
}
}

public String toString() {
String out = “Hotel ReservationInfon__________________n”;

for (int i = 0; i <DAY_COUNT; i++) {
out += (i + 1) +”: “;
if(reservations.get(i) == null) {
out += “Availablen”;
} else {
out += reservations.get(i) + “n”;
}
}
return out;
}

public synchronized boolean requestReservation(Stringuser, int first, int last) {
if (reservations.indexOf(user) !=-1) {
return false;//”Only one reservation allowed per person”;
}

if (first < 1 || last >DAY_COUNT) {
return false;//”Incorrect Date Given”;
}

return reserveRoom(reservations,user, first, last);

}

]
public synchronized boolean cancelReservation(Stringuser) {
if (reservations.indexOf(user) ==-1) {
return false;//”You don’t have a reservation to cancel.”;
}

for (int i = 0; i <DAY_COUNT; i++) {
if(user.equals(reservations.get(i))) {
reservations.set(i, null);
}
}
return true;// “ReservationSuccesfully Canceled”;
}

private boolean reserveRoom(ArrayList room, Stringname, int first, int last) {
for (int i = first – 1; i <=last – 1; i++) {
if (room.get(i)!= null) {
return false;
}
}
for (int i = first – 1; i <=last – 1; i++) {
room.set(i,name);
}
return true;
}

}

Write an automated PeriodicCustomer class that implementsRunnable. Your customer should have a name and should test yourhotel’s commands (The customer will need a reference to the hotelobject). Don’t involve user input, just test all of the commandsensuring that everything is working as it should. • The clientshould periodically do one of the following. Each time chooserandomly between the two. (So, the first action may be cancel, eventhough that doesn’t make sense) o Make a new reservation startingon a random day for a random number of days. (Make sure that thereservation is theoretically possible e.g. don’t request a 60 dayreservation.) o Cancel current reservations. Only do this if theclient has successfully made a reservation • After doing so, printa message to the console stating what happened. The message shouldalways include the customer’s name. o Reservation made: Chris from3 through 5 o Reservation unsuccessful: Chris from 3 through 5 oReservations successfully canceled for Chris o Reservations notcanceled for Chris, no current reservation. • The Customer should“shut down” if it has been interrupted. (It’s ok to just check forthe exception created by the call to sleep) Display a message tothe console such as “Periodic Test Customer Chris Shutting Down”before the run method exits

 

Expert Answer


Answer to It is Object Oriented Java JAVA PROGRAMMING LANGUAGE import java.util.ArrayList; /** * A class that represents a one roo…

Category:

Description

It is Object Oriented Java

JAVA PROGRAMMING LANGUAGE

import java.util.ArrayList;

/**
* A class that represents a one room hotel and allows reservationsto be made
* and cancelled for the month of December.
*
* *
*/
public class Hotel {
private final int DAY_COUNT = 31;
private ArrayList reservations;

public Hotel() {
reservations = newArrayList(DAY_COUNT);
for (int i = 0; i < DAY_COUNT;i++) {
reservations.add(null);
}
}

public String toString() {
String out = “Hotel ReservationInfon__________________n”;

for (... View full description