Modify the program to have a command to delete a reservation.
Modify the program to defi...
![subject](/tpl/images/cats/informatica.png)
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.");
}
}
}
}
![ansver](/tpl/images/cats/User.png)
Answers: 1
Another question on Computers and Technology
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 15:30
Melissa needs to add a topic to an email that she will send to her teacher. choose the name of the field where she should type her topic.
Answers: 2
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 16:30
What type of file does a cookie place on web site visitors' computers so that web site managers can customize their sites to their visitors' preferences?
Answers: 1
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 01:00
Let r be a robotic arm with a fixed base and seven links. the last joint of r is a prismatic joint, the other ones are revolute joints. give a set of parameters that determines a placement of r. what is the dimension of the configuration space resulting from your choice of parameters?
Answers: 3
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 16:10
What is the ooh? a. omaha occupation handbook b. online occupational c. occupations online d. occupational outlook handbook select the best answer from the choices provided
Answers: 3
You know the right answer?
Questions
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 29.06.2019 13:20
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/fizika.png)
Physics, 29.06.2019 13:20
![question](/tpl/images/cats/mat.png)
Mathematics, 29.06.2019 13:20
![question](/tpl/images/cats/fizika.png)
Physics, 29.06.2019 13:20
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 29.06.2019 13:20
![question](/tpl/images/cats/mat.png)
Mathematics, 29.06.2019 13:20
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 29.06.2019 13:30
![question](/tpl/images/cats/fizika.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/obshestvoznanie.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 29.06.2019 13:30
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 29.06.2019 13:30