Question

In this project, you are asked to write a program for a Pizza store to process...

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:

  1. There are 3 sizes of pizza: small, medium and large. Basic price of a pizza is: small - $8, medium-$12; large-$16.
  2. No additional charge for Cheese topping. For pepperoni topping, the additional charge is $1. For sausage topping, the additional charge is $2. Note that the additional charge is same for different sizes of pizzas.
  3. If the distance is 0 (i.e. self-pickup), no delivery fee. If it is between 0 and 1 mile, the delivery fee is $2. If it is more than 1 mile, it is $2 plus $0.50/mile for mileage over 1 (i.e. if it is 1.5 miles , the total charge is 2 + 0.5*(1.5 -1) = 2.25).

Requirements on your programs:

  1. Create and define a PizzaOrder class. Basic attributes: Order ID (1-10), Customer name, Size of the pizza, topping of the pizza, and distance for delivery. Basic methods: constructor, getters and setters for each attribute, method for computing the delivery fee, method for computing the topping fee, and method for computing the total charge (including the basic price, topping fee, and delivery fee) on a pizza order.
  2. In your main class file
  1. Prompt the user to input detailed information for each of 10 pizza orders. Remind the customers about all possible choices of size and topping.
  2. Create an object for each pizza order using array of objects.
  3. Compute the total charge for each pizza order and the total revenue for all 10 orders.
  4. Print the order information for each of the 10 pizzas in a table format. Information to be printed: Pizza order ID (1-10), Customer name, Size of the pizza, topping of the pizza, distance for delivery, total charge.
  5. Print the total revenue at the end.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//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

Add a comment
Know the answer?
Add Answer to:
In this project, you are asked to write a program for a Pizza store to process...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT