I have another class that has a main method and has the JFrame
. When I run my code it stops after the user selects a cabin, and doesn't run the rest of my code such as asking the user for their first name. After it goes through my action listener it does not move forward.
private class CabinListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
String setCabin;
if(source == cabin1)
{
setCabin = "Cabin 1-1";
System.out.print(setCabin);
}
else if(source == cabin2)
{
setCabin = "Cabin 1-2";
System.out.print(setCabin);
}
else if(source == cabin3)
{
setCabin = "Cabin 1-3";
System.out.print(setCabin);
}
else if(source == cabin4)
{
setCabin = "Cabin 1-4";
System.out.print(setCabin);
}
else if(source == cabin5)
{
setCabin = "Cabin 1-5";
System.out.print(setCabin);
}
else if(source == cabin6)
{
setCabin = "Cabin 1-6";
System.out.print(setCabin);
}
else if(source == cabin7)
{
setCabin = "Cabin 1-7";
System.out.print(setCabin);
}
else if(source == cabin8)
{
setCabin = "Cabin 1-8";
System.out.print(setCabin);
}
else if(source == cabin9)
{
setCabin = "Cabin 1-9";
System.out.print(setCabin);
}
else if(source == cabin10)
{
setCabin = "Cabin 1-10";
System.out.print(setCabin);
}
else if(source == cabin11)
{
setCabin = "Cabin 2-1";
System.out.print(setCabin);
}
else
{
setCabin = "Cabin 2-2";
System.out.print(setCabin);
}
Scanner scan = new Scanner(System.in);
Destination dest1 = new Destination("Jmaica", "stop1", 200.14, "stop2", 250.12, "stop3", 234.99, "stop4", 300.12);
Destination dest2 = new Destination("Key largo", "stop1.1", 253.2, "stop2.1", 231.2, "stop3.1", 342.3, "stop4.1", 324.0);
Destination dest3 = new Destination("Hawaii", "stop1.2", 258.2, "stop2.2", 265.2, "stop3.2", 348.3, "stop4.2", 334.4);
Destination dest4 = new Destination("Carribean", "stop1.3", 158.2, "stop2.3", 325.2, "stop3.3", 768.3, "stop4.3", 564.4);
Destination cust_dest = new Destination("", "", 0, "", 0, "", 0, "", 0); //creates seperate object that will adopt the properties of the destination that the user chooses.
Account customer1 = new Account("","","","",0,"","","","","","");
System.out.println("Please enter our first name"); //gets Customers first name and assigns it to customer1 obj
String fName_scan = scan.nextLine();
customer1.setFname(fName_scan);
System.out.println("Please enter your last name");
String lName_scan = scan.nextLine();
customer1.setLname(lName_scan);
System.out.println("Please enter your city");
String city_scan = scan.nextLine();
customer1.setCity(city_scan);
System.out.println("Please enter your state");
String state_scan = scan.nextLine();
customer1.setState(state_scan);
System.out.println("Please enter how many members are in your party");
int party_scan = scan.nextInt();
customer1.setGroup(party_scan);
System.out.println("Please choose your cabin");
System.out.println("Please enter the corresponding number for your desired destination" + " \t 1. Jamaica" + " \t 2. Key largo" +
" \t 3. Hawaii" + " \t 4. Carribean");
int dest_scan = scan.nextInt();
if(dest_scan == 1)
{
System.out.println(dest1);
cust_dest = dest1; //adopts the properties of destination1 to the customer destination, so we can use getter methods to choose the users possible excursions
}
else if(dest_scan == 2)
{
System.out.println(dest2);
cust_dest = dest2;
}
else if(dest_scan == 3)
{
System.out.println(dest3);
cust_dest = dest3;
}
else if(dest_scan == 4)
{
System.out.println(dest4);
cust_dest = dest4;
}
double excursionTotal = 0.0;
System.out.println("Now choose your excursions");
String exit_loop = "no";
String excursion_choice;
System.out.print("Enter the corresponding number to add an excursion to your package. Type X when finished:");
while(exit_loop.equals("no"))
{
excursion_choice = scan.nextLine();
if(excursion_choice.equals("x") || excursion_choice.equals("X"))
exit_loop = "yes";
else if(excursion_choice.equals("1"))
{
customer1.setExcursion1(cust_dest.getExcursion1()); //assigns customers excursion 1 from the customer destination object; which was adopted when the user chose a destination.
excursionTotal = excursionTotal + cust_dest.getExcursion1_price(); // gets excursion price from customer destination object for excursion 1.
}
else if(excursion_choice.equals("2"))
{
customer1.setExcursion2(cust_dest.getExcursion2());
excursionTotal = excursionTotal + cust_dest.getExcursion2_price();
}
else if(excursion_choice.equals("3"))
{
customer1.setExcursion3(cust_dest.getExcursion3());
excursionTotal = excursionTotal + cust_dest.getExcursion3_price();
}
else if(excursion_choice.equals("4"))
{
customer1.setExcursion4(cust_dest.getExcursion4());
excursionTotal = excursionTotal + cust_dest.getExcursion4_price();
}
}
System.out.println(customer1);
System.out.print(excursionTotal);
}
}
}