/*
* Reserve.java
* The package functions contains the different class executing the different functions of the FlightSystem Reservation.
*/
package reservation.system.functions;
import java.util.HashSet;
import java.util.Set;
/**
* 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}.
* @author Texier Mathieu and Frederic Bidon
*/
public class Reserve extends Functions {
/**
* Reserve several one or many person in one flight if the command <CODE>reservation</CODE> and their arguments are correct.
* @throws Exception if a person name is duplicated or if the person are not registered.
* @return a confimation's message if the person(s) are registered.
*/
for (int i = 1; i< arg.length; i++)
setPersonNames.add(arg[i]);
if(setPersonNames.size() != arg.length -1)
throw new Exception("no duplicate name are allowed in reserve comande");
int BookingNumber = fs.reserve(arg[0], setPersonNames);
if (BookingNumber != -1){
return "Your booking number is " + BookingNumber +".\r\n" +
"\tPlease, don't forget this booking number.\r\n" +
" It could be usefull to cancel your reservation.\r\n";
} else {throw new Exception("The person are not succesfully reserved");}
}
/**
* Verify that at least one flight is created.
* Verify invariants :
* <PRE>
* - Arguments not null
* </PRE>
* @throws Exception if the invariants is violated
*/
try {
CheckFlightListNotEmpty();
ArgumentIsValid(arg, 2, (short) NUMBER_ARGUMENT_MAX);
throw new Exception(e.
getMessage()+ "\r\n" + usage
());
}
}
/**
* Display the usage for the command <CODE>reserve</code>.
* @return the usage.
*/
static public String usage
() {
String usage
= " Usage command reserve: reserve <flightName> <personName1> [personName2] [...]\n\r";
usage += " - The <flightName> can contain all the characters except the syntax character.\r\n";
usage += " - The arguments <personNameX> which follow correspond to the name of the \n\r";
usage += " different persons that you want to register on the flight.\r\n";
usage += "\t The first letter of each passenger must be in uppercase and all \n\r";
usage += "\t the other in lowercase.\n\r";
usage += "\t The number of name cannot be superior to the free place of the plane.\n";
return usage;
}
}