import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner; //Scanner Class Available
public class Pies {
/**
* @param args
*/
public static void main(String[] args) {
Scanner inScan = new Scanner(System.in);
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);
//
while (true)
{
System.out.println("Is there another customer waiting in line?");
String newCustomer = inScan.nextLine();
while (newCustomer.equalsIgnoreCase("Y") || newCustomer.equalsIgnoreCase("Yes"))
{
System.out.println("Are you a Pi Card Member?");
String cardHolder = inScan.nextLine();
while (cardHolder.equalsIgnoreCase("Y") || cardHolder.equalsIgnoreCase("Yes"))
{
System.out.println("Here's a list of products for sale:");
System.out.println("(a) Cheese Pizza $10.00");
System.out.println("(b) Pepperoni Pizza $10.00");
System.out.println("(c) Cherry Pies $ 8.00");
System.out.println("(d) Cherry Pie Slices $ 1.75");
System.out.println("(e) Pi Charms (14k Gold) $45.00");
System.out.println("(f) Checkout");
System.out.println(System.getProperty("line.separa tor"));
System.out.println("Which item would you like to purchase? (a,b,c,d, or e)");
String addCart = inScan.nextLine();
if (addCart.equalsIgnoreCase("A"))
{
System.out.println("How many Cheese Pizzas would you like to purchase?");
double numberCheesePizzas = inScan.nextDouble();
double cheesePizzaCost = 10.00;
double cheeseTotal = (cheesePizzaCost * numberCheesePizzas);
System.out.println("You have a total of " + numberCheesePizzas + " Cheese Pizzas in your cart for a total of $" + cheeseTotal + ".");
System.out.println(System.getProperty("line.separa tor"));
}
if (addCart.equalsIgnoreCase("B"))
{
//and so on I didn't want to copy the entire code when i really just need help with making the individual loops work--
}
}
}
}
}
}
The goal of the entire exercise is to allow multiple items to be put into a "basket", purchased, with sales tax, etc. None of that is important right now but can someone help me understand why the output for this using (a) and any number causes the loop to output the list of items and prices twice? ITS KILLING ME INSIDE TRYING TO FIGURE THIS OUT!
Sample Output:
Is there another customer waiting in line?
Y
Are you a Pi Card Member?
Y
Here's a list of products for sale:
(a) Cheese Pizza $10.00
(b) Pepperoni Pizza $10.00
(c) Cherry Pies $ 8.00
(d) Cherry Pie Slices $ 1.75
(e) Pi Charms (14k Gold) $45.00
(f) Checkout
Which item would you like to purchase? (a,b,c,d, or e)
A
How many Cheese Pizzas would you like to purchase?
23
You have a total of 23.0 Cheese Pizzas in your cart for a total of $230.0.
Here's a list of products for sale:
(a) Cheese Pizza $10.00
(b) Pepperoni Pizza $10.00
(c) Cherry Pies $ 8.00
(d) Cherry Pie Slices $ 1.75
(e) Pi Charms (14k Gold) $45.00
(f) Checkout
Which item would you like to purchase? (a,b,c,d, or e)
Here's a list of products for sale:
(a) Cheese Pizza $10.00
(b) Pepperoni Pizza $10.00
(c) Cherry Pies $ 8.00
(d) Cherry Pie Slices $ 1.75
(e) Pi Charms (14k Gold) $45.00
(f) Checkout
Which item would you like to purchase? (a,b,c,d, or e)