Airline Reservation System

This program simulates an airline reservation system.


import java.awt.*;

public class Airplane extends EasyApp
{  public static void main(String[] args)
   {
      new Airplane();
   }
   
   Button bReserve = addButton("Reserve a Seat",50,50,200,50,this);
   
   String[] seats = {"o","o","o","o","o","o","o","o","o","o"};
   
   public void actions(Object source,String command)
   {
      if (source == bReserve)
      {  reserve(); }
   }

   public void reserve()
   {  
      String name = input("What is your name?");
      int num = inputInt("Which seat would you like (0-9)?");
      if (seats[num].equals("o") )
      {
         seats[num] = name;
         output("Seat #" + num + " has been reserved for you.");
      }
      else
      {  output("That seat is taken."); }
   }      
}

/*****************************************
This program simulates an airline reservation system.
It is very simple - it only reserves seats on one single plane,
which has only 10 seats.  And when the program ends,
all the reservations are erased.  So this isn't "realistic",
but is a good start for a better program.

(1) Run this program and TEST it thoroughly - e.g.
  (a) What happens if you ask for seat #20?
  (b) What happens if Bob reserves seat #1,
      and then Joe asks for the same seat?
  (c) What will happen if after all the seats are full?

(2) Fix the program to VALIDATE the number, and reject
    numbers under 0 and over 9.  State the type of error
    that this prevents.


(3) Add a new button called FREE SEATS.
   It should COUNT the number of free seats in the plane,
   and display the answer. You must write a COUNT method,
   and it should RETURN the number of free seats.

(4) Change the program so that at the beginning of RESERVE
   the COUNT method will run automatically, and tell the
   user how many seats are still free.
   
(5) Write another method called firstFreeSeat.  This should
   search the SEATS array until it finds a free seat ("o"),
   and then return the NUMBER of the seat.  So if you did
   this at the beginning, it would return 0.
   
(6) Change the program so that RESERVE always "suggests"
   a free seat by running firstFreeSeat.  This makes things
   simpler for the user.
   
(7) Make a COUPLES button.  This inputs TWO names
    and TWO seat numbers together, and tries to place BOTH
    names into the two seats.  If EITHER seat is occupied,
    the attempt is rejected.
    
(8) Make a method to FIND TWO FREE SEATS.  This should
    run every type the COUPLES button is pressed.

(9) Write a method that inputs a name and searches for
    that name in the SEATS array.  It should return
    the NUMBER of the seat if the name is found.
    Otherwise it should return -1.

(10) Write a method called EMPTYPLANE that erases all
     the names in the SEATS array.

(11) Write a method that prints the names of all
     the passengers in the plane.  It should print the
     seat number and the name for each seat.

(12) Write a CANCEL method.  It should search for a name
     and erase it by replacing it with "o".

******************************************/