Système de réservation

  1. /*
  2.  * Cancel.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 Cancel structure. This object allows to cancel a reservation for different person or for a whole of person by calling the methods <CODE>cancel</CODE> in {@link reservation.system.FlightSystem}.
  12.  * @author Texier Mathieu and Frederic Bidon
  13.  */
  14. public class Cancel extends Functions {
  15.    
  16.      /**
  17.      * Cancel several person or a whole of person if the command <CODE>cancel</CODE> and their arguments are correct.
  18.      * @throws Exception if a person name is duplicated or if the person are not canceled.
  19.      * @return a confimation's message if the person(s) or the bookingNumber are canceled.
  20.      */
  21.     public String execute () throws Exception {
  22.         boolean valid;
  23.         if (arg.length > 1) {
  24.             Set setPersonNames = new HashSet ();
  25.             for (int i = 1; i< arg.length; i++)
  26.                 setPersonNames.add (arg[i]);
  27.            
  28.             if (setPersonNames.size () != arg.length-1)
  29.                 throw new Exception ("no duplicate name are allowed in reserve comande");
  30.             valid = fs.cancel (Integer.parseInt (arg[0]), setPersonNames);
  31.         }
  32.         else
  33.             valid = fs.cancel (Integer.parseInt (arg[0]));
  34.        
  35.         if (valid) {
  36.             return "Flight canceled \r\n" +
  37.             "We are Sorry, if our compagny does not fully satified you and we hope to see you soon.\r\n";
  38.         } else {throw new Exception ("The person are not succesfully canceled");}
  39.     }
  40.    
  41.      /**
  42.      * Verify that at least one flight is created and also one reservation has been made.
  43.      * Verify invariants :
  44.      * <PRE>
  45.      * - Arguments not null
  46.      * - <CODE>bookingNumber</CODE> belongs to [1 <CODE>fs.getBookingNumberMax</CODE>]
  47.      * </PRE>
  48.      * @throws Exception if the invariants is violated
  49.      */
  50.     void _check (String[] arg) throws Exception {
  51.         try {
  52.         CheckFlightListNotEmpty ();
  53.         CheckBookingListNotEmpty ();
  54.         ArgumentIsValid (arg, 1, (short) NUMBER_ARGUMENT_MAX);
  55.         if (!checkInteger (arg[0], 1, fs.getBookingNumberMax ()))
  56.             throw new Exception ("The argument booking number has to be an integer");
  57.         } catch (Exception e) {
  58.             throw new Exception (e.getMessage ()+ "\r\n" + usage ());
  59.         }
  60.     }
  61.    
  62.     /**
  63.     * Display the usage for the command <CODE>cancel</code>.
  64.     * @return the usage.
  65.     */
  66.     static public String usage () {
  67.         String usage = " Usage command cancel: cancel <bookingNumber> [personName1] [personName2] [...]\n\r";
  68.         usage += " - The <bookingNumber> is a number and cannot be inferior to 0. \r\n";
  69.         usage += " - The arguments <personNameX> which follow correspond to the name of the \n\r";
  70.         usage += "  different persons that you want to register on the flight.\r\n";
  71.         usage += "\t The first letter of each passenger must be in  uppercase and \n\r";
  72.         usage += " all the other in lowercase.\n\r ";
  73.         usage += "\t The number of name cannot be superior to the free place of the plane.\n";
  74.         return usage;
  75.     }
  76. }
  77.  

contact - faire un lien