Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a solution I need b solution please import java.util.ArrayList; import java.util.Collections; import java.util.Date; class PizzaOrder implements Comparable (private String customerName; private Date dateOrdered;

image text in transcribed

This is a solution I need b solution please

import java.util.ArrayList; import java.util.Collections; import java.util.Date; class PizzaOrder implements Comparable (private String customerName; private Date dateOrdered; final static int SMALL = 1, MEDIUM=2, LARGE = 3; private int pizzaSize; private int numberOfToppings; private double toppingPrice; public PizzaOrder() () public PizzaOrder(String customerName, int pizzaSize, int numberOfToppings, double toppingPrice) { this.customerName = customerName; this.pizzaSize = pizzaSize; this.numberOfToppings = numberOfToppings; this.topping Price = toppingPrice; } public String getCustomerName() { return customerName; } public void setCustomerName(String customerName) { this.customerName = customerName; } public Date getDateOrdered() { return dateOrdered; } public void setDateOrdered(Date dateOrdered) { this.dateOrdered = dateOrdered; } public int getPizzaSize() { return pizzaSize; } public void setPizzaSize(int pizzaSize) { this.pizzaSize = pizzaSize; } public int getNumberOfToppings() { return numberOfToppings;) public void setNumberOfToppings (int numberOfToppings) { this.numberOfToppings = numberOfToppings; } public double getToppingPrice() { return toppingPrice; } public void setToppingPrice(double toppingPrice) { this.toppingPrice = toppingPrice; } public double calculateOrderPrice() { return (numberOfToppings topping Price) pizzaSize; } public void printOrderinfo() { System.out.println(customerName+":" calculateOrderPrice()); } @Override public int compareTo(PizzaOrder o) { return Double.compare(calculateOrderPrice(). o.calculateOrderPrice()); } @Override public String toString() { return "PizzaOrder(" + "customerName="" + customerName + ""+", dateOrdered=" + dateOrdered + ", pizzaSize="+ pizzaSize + ", numberOfToppings="+ numberOfToppings+", toppingPrice=" + toppingPrice+"')";}} class Delivery extends PizzaOrder { private double tripRate; private int zone; public Delivery() { } public Delivery(String customerName, int pizzaSize, int numberOfToppings, double toppingPrice, double tripRate, int zone) { super(customerName, pizzaSize, numberOfToppings, toppingPrice); this.tripRate = tripRate; this.zone zone; } public double getTripRate() { return tripRate; } public void set TripRate(double tripRate) { this.tripRate = tripRate; }

Explanation:

Step 2 of 6

public int getZone() {return zone; } public void setZone (int zone) { this.zone zone; } @Override public double calculateOrderPrice() { return (super.calculateOrderPrice()+ (tripRate/100 super.calculateOrderPrice() zone)); } @Override public String toString() { return "Delivery(" + "customerName="" + super.getCustomerName() + ""+", tripRate="+tripRate+", zone=" + zone +

Explanation:

Step 3 of 6

class ToGo extends PizzaOrder

customerName, int pizzaSize, int numberOfToppings, double toppingPrice) (

public ToGo()() public ToGo(String super(customerName, pizzaSize, numberOfToppings, toppingPrice); } @Override public String toString() return "ToGo("+ "customerName="" + super.getCustomerName() +

class Seated extends PizzaOrder { private double serviceCharge; private int numberOfPeople; public Seated() {} public Seated(String customerName, int pizzaSize, int numberOfToppings, double toppingPrice, double serviceCharge, int numberOfPeople) { super(customerName, pizzaSize, numberOfToppings, toppingPrice); this.serviceCharge serviceCharge; this.numberOfPeople = numberOfPeople; } public double getServiceCharge() { return serviceCharge; } public void setServiceCharge(double serviceCharge) { this.serviceCharge = serviceCharge; } public int getNumberOfPeople() { return numberOfPeople; } public void setNumberOfPeople(int numberOfPeople) { this.numberOfPeople = numberOfPeople;) @Override public double calculateOrderPrice() { return (super.calculateOrderPrice()+ (serviceCharge numberOfPeople)); } @Override public String toString() (return "Seated(" + "customerName="+super.getCustomerName() + 1"+", serviceCharge="+ serviceCharge+", numberOfPeople" + numberOfPeople + ":)

class Driver (public static void main(String[] args) { ArrayList orders = new ArrayList(); orders.add(new Delivery("John". PizzaOrder.LARGE, 2, 3.5, 0.1, 1)); orders.add(new Delivery("Mike", PizzaOrder.MEDIUM, 3, 4.5, 0.2, 2)); orders.add(new ToGo("Jessica", PizzaOrder.SMALL, 1, 2.5)); orders.add(new Seated("Mary", PizzaOrder.LARGE, 3, 4.5, 0.1, 4)); orders.add(new Seated("Steven", PizzaOrder.MEDIUM, 2, 3.5, 0.2, 6)); sortOrders(orders); printSortedOrders(orders); System.out.println("Total sum of all order prices: " +calculateTotalOrders Price(orders)); System.out.println("Report for second Delivery order:" orders.get(1)); } Explanation:

Step 4 of 6

public static void sortOrders (ArrayList orders) { Collections.sort(orders); } public static void printSortedOrders (ArrayList orders) { for (PizzaOrder order: orders) (order.printOrderinfo(): }} public static double calculateTotal OrdersPrice(ArrayList orders) { double totalPrice = 0; for (PizzaOrder order: orders) { totalPrice += order.calculateOrderPrice(); } return totalPrice;}} Explanation:

Step 5 of 6

This program creates the five classes as specified, including the appropriate constructors, setter and getter methods, and methods for calculating the order price and printing order information. The Driver class includes a mae method that creates an ArrayList of zzaOrder objects, adds five different orders to it, sorts the orders based on their calculated order price, prints the sorted orders' customer names and prices, prints the total sum of all order prices, and prints a report for the second delivery order. Additionally, the Driver class

includes two helper methods: sortOrders and calca--

teTotalOrdersPrice, which are used in the mac method.

Explanation:

Step 5 of 6

This program creates the five classes as specified, including the appropriate constructors, setter and getter methods, and methods for calculating the order price and printing order information. The Driver class includes a mae method that creates an ArrayList of zzaOrder objects, adds five different orders to it, sorts the orders based on their calculated order price, prints the sorted orders' customer names and prices, prints the total sum of all order prices, and prints a report for the second delivery order. Additionally, the Driver class includes two helper methods: sortOrders and calca-- teTotalOrdersPrice, which are used in the mae method.

Explanation:

Step 6 of 6

It's worth noting that the Pizza Order class implements the Comparable interface and overrides the compareTo method. The compareTo method compares the prices of two PizzaOrder objects, allowing the Collections.sort method to sort the ArrayList of orders based on their prices. It's also worth noting that the toString method for Delivery, ToGo, and Seated classes are overridden, in order to display the specific properties of those classes. In the main method, the objects are created by passing the attributes in the order specified in the prompt, and the attributes are hardcoded, not taking the input from the user. Finally, the calculateOrder Price method in the Delivery and Seated classes override the one in the PizzaOrder class and adds the appropriate calculation to the price.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions