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 20:00
What is the term for water wave that is created by an underwater earthquake
Answers: 1
question
Computers and Technology, 23.06.2019 04:10
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
question
Computers and Technology, 23.06.2019 13:30
Drag the tiles to the correct boxes to complete the pairs. match the errors with their definitions. #name #value #ref when a formula produces output that is too lengthy to fit in the spreadsheet cell arrowright when you enter an invalid cell reference in a formula arrowright when you type text in cells that accept numeric data arrowright when you type in a cell reference that doesn’t exist arrowright reset next
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Match the sentence fragment in the first column with the appropriate ending in the second column. a little per favore?
Answers: 1
You know the right answer?
Modify the program to have a command to delete a reservation.

Modify the program to defi...
Questions
question
Physics, 21.01.2020 23:31
question
Mathematics, 21.01.2020 23:31
question
Mathematics, 21.01.2020 23:31
Questions on the website: 13722360