Find the information you're looking for at Westonci.ca, the trusted Q&A platform with a community of knowledgeable experts. Get immediate and reliable answers to your questions from a community of experienced professionals on our platform. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

Consider an online food delivery service, such as Seamless. Customers and Items are represented by the classes given below. Your task is to create an Order class that will contain information about the customer, an ArrayList of items, and the restaurant name. Create the following methods: - a constructor to initialize these attributes - computeTotal method to compute the total of all items - showOrder method to display the information about the customer, items, and order, including the total public class Customer { private String name; private String phone; private String address; public Customer(String name, String phone, String address) { this.name

Sagot :

Answer:

Explanation:

Since none of the classes were provided in the question I created all of the classes so that the program works as requested in the question. I also created a test order so that you can see the output of the program in the attached picture below.

import java.util.ArrayList;

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       ArrayList<Item> items = new ArrayList<>();

       Item item1 = new Item("banana", 1, 3);

       Item item2 = new Item("apple", 0.5, 6);

       Item item3 = new Item("grapes", 2, 3);

       items.add(item1);

       items.add(item2);

       items.add(item3);

       Customer customer = new Customer("John", "9085526269", "123 Inslee");

       Order myOrder = new Order(customer, items, "Grocery");

       myOrder.showOrder();

   }

}

class Order {

   Customer customer;

   ArrayList<Item> items = new ArrayList<>();

   String restaurant;

   public Order(Customer customer, ArrayList items, String restaurant) {

       this.customer = customer;

       this.items = items;

       this.restaurant = restaurant;

   }

   public void computeTotal() {

       int total = 0;

       for (Item x: items) {

           total += x.total();

       }

       System.out.println("Order Total: " + total);

   }

   public void showOrder() {

       System.out.println(restaurant);

       System.out.println("Name: " + customer.getName());

       System.out.println("Phone: " + customer.getPhone());

       System.out.println("Address: " + customer.getAddress());

       for (Item x :items) {

           System.out.println(x.itemName + " : " + x.quantity);

       }

       computeTotal();

   }

}

class Item {

   String itemName;

   double costPerItem;

   int quantity;

   public Item(String itemName, double costPerItem, int quantity) {

       this.itemName = itemName;

       this.costPerItem = costPerItem;

       this.quantity = quantity;

   }

   public double total() {

       double total = costPerItem * quantity;

       return total;

   }

}

class Customer {

   private String name;

   private String phone;

   private String address;

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public String getPhone() {

       return phone;

   }

   public void setPhone(String phone) {

       this.phone = phone;

   }

   public String getAddress() {

       return address;

   }

   public void setAddress(String address) {

       this.address = address;

   }

   public Customer(String name, String phone, String address) {

       this.name = name;

       this.phone = phone;

       this.address = address;

   }

}

View image sandlee09