subject

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
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:00
Eva has many contacts on the professional networking site she uses which contacts are considered second degree
Answers: 3
question
Computers and Technology, 22.06.2019 19:10
What a backup plan that you have created in a event you encounter a situation
Answers: 2
question
Computers and Technology, 22.06.2019 19:20
Write a program that prompts the user to input a string. the program then uses the function substr to remove all the vowels from the string. for example, if str = "there", then after removing all the vowels, str = "thr". after removing all the vowels, output the string. your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 3
You know the right answer?
Modify the program to have a command to delete a reservation.

Modify the program to defi...
Questions
question
English, 12.03.2021 01:00
question
Mathematics, 12.03.2021 01:00
question
Mathematics, 12.03.2021 01:00
question
Mathematics, 12.03.2021 01:00
question
History, 12.03.2021 01:00
question
Mathematics, 12.03.2021 01:00
Questions on the website: 13722363