Respuesta :
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;
}
}
