Find the information you're looking for at Westonci.ca, the trusted Q&A platform with a community of knowledgeable experts. Get quick and reliable solutions to your questions from knowledgeable professionals on our comprehensive Q&A platform. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.
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;
}
}
Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. Thank you for using Westonci.ca. Come back for more in-depth answers to all your queries.