I want to change if to switch...can someone help me with that? I ve been trying but nothing worked... please help me with this Please please please please
I want to change if to switch...can someone help me with that? I ve been trying but nothing worked... please help me with this Please please please please
if(choose==1){
System.out.println("Milk");
System.out.print("How many items do you want to add? :");
quantity =input.nextInt();
total = total +(quantity*1);
System.out.println("Continue? ");
System.out.println("Type in Yes or No : ");
again = input.next();
if(again.equalsIgnoreCase("Yes")){
add();//call the method you to create
}else{
System.out.println("Payment (add amout of money you give)");
pay = input.nextDouble();
if(pay <=total){
System.out.println("Payment failed");
}else{
System.out.println("Total price is " + total);
total = pay-total;
System.out.println("The change is " + total);
}
}
}else if(choose==2){
System.out.println("Tea");
System.out.print("How many items do you want to add? :");
quantity =input.nextInt();
total = total +(quantity*2.78);
System.out.println("Continue?");
System.out.println("Type in Yes or No");
again = input.next();
if(again.equalsIgnoreCase("Yes")){
add();//call the method you to create
}else{
System.out.println("Payment (add amout of money you give)");
pay = input.nextDouble();
if(pay <=total){
System.out.println("Payment failed");
}else{
System.out.println("Total price is " + total);
total = pay-total;
System.out.println("The change is " + total);
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire