Quote:
Originally Posted by Fou-Lu
That's wierd; you're combining gui and cli for io?
The input within the selectValue method will contain the value entered into the option dialog. Cast that to an integer with Integer.parseInt and assign it to the choice. Then switch on the choice to determine what to do next.
|
At the moment im just sticking to basics so would using scanner be more easier?
also this is what ive done is it correct??
import javax.swing.JOptionPane;
public class TravelAgentSystem {
public static void main(String[] args) {
// Local variable declared
int selectValue;
// Main Menu is displayed
System.out.println("| Flight Travel Systems |");
System.out.println("|--------------------------|");
System.out.println("| Options: |");
System.out.println("| 1. Time |");
System.out.println("| 2. Price |");
System.out.println("| 3. Hotels |");
System.out.println("| 4. End |");
System.out.println("============================");
selectValue();
}
public static void selectValue()
{
int choice = -1;
while(choice < 0)
{
String input = JOptionPane.showInputDialog("Please select an option: ");
if (input.equals("1")){
System.out.println("fdsfds");
}
else if (input.equals("2")){
System.out.println("ggfdgd " );
}
else if (input.equals("3")){
System.out.println("hgfdhgf " );
}
else if (input.equals("4")){
System.out.println("nhgdhd " );
}
else {
JOptionPane.showMessageDialog(null, "User error,please select an option");
}
}
}
}
i need to change the system to options but at the moment the concept seems baffling. If i select 1 i want to bring up an array of flights in which can be selected