Modify the program to have a command to delete a reservation.
Modify the program to defi...
Computers and Technology, 07.04.2020 22:03, ElDudoso
Modify the program to have a command to delete a reservation.
Modify the program to define and use a method public void makeSeatReservations(Scanner scnr) so that the program's main() is cleaner. The makeSeatReservations() method should have a Scanner object passed to it to read the user's input.
import java. util. ArrayList;
import java. util. Scanner;
public class SeatReservation {
// Arraylist for seat reservations
private ArrayList allSeats;
public SeatReservation() {
allSeats = new ArrayList();
}
public void makeSeatsEmpty() {
int i;
for (i = 0; i < allSeats. size(); ++i) {
allSeats. get(i).makeEmpty();
}
}
public void printSeats() {
int i;
for (i = 0; i < allSeats. size(); ++i) {
System. out. print(i + ": ");
allSeats. get(i).print();
}
}
public void addSeats(int numSeats) {
int i;
for (i = 0; i < numSeats; ++i) {
allSeats. add(new Seat());
}
}
public Seat getSeat(int seatNum) {
return allSeats. get(seatNum);
}
public void setSeat(int seatNum, Seat newSeat) {
allSeats. set(seatNum, newSeat);
}
// Main method to use SeatReservation methods
public static void main (String [] args) {
Scanner scnr = new Scanner(System. in);
String usrInput = "";
String firstName, lastName;
int amountPaid;
int seatNum;
Seat newSeat;
SeatReservation ezReservations = new SeatReservation();
// Add 5 seat objects
ezReservations. addSeats(5);
// Make all seats empty
ezReservations. makeSeatsEmpty();
while (!usrInput. equals("q")) {
System. out. println();
System. out. print("Enter command (p/r/q): ");
usrInput = scnr. next();
// Print seats
if (usrInput. equals("p")) {
ezReservations. printSeats();
}
// Reserve a seat
else if (usrInput. equals("r")) {
System. out. print("Enter seat num: ");
seatNum = scnr. nextInt();
if ( !(ezReservations. getSeat(seatNum).isEmpty()) ) {
System. out. println("Seat not empty.");
}
else {
System. out. print("Enter first name: ");
firstName = scnr. next();
System. out. print("Enter last name: ");
lastName = scnr. next();
System. out. print("Enter amount paid: ");
amountPaid = scnr. nextInt();
// Create new Seat object and add to the reservations
newSeat = new Seat();
newSeat. reserve(firstName, lastName, amountPaid);
ezReservations. setSeat(seatNum, newSeat);
System. out. println("Completed.");
}
}
// FIXME: Add option to delete reservations
else if (usrInput. equals("q")) { // Quit
System. out. println("Quitting.");
}
else {
System. out. println("Invalid command.");
}
}
}
}
Answers: 1
Computers and Technology, 24.06.2019 22:00, ivethzurita0425
What is a number system, and what is the total number of digits used in this system called? a number system is a system that uses different (options: a) numbers b) symbols c) codes d) digits e) alphabets) to represent different numbers. the total number of digits used in a number system is known as its (options: 1) processor 2) converter 3) radix 4) least significant digit 5) most significant digit)
Answers: 1
Computers and Technology, 25.06.2019 02:30, 30valgolden
Technology has changed communications by replacing or supplementing traditional modes of communication that were primarily
Answers: 2
Computers and Technology, 25.06.2019 05:30, AM28
Two technicians are discussing a resistance measurement. technician a states that components being measured should be removed or isolated from the circuit. technician b states that power to the circuit should be disconnected when measuring resistance. which technician is correct?
Answers: 1
Computers and Technology, 25.06.2019 08:00, yungkxng57
Is a major factor in the widespread use of global information systems
Answers: 1
Chemistry, 23.04.2021 22:30
Geography, 23.04.2021 22:30
Chemistry, 23.04.2021 22:30
Geography, 23.04.2021 22:30
Physics, 23.04.2021 22:30