In this project, you are asked to write a program for a Pizza store to process pizza orders. Suppose that they receive 10 orders in one hour, each order includes the following information: Name of the customer, size of the pizza, topping of the pizza, and distance for delivery. The charge information on a order:
Requirements on your programs:
//Java code
Note:--> I am giving output only for two inputs, you can test it for 10
import java.text.NumberFormat;
public class PizzaOrder {
//attributes
private int orderId;
private String customerName;
private String pizzaSize;
private String toppingType;
private double distanceForDelivery;
//Constants
private final double SMALL =8,MEDIUM=12,LARGE=16;
private final double PEPPERONI_TOPPING=1,SAUSAGE_TOPPING=2;
//Methods
public PizzaOrder(int orderId, String customerName, String pizzaSize, String toppingType, double distanceForDelivery) {
this.orderId = orderId;
this.customerName = customerName;
this.pizzaSize = pizzaSize;
this.toppingType = toppingType;
this.distanceForDelivery = distanceForDelivery;
}
//gettters
public int getOrderId() {
return orderId;
}
public String getCustomerName() {
return customerName;
}
public String getPizzaSize() {
return pizzaSize;
}
public String getToppingType() {
return toppingType;
}
public double getDistanceForDelivery() {
return distanceForDelivery;
}
//Setters
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public void setPizzaSize(String pizzaSize) {
this.pizzaSize = pizzaSize;
}
public void setNumberOfToppings(String toppingType) {
this.toppingType = toppingType;
}
public void setDistanceForDelivery(double distanceForDelivery) {
this.distanceForDelivery = distanceForDelivery;
}
public double calculateDeliveryFee()
{
if(distanceForDelivery==0)
return 0;
else if(distanceForDelivery>0 && distanceForDelivery<=1)
return 2;
else
{
return 2+0.5*(distanceForDelivery-1);
}
}
public double computeToppingFee()
{
if(toppingType.equalsIgnoreCase("pepperoni "))
return PEPPERONI_TOPPING;
else if(toppingType.equalsIgnoreCase("sausage "))
return SAUSAGE_TOPPING;
else
return 0;
}
public double computeTotalCharge()
{
if(pizzaSize.equalsIgnoreCase("small"))
return computeToppingFee()+calculateDeliveryFee()+SMALL;
else if(pizzaSize.equalsIgnoreCase("MEDIUM"))
return computeToppingFee()+calculateDeliveryFee()+MEDIUM;
else
return computeToppingFee()+calculateDeliveryFee()+LARGE;
}
@Override
public String toString() {
return String.format("%-10.30s %-10.30s %-10.30s %-10.30s %-10.30s %-10.30s",orderId,customerName,pizzaSize,toppingType,distanceForDelivery,NumberFormat.getCurrencyInstance().format(computeTotalCharge()));
}
}
//============================================
import java.text.NumberFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
//Create array of Pizza Order
int size=10;
double totalRevenue=0;
Scanner input = new Scanner(System.in);
String name="",pizza="",toppingType="";
int pizzaSize=0,topping=0;
double distance;
PizzaOrder[] pizzaOrders= new PizzaOrder[size];
System.out.println("==============Welcome to Pizza Store==============\n");
for (int i = 0; i <pizzaOrders.length ; i++) {
System.out.println("Enter customer Name: ");
name = input.nextLine();
System.out.println("Select Pizza Size\n1. small - $8\n2. medium-$12\n3.large-$16\n Select any one: ");
pizzaSize = input.nextInt();
System.out.println("Select Topping\n1. Cheese topping\n2. Pepperoni topping\n3. Sausage topping\n Enter a choice: ");
topping = input.nextInt();
System.out.print("Enter distance: ");
distance= input.nextDouble();
if(pizzaSize==1)
pizza="Small";
else if(pizzaSize==2)
pizza="Medium";
else
pizza="Large";
//find topping type
if(topping==1)
toppingType="Cheese";
else if(topping==2)
toppingType="Pepperoni";
else
toppingType="Sausage";
//add Object to orders
pizzaOrders[i]= new PizzaOrder((i+1),name,pizza,toppingType,distance);
totalRevenue+=pizzaOrders[i].computeTotalCharge();
input.nextLine();
}
//print info
System.out.println("==============Order Report===================");
System.out.println(String.format("%-10.30s %-10.30s %-10.30s %-10.30s %-10.30s %-10.30s","Id","Name","Size","Topping","Distance","Total Charge"));
for (int i = 0; i <pizzaOrders.length ; i++) {
System.out.println(pizzaOrders[i]);
}
System.out.println("Total Revenue: "+NumberFormat.getCurrencyInstance().format(totalRevenue));
}
}
//Output

//If you need any help regarding this solution........... please leave a comment ........ thanks
In this project, you are asked to write a program for a Pizza store to process...