OK, so I have to make a method that assigns a seat in an airplane. There are two options: First Class or Coach Class. I am having trouble with my reserveSeat() method. There are multiple ways to accomplish this but I am attempting to stick to the logic I have already provided. Here are all the methods, variables, objects defined already:
-If the user chooses to reserve a seat (an integer of 0):
__________________________________________________ __________________________________________________ __if(choice == 0) { String classSpec = JOptionPane.showInputDialog("Specify Class type"); { if(theSeat.checkSeatAvailability() == true) { theAirplane.assignSeat(classSpec); flag = true; } else if(theSeat.checkSeatAvailability() == false) { JOptionPane.showMessageDialog( null, "There are no more seats", "Seating." + " The Seat: " + theSeat.getSeatNum() + " is Occupied", JOptionPane.INFORMATION_MESSAGE); flag = true; } } flag = true; }
My reserveSeat method looks like this:
public void assignSeat(String spec) { boolean flag = true; if (spec.equals("First Class")) { for(int i = 0; i < 4 && flag ; i++) { seatArray[i] = new Seat(i, spec); if(seatArray[i].checkSeatAvailability() == true) { seatArray[i].reserveSeat(); flag = false; } else { flag = true; } } } else { for(int i = 4; i < 10 ; i++) { while(flag) { seatArray[i] = new Seat(i, spec); if(seatArray[i].checkSeatAvailability() == true) { seatArray[i].reserveSeat(); flag = false; } else { flag = true; } } } } }