booking system

  1. /*
  2.  * Identify.java
  3.  * The package functions contains the different class executing the different functions of the FlightSystem Reservation.
  4.  */
  5. package reservation.system.functions;
  6.  
  7. import reservation.system.Person;
  8.  
  9. import java.util.Vector;
  10.  
  11. /**
  12.  * This class hold Lists structure. This object allows to see the person who are registered in one flight by calling the method <CODE>list</CODE> in {@link reservation.system.FlightSystem}.
  13.  * @author Texier Mathieu and Frederic Bidon
  14.  */
  15. public class Identify extends Functions {
  16.    
  17.     /**
  18.      * Display the list of the persons who have got the bookingNumber written by the user if the command <CODE>identify</CODE> and their arguments are correct.
  19.      * @throws Exception the command is not executed.
  20.      * @return the names of the persons which correpond to this bookingNumber and their positions in the flight.
  21.      */
  22.     public String execute () throws Exception {
  23.         Vector groupePersonVector = fs.identify (Integer.parseInt (arg[0]));
  24.         if (groupePersonVector.isEmpty ())
  25.             return "The List is empty.\r\n";
  26.        
  27.         String flightName = ((Person) groupePersonVector.get (0)).getFlight ().getFlightName ();
  28.         String retString = "Flight: Identify " + arg[0] + " (flght " + flightName +" )\r\n" ;
  29.         for (int i=0; i< groupePersonVector.size (); i++)
  30.             retString += (Person) groupePersonVector.get (i);
  31.         return retString;
  32.     }
  33.    
  34.     /**
  35.      * Verify that at least one flight is created and also one reservation has been made.
  36.      * Verify invariants :
  37.      * <PRE>
  38.      * - Arguments not null
  39.      * - <CODE>bookingNumber</CODE> belongs to [1 <CODE>fs.getBookingNumberMax</CODE>]
  40.      * </PRE>
  41.      * @throws Exception if the invariants is violated
  42.      */
  43.     void _check (String[] arg) throws Exception {
  44.         try {
  45.         CheckFlightListNotEmpty ();
  46.         CheckBookingListNotEmpty ();
  47.         ArgumentIsValid (arg, 1, 1);
  48.         if (!checkInteger (arg[0], 1, fs.getBookingNumberMax ()))
  49.             throw new Exception ("The argument booking number has to be an integer");
  50.          } catch (Exception e) {
  51.             throw new Exception (e.getMessage ()+ "\r\n" + usage ());
  52.         }
  53.     }
  54.    
  55.     /**
  56.     * Display the usage for the command <CODE>identify</code>.
  57.     * @return the usage.
  58.     */
  59.     static public String usage () {
  60.         String usage = " Usage command identify: identify <bookingNumber>\n\r";
  61.         usage += " - The <bookingNumber> is a number and cannot be inferior to 0.\n";  
  62.         return usage;
  63.     }
  64. }

contact - link to this site