Système de réservation

  1. /*
  2.  * Reserve.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 java.util.HashSet;
  8. import java.util.Set;
  9.  
  10. /**
  11.  * This class hold Reserve structure. This object allows to reserve to one flight one or many persons by calling the method <CODE>reserve</CODE> in {@link reservation.system.FlightSystem}.
  12.  * @author Texier Mathieu and Frederic Bidon
  13.  */
  14. public class Reserve extends Functions {
  15.    
  16.     /**
  17.      * Reserve several one or many person in one flight if the command <CODE>reservation</CODE> and their arguments are correct.
  18.      * @throws Exception if a person name is duplicated or if the person are not registered.
  19.      * @return a confimation's message if the person(s) are registered.
  20.      */
  21.     public String execute() throws Exception {
  22.         Set setPersonNames = new HashSet();
  23.         for (int i = 1; i< arg.length; i++)
  24.             setPersonNames.add(arg[i]);
  25.        
  26.         if(setPersonNames.size() != arg.length -1)
  27.             throw new Exception("no duplicate name are allowed in reserve comande");
  28.        
  29.         int BookingNumber = fs.reserve(arg[0], setPersonNames);
  30.         if (BookingNumber != -1){
  31.             return "Your booking number is " + BookingNumber +".\r\n" +
  32.             "\tPlease, don't forget this booking number.\r\n" +
  33.             " It could be usefull to cancel your reservation.\r\n";
  34.         } else {throw new Exception("The person are not succesfully reserved");}
  35.     }
  36.    
  37.     /**
  38.      * Verify that at least one flight is created.
  39.      * Verify invariants :
  40.      * <PRE>
  41.      * - Arguments not null
  42.      * </PRE>
  43.      * @throws Exception if the invariants is violated
  44.      */
  45.    
  46.     void _check(String[] arg) throws Exception {
  47.         try {
  48.             CheckFlightListNotEmpty();
  49.             ArgumentIsValid(arg, 2, (short) NUMBER_ARGUMENT_MAX);
  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>reserve</code>.
  57.      * @return the usage.
  58.      */
  59.     static public String usage() {
  60.         String usage = " Usage command reserve: reserve <flightName> <personName1> [personName2] [...]\n\r";
  61.         usage += " - The <flightName> can contain all the characters except the syntax character.\r\n";
  62.         usage += " - The arguments <personNameX> which follow correspond to the name of the \n\r";
  63.         usage += " different persons that you want to register on the flight.\r\n";
  64.         usage += "\t The first letter of each passenger must be in  uppercase and all \n\r";
  65.         usage += "\t the other in lowercase.\n\r";
  66.         usage += "\t The number of name cannot be superior to the free place of the plane.\n";
  67.         return usage;
  68.     }
  69. }

contact - faire un lien