(JAVA) Using the IntelliJ create the following Java command line pizza shop orde
ID: 3728938 • Letter: #
Question
(JAVA)
Using the IntelliJ create the following Java command line pizza shop ordering application. Make sure to include the standard project header comments in all the classes. Upload all the classes code and the running application.
Create the following classes: Lab9Oakes.java (replace Oakes with your last name), Menu.java, Order.java, Customer.java, and Transaction.java. Add all the class properties and methods members needed to define the pizza shop objects that will be built from these classes. Please use proper access modifiers.
The menu items will use ArrayList collections that will contain an item name and a price.
The menu items can be added or removed to the order with a quantity value.
The customer can enter or edit their information.
The transaction class will handle the payment selection
Use what you learned from the Input/Output zybooks to handle input and output.
Explanation / Answer
Create a simple java/maven project.
Create package package com.chegg.model;
Include first four classes in above package.
Create package package com.chegg.service;
Include last class in above package.
Run Lab9Sardana class to check the behaviour.
package com.chegg.model;
public class Customer {
private long custId;
private String custName;
public long getCustId() {
return custId;
}
public void setCustId(long custId) {
this.custId = custId;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
}
package com.chegg.model;
public class Item {
private String name;
private int price;
private int quantity;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
package com.chegg.model;
import java.util.List;
public class Menu {
private List<Item> items;
public Menu(List<Item> items) {
super();
this.items = items;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
package com.chegg.model;
import java.util.List;
public class Order {
private String orderId;
private List<Item> items;
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
package com.chegg.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.chegg.model.Customer;
import com.chegg.model.Item;
import com.chegg.model.Menu;
import com.chegg.model.Order;
public class Lab9Sardana {
private static List<Item> menuList = createMenu();
private static List<Customer> customerList = new ArrayList<Customer>();
static int custId = 1;
public static void main(String[] args) {
// TODO Auto-generated method stub
Menu menu = new Menu(menuList);
while (true) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your choice");
System.out.println("1. Place an order.");
System.out.println("2. Edit customer details");
System.out.println("3. Add customer");
System.out.println("4. Add items to Menu");
System.out.println("5. exit");
int choice = sc.nextInt();
if (choice == 1) {
System.out.println("");
System.out.println("Available items:");
int i = 1;
for (Item item : menuList) {
System.out.println(i + ": item: " + item.getName() + " price: " + item.getPrice());
i++;
}
System.out.println("Enter your item");
int item = sc.nextInt();
if (item > menuList.size()) {
System.out.println("Item not present. Please enter again");
item = sc.nextInt();
}
Order order = new Order();
Item orderedItem = menu.getItems().get(item - 1);
List<Item> orderdItemList = new ArrayList<Item>();
orderdItemList.add(orderedItem);
order.setItems(orderdItemList);
System.out.println("you choose " + menu.getItems().get(item - 1).getName() + ". Please pay $"
+ menu.getItems().get(item - 1).getPrice() + ".");
System.out.println("Type the amount to pay for an order");
int amount = sc.nextInt();
if (amount == menu.getItems().get(item - 1).getPrice()) {
System.out.println("Your order has been placed");
} else {
System.out.println("Invalid amount");
}
} else if (choice == 2) {
System.out.println("");
System.out.println("Enter current customer Name");
String name = sc.next();
System.out.println("Enter updated customer Name");
String updatedName = sc.next();
if (updateCustomer(name, updatedName)) {
System.out.println("Customer updated successfully");
} else {
System.out.println("Customer not found.");
}
} else if (choice == 3)
{
System.out.println("");
System.out.println("Enter customer Name");
String name = sc.next();
if (addCustomer(name)) {
System.out.println("Customer added successfully");
} else {
System.out.println("Error adding the customer");
}
} else if (choice == 4) {
System.out.println("");
System.out.println("Enter item name to add");
String name = sc.next();
System.out.println("Enter price of the item");
int price = sc.nextInt();
Item newItem = new Item();
newItem.setName(name);
newItem.setPrice(price);
menuList.add(newItem);
System.out.println("Item added succesfully");
} else if (choice == 5) {
sc.close();
break;
} else {
System.out.println("Invalid choice");
}
}
}
private static List<Item> createMenu() {
List<Item> menu = new ArrayList<Item>();
Item item1 = new Item();
item1.setName("cheese pizza");
item1.setPrice(200);
Item item2 = new Item();
item2.setName("veg pizza");
item2.setPrice(150);
menu.add(item1);
menu.add(item2);
return menu;
}
private static boolean addCustomer(String name) {
Customer cust = new Customer();
cust.setCustId(custId);
custId++;
cust.setCustName(name);
return customerList.add(cust);
}
private static boolean updateCustomer(String name, String updatedName) {
if (customerList.size() == 0) {
return false;
}
for (Customer cust : customerList) {
if (cust.getCustName().equals(name)) {
cust.setCustName(updatedName);
return true;
}
}
return false;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.