0% found this document useful (0 votes)
204 views

PizzaOrder Assignment Working Coding

1. The program allows a user to order a pizza with size, toppings, and delivery options. 2. It uses conditionals like if/else statements to determine the pizza price based on size selected and add topping prices to a running total. 3. The program calculates the total cost of the order, including an added delivery fee if delivery is requested, then prints an invoice for the user.

Uploaded by

inpreetk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
204 views

PizzaOrder Assignment Working Coding

1. The program allows a user to order a pizza with size, toppings, and delivery options. 2. It uses conditionals like if/else statements to determine the pizza price based on size selected and add topping prices to a running total. 3. The program calculates the total cost of the order, including an added delivery fee if delivery is requested, then prints an invoice for the user.

Uploaded by

inpreetk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Creating class Pizza with encapsulation

public class Pizza {


public static void main(String[] args) {
int pizza;
double pizzaPrice = 0;
String name;
String pizzaSize;
int topping;
Scanner sc = new Scanner(System.in); //create new scanner class

//Using ArrayList

System.out.println("Hello " What size pizza would you like? 1:large = 14.99" +
//records users pizza size
" 2: medium = 12.99 3:small = 10.99");
pizza = sc.nextInt(); //grab int relative to pizza cost

if (pizza == 1) {

pizzaSize = "Large";
pizzaPrice = 14.99; //gather pizza int and convert to double
}
if (pizza == 2) {
pizzaSize ="Medium";
pizzaPrice = 12.99;
}
if (pizza == 3) {
pizzaSize ="Small";
pizzaPrice = 10.99;
}
double toppingPrice = 0;

int count = 0; //initalize beginning of loop to 0


do

System.out.println("What toppings would you like? Choose 2 1: Olives = 1.29"


+//do while loop for toppings
" 2: Mushrooms = 1.49 3: Pepperoni = 1.79" +
" 4) Pineapple = 1.59 5) Black Olive = 1.87" +
" 6) Tomato = 1.59 7) Onion = 1.40" +
" 8) Green Capsicum = 1.59 9) Golden Corn = 1.50" +
" 10) Zucchini = 1.59 " +);
topping = sc.nextInt();

if (topping == 1) //if Olives are chosen, initalize toppingPrice to 1.29


toppingPrice = 1.29;
if (topping == 2)
toppingPrice = 1.49;// if Mushrooms are chosen initalize value of
toppingPrice too 1.49
if (topping == 3)
toppingPrice = 1.79;//if Mushrooms are chosen initialize value of
toppingPrice to 1.79
if (topping == 4)
toppingPrice = 1.59;//If pineapple is chosen initalize value of
toppingPrice to 1.59
//so on

//find way to add both topping prices

} while (topping < 5); //get the topping Int, aslong as its under 5 loop will
continue to run

double totalCost1 = pizzaPrice +toppingPrice;


double totalCost = pizzaPrice +toppingPrice +deliveryFee;
sc.nextLine();
System.out.println("Do you want delivery?\n Enter yes or no");
delivery = sc.nextLine();

if (delivery.equals("yes")) {
System.out.println("Hello" " here is your order:" +"\n" + pizzaPrice +
"\nToppings:" + toppingPrice + "\ndelivery 2.50"
+ "\nTotal cost "+ totalCost );//invoice if user types in yes
}

if (delivery.equals("no")) {
System.out.println("Hello"+" " + name + " here is your order:" +"\n" +
pizzaPrice +
"\nToppings:" + toppingPrice +
"\nTotal cost: "+ totalCost1 ); //invoice if user types in no
}

You might also like