there is a variable called (limitOfPassengers) in the first method called (addFlight), asking the user to enter a number for the limit then save it in the variable. then i want to use this input in another method called (addPassengerToTheFlight) with an if statement to check if the added passengers doesn't exceed the given limit number.
if i use a parameter in the second method there will be an error on a switch method. What should i do?
The code is too long but here are the codes issue
switch (choice) {
case 1: {
airway.addFlight();
break;
}
case 2: {
System.out.println("\t\t\t\tPlease Enter Detail of Passenger");
airway.addPassengersToFlight();
break;
}
// the first method
public void addFlight()
{
int limitOfpassengers;
System.out.print("Enter passenger limit: ");
limitOfpassengers=ss.nextInt();
}
//the second method
public void addPassengersToFlight() {
if (flight.getPassengerLimit() <= limitOfpassengers) {
flight.addPassengers(passengers);
System.out.println("New Passenger is Added!");
} else {
System.out.println("!!!No More Space for Passenger!!!");
}
}
Aucun commentaire:
Enregistrer un commentaire