this is the code:
import java.util.Scanner;
public class Bill {
public static void main(String[] args) {
// smiley 30 strips 40 milk 20
Scanner sc = new Scanner(System.in);
System.out.println("Choose one of the following products");
System.out.println("smiley");
System.out.println("veggie strips");
System.out.println("milk");
String item1 = sc.nextLine();
System.out.println("how many of these?");
int qty1 = sc.nextInt();
if (item1.equalsIgnoreCase("smiley")) {
double cost1 = 30 * qty1;
System.out.print("The total bill now is");
System.out.println(cost1);
System.out.println("would you like to add this item to cart? type yes or no");
String choice1 = sc.next();
if (choice1.equalsIgnoreCase("yes")) {
System.out.println("okay please type continue choose the next item or type stop to exit shopping.");
} else if (choice1.equalsIgnoreCase("no")) {
System.out.println("okay please type continue choose the next item or type stop to exit shopping.");
}
}
double cost1 = 30 * qty1;
String omg = sc.next();
if (omg.equalsIgnoreCase("stop")) {
System.out.println("thanks for coming");
}
else if (omg.equalsIgnoreCase("continue")) {
System.out.println("ok chose which item");
System.out.println("veggie fingers or milk");
}
String item2 = sc.nextLine();
if (item2.equalsIgnoreCase("veggie")) {
System.out.println("ok how many of that");
}
else if (item2.equalsIgnoreCase("milk")) {
System.out.println("ok how many of that");
}
int qty2 = sc.nextInt();
if (item2.equalsIgnoreCase("veggie fingers")) {
double k = qty2 * 40;
System.out.print("okay the total bil till now is ");
System.out.println(k + cost1);
}
else if (item2.equalsIgnoreCase("milk")) {
double t = qty2 * 20;
System.out.print("okay the total bill till now is ");
System.out.println(cost1 + t);
}
System.out.println("would you like to continue shopping? answer in yes or no");
String d = sc.next();
if (d.equalsIgnoreCase("no")) {
System.out.println("okay please pay thhe bill at the counter and thanks for shopping with us.");
System.exit(1);
} else if (d.equalsIgnoreCase("yes") && item2.equalsIgnoreCase("veggie fingers")) {
System.out.println("the only item left in our store is milk.would you like that? answer in yes or no");
}
else if (d.equalsIgnoreCase("yes") && item2.equalsIgnoreCase("milk")) {
System.out.println("the only item left in our store is veggie fingers.would you like that? answer in yes or no");
}
String hoo = sc.next();
if (hoo.equalsIgnoreCase("no")) {
System.out.println("OKay thank you for shopping with us please pay the bill at the counter");
System.exit(1);
}
if (hoo.equalsIgnoreCase("yes")) {
System.out.println("how much of that would you like");
}
double t = qty2 * 20;
double p = sc.nextDouble();
if (item2.equalsIgnoreCase("milk")) {
System.out.print("okay that costed you ");
System.out.println(p*40);
System.out.print("the total bill is ");
System.out.println(cost1+t+p*40);
}
else if (item2.equalsIgnoreCase("veggie fingers")) {
System.out.print("okay that costed you ");
System.out.println(p*20);
System.out.print("the total bill is ");
System.out.println(cost1+t+p*20);
}
System.out.println("thanks for visiting us");
}
}
This is the output:
Choose one of the following products
smiley
veggie strips
milk
smiley
how many of these?
2 The total bill now is60.0
would you like to add this item to cart? type yes or no
yes
okay please type continue choose the next item or type stop to exit shopping.
continue
ok chose which item
veggie fingers or milk
veggie fingers
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Bill.main(Bill.java:44)
Process finished with exit code 1
0 Answer(s)