public class PizzaExamfinalOne{
public static void main(String[]args){
double total2 = 0;
String customerName = " ";
String address = " ";
String phoneNum ="0";
int max = 5;
int done = 1;
double totalPizza = 0;
double totalA = 0;
int pizzaChoice =0;
String [] pizzaType = {"Placeholder", "Hawaian" , "Classic Italian" , "Cheese Extreme" , "Veg Delight" , "Pepperoni" , "Tomato Margherita" , "Beef & Onion" , "Super Supreme" , "Meat Lovers" , "Hot 'n Spicy" , "Italiano" , "Italian Veg"};
double [] pizzaPrice = {0, 8.5 , 8.5 , 8.5 , 8.5 , 8.5 , 8.5 , 8.5 , 13.5 , 13.5 , 13.5 , 13.5 , 13.5};
int [] orderDisplay = {0,0,0,0,0,0,0,0,0,0,0,0,0};
boolean pickup = true;
int pickup1 = readInt("If you wish to pickup press 1 or press 0 for delivery");
if (pickup1 ==0){
pickup = false;
}
for (int i = 1; i <pizzaType.length; i++){
System.out.println(i + " " +pizzaType[i] + " $" + pizzaPrice[i]);
}
while (done !=0){
pizzaChoice = readInt ("Choose the type of pizza you wish to order");
double pizzaQuantity = readInt ("How many " + pizzaType[pizzaChoice] + " pizzas do you wish to buy (Maximum is 5)");
totalPizza = totalPizza + pizzaQuantity;
if(totalPizza > max){
System.out.println("You cannot order more than five pizzas");
pizzaChoice = 0;
pizzaQuantity = 0;
}
done= readInt ("Press 0 if you are done or press 1 to make another pizza order");
double total1 = pizzaQuantity*pizzaPrice[pizzaChoice];
total2 = total2 + total1;
}
if(pickup==false){
int deliveryCost = 3;
customerName = readString ("Please enter your full name");
address = readString ("Please enter the Delivery address");
phoneNum = readString ("Please enter the phone number of " + customerName);
totalA = total2 + deliveryCost;
System.out.println("Delivery order for " + customerName);
System.out.println("To " + address + ", Phone number 0" + phoneNum);
}
else{
customerName = readString ("Please enter your full name");
System.out.println("Pickup order for " + customerName);
int deliveryCost = 0;
totalA = total2 + deliveryCost;
}
My problem is here. I need to display the pizzas that the user has ordered along with the amount of pizzas ordered and I’m stuck here. there are no errors in the code it just doesnt display the following
for(int i=1;i<orderDisplay.length;i++){
if(orderDisplay[i]>0){
System.out.println(" " + orderDisplay[i] + " " + pizzaType[i] + " pizzas");
}
}
System.out.println("The total amount of your order is " + formatMoney(totalA));
}
public static int readInt(String prompt){
System.out.println(prompt);
java.util.Scanner keyboard = new java.util.Scanner(System.in);
return keyboard.nextInt();
}
public static String readString (String prompt){
System.out.println (prompt);
java.util.Scanner keyboard= new java.util.Scanner(System.in);
return keyboard.nextLine();
}
public static String formatMoney(double phoneNum){
java.text.NumberFormat fmt = java.text.NumberFormat. getCurrencyInstance();
return(fmt.format(phoneNum));
}
}
You have set all the array elements of orderDisplay to 0.
U never changed the value of orderDispaly elements and checking for value greater than 0 and u have started your loop with value 1. check the below lines.
Here is your answer :