Système de réservation

  1. /*
  2.  * Create.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.Flight;
  8.  
  9. import java.util.HashSet;
  10. import java.util.Set;
  11.  
  12. /**
  13.  * This class hold Create structure. This object allows to create a new flight in the data base by calling the method <CODE>create</CODE> in {@link reservation.system.FlightSystem}.
  14.  * @author Texier Mathieu and Frederic Bidon
  15.  */
  16. public class Create extends Functions {
  17.    
  18.     /**
  19.      * Create a new flight in a database if the command <CODE>create</CODE> and their arguments are correct.
  20.      * @throws Exception if the flight is not created.
  21.      * @return a confimation's message if the flight is created.
  22.      */
  23.     public String execute () throws Exception {
  24.         if (fs.create (arg[0], (short) Integer.parseInt (arg[1]), (short)
  25. Integer.parseInt (arg[2])))
  26.             return "Flight created \r\n";
  27.         else {throw new Exception ("The flight is not succesfully created");}
  28.     }
  29.  
  30.     /**
  31.      * Verify invariants :
  32.      * <PRE>
  33.      * - Arguments not null
  34.      * - <CODE>rows</CODE> belongs to [1 <CODE>Flight.ROWS_MAX</CODE>]
  35.      * - <CODE>rowsLength</CODE> belongs to [1 <CODE>Flight.ROW_LENGTH_MAX</CODE>]
  36.      * </PRE>
  37.      * @throws Exception if the invariants is violated
  38.      */
  39.     void _check (String[] arg) throws Exception {
  40.         try {
  41.         ArgumentIsValid (arg, 3, 3);
  42.         if (!checkInteger (arg[1], 1, Flight.ROWS_MAX))
  43.             throw new Exception ("The argument : rows has to be a number");
  44.         if (!checkInteger (arg[2], 1, Flight.ROW_LENGTH_MAX))
  45.             throw new Exception ("The argument : rows length has to be a number");
  46.          } catch (Exception e) {
  47.             throw new Exception (e.getMessage ()+ "\r\n" + usage ());
  48.         }
  49.     }
  50.    
  51.     /**
  52.     * Display the usage for the command <CODE>create</code>.
  53.     * @return the usage.
  54.     */
  55.     static public String usage () {
  56.         String usage = " Usage command create: create <flightName> <rows> <rowLength>\n\r";
  57.         usage += " - The <flightName> can contain all the characters except the special \r\n";
  58.         usage += " character. \r\n";
  59.         usage += " - The argument <rows> is a number that belongs to [1 100].\r\n";
  60.         usage += " - The argument <rowLength> is a number that belongs to [1 10].\n";
  61.         return usage;
  62.     }
  63. }

contact - faire un lien