Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement a Java program that creates a GUI that will take the orders

ID: 3589129 • Letter: D

Question

Design and implement a Java program that creates a GUI that will take the orders of customers at a local restaurant. The GUI should allow the user to input the following information: • Customer name • Table Number • Meal (The following items can be ordered burger, pizza, sub, or sandwich) • Side Dishes (The following items can be ordered french fries, coleslaw, potato salad or salad) • Drinks (The following items can be ordered soda, tea, coffee or juice) • Dessert (The following items can be ordered ice cream, pie, cake, cookies) The costs of the above items are as follows: • burger $6 • pizza $12 • sub $8 • sandwich $9 • french fries $5.50 • coleslaw $4.50 • potato salad $4.50 • salad $6.50 • soda $3 • tea $2 • coffee $2.50 • juice $1.50 • ice cream $3.00 • pie $3.50 • cake $4.00 • cookies $2.50 Once the order is placed the system should display the customer's the bill. Make sure error checking is done on all input. If an error is found the customer should be notified and allowed to re-enter data.

Explanation / Answer

Hii... Please find below code and paste according to their classes.

ShoppingCart.java

package com.bill;

import java.util.Scanner;

public class ShoppingCart {

public static void main( String [] args) {

Scanner input = new Scanner(System.in);

ShoppingList myList = new ShoppingList();

int userOpt = 0;

int secondOpt=0;

String customerName="";

int tableNumber=0;

String option="";

while (userOpt != 4) {

System.out.println("");

System.out.println("----- Welcome to Order Billing------");

System.out.println("----- Select size of cake------");

System.out.println("(1) Enter Bill. ");

System.out.println("(2) Display Final Bill. ");

System.out.println("(3) Clear Bill. ");

System.out.println("(4) Exit. ");

userOpt = input.nextInt();  

int thirdInput=0;

  

if(userOpt==1){

System.out.println("");

while(customerName.isEmpty()){

  

customerName = input.nextLine();

if(customerName.isEmpty())

System.out.println("Enter Customer Name:");

}

while(tableNumber==0){

if(tableNumber==0)

System.out.println("Enter Table Number");

tableNumber = input.nextInt();

}

  

while(secondOpt!=5){

System.out.println("Select Meal");

  

System.out.println("(1) Burger ");

System.out.println("(2) Pizza. ");

System.out.println("(3) Sub. ");

System.out.println("(4) Sandwich. ");

System.out.println("(5) Exit Meals. ");

secondOpt = input.nextInt();

if((secondOpt!=5))

myList.addItem(secondOpt,"meal");

  

}

secondOpt=0;

while(secondOpt!=5){

System.out.println("Select Side Dishes");

  

System.out.println("(1) French fries ");

System.out.println("(2) coleslaw. ");

System.out.println("(3) potato salad . ");

System.out.println("(4) salad. ");

System.out.println("(5) Exit side dishes. ");

secondOpt = input.nextInt();

if(secondOpt!=5)

myList.addItem(secondOpt,"dishes");

}

secondOpt=0;

while(secondOpt!=5){

System.out.println("Select Drinks");

  

System.out.println("(1) Soda ");

System.out.println("(2) Tea. ");

System.out.println("(3) Cofee . ");

System.out.println("(4) Juice. ");

System.out.println("(5) Exit drinks. ");

secondOpt = input.nextInt();

if(secondOpt!=5)

myList.addItem(secondOpt,"drinks");

}

secondOpt=0;

while(secondOpt!=5){

System.out.println("Select Dessert");

  

System.out.println("(1) Ice Cream ");

System.out.println("(2) Pie. ");

System.out.println("(3) Cake . ");

System.out.println("(4) Cookies. ");

System.out.println("(5) Exit Desserts. ");

secondOpt = input.nextInt();

if(secondOpt!=5)

myList.addItem(secondOpt,"desserts");

}

  

  

//System.out.println(userOpt+":::User selection:::"+secondOpt);

  

}

if (userOpt == 2) {

System.out.println("--------Bill----------");

System.out.println("Customer Name:"+customerName);

System.out.println("Table Number:"+customerName);

myList.displayItem();

System.out.println("");

while(option.isEmpty()){

option = input.nextLine();

if(option.isEmpty())

System.out.println("If you want to renter bill(Yes/no)");

}

if("yes".equalsIgnoreCase(option)){

myList.removeAll();

//input=1;

}else{

}

}

if (userOpt == 3) {

myList.removeAll();

}

  

}

}

}

---------------

ShoppingList.java

package com.bill;

import java.util.ArrayList;

import java.util.*;

import java.util.Scanner;

public class ShoppingList {

List<String> mealList = new ArrayList<String>();

List<String> dishList = new ArrayList<String>();

List<String> dessertList = new ArrayList<String>();

List<String> drinkList = new ArrayList<String>();

Map<Integer,Double> dishMap = new HashMap<Integer,Double>();

Map<Integer,Double> mealMap = new HashMap<Integer,Double>();

Map<Integer,Double> dessertMap = new HashMap<Integer,Double>();

Map<Integer,Double> drinkMap = new HashMap<Integer,Double>();

ShoppingList(){

mealList.add("Burger");

mealList.add("Pizza");

mealList.add("Sub");

mealList.add("Sandwitch");

drinkList.add("Soda");

drinkList.add("Tea");

drinkList.add("Cofee");

drinkList.add("Juice");

dishList.add("French fries");

dishList.add("coleslaw");

dishList.add("potato salad");

dishList.add("salad");

dessertList.add("Ice Cream");

dessertList.add("Pie");

dessertList.add("Cake");

dessertList.add("Cookies");

mealMap.put(1, 6.00);

mealMap.put(2, 12.00);

mealMap.put(3, 8.00);

mealMap.put(4, 9.00);

drinkMap.put(1, 3.00);

drinkMap.put(2, 2.00);

drinkMap.put(3, 2.50);

drinkMap.put(4, 1.50);

dishMap.put(1, 5.50);

dishMap.put(2, 4.50);

dishMap.put(3, 4.50);

dishMap.put(4, 6.50);

dessertMap.put(1, 3.00);

dessertMap.put(2, 3.50);

dessertMap.put(3, 4.00);

dessertMap.put(4, 2.50);

}

ArrayList<ShoppingItem> list = new ArrayList<ShoppingItem>();

//Add a new ShoppingItem to the list

public void addItem(int input,String string)

{

double ItemPrice = 0.0;

//System.out.println("enter in the name of your item");

Scanner keyboard = new Scanner(System.in);

String ItemName = "";

if(string.equalsIgnoreCase("meal")){

ItemName = mealList.get(input-1);

ItemPrice = mealMap.get(input);

}else if(string.equalsIgnoreCase("dishes")){

ItemName = dishList.get(input-1);

ItemPrice = dishMap.get(input);

}

else if(string.equalsIgnoreCase("desserts")){

ItemName = dessertList.get(input-1);

ItemPrice = dessertMap.get(input);

}else{

ItemName = drinkList.get(input-1);

ItemPrice = drinkMap.get(input);

}

System.out.println("enter in the Qty of your item");

int ItemQty = keyboard.nextInt();

double totalCost=ItemPrice*ItemQty;

ShoppingItem Item = new ShoppingItem(ItemName, ItemPrice,

ItemQty,totalCost);

list.add(Item);

System.out.println("Item Added");

}

//Display list and total number of items.

public void displayItem(){

System.out.println( list.size()+ " items. ");

double totalCost=0.0;

for (ShoppingItem x : list) {

System.out.println(x.toString());

totalCost+=x.getTotalCost();

}

System.out.println("Total Cost::"+totalCost);

}

public void removeAll() {

// TODO Auto-generated method stub

list.clear();

}

}

-------------------

ShoppingItem.java

package com.bill;

public class ShoppingItem {

private String ItemName;

private double ItemPrice;

private int ItemQty;

private double totalCost;

public double getTotalCost() {

return totalCost;

}

public void setTotalCost(double totalCost) {

this.totalCost = totalCost;

}

public void setItemPrice(double itemPrice) {

ItemPrice = itemPrice;

}

public ShoppingItem()

{

ItemName = "Fruit";

ItemPrice = 100;

ItemQty = 1;

totalCost = 100;

}

public ShoppingItem(String ItemName, double ItemPrice, int ItemQty, double totalCost )

{

this.ItemName = ItemName;

this.ItemPrice = ItemPrice;

this.ItemQty = ItemQty;

this.totalCost = totalCost;

}

public String getItemName() {

return ItemName;

}

public double getItemPrice() {

return ItemPrice;

}

public double getItemTotalPrice() {

return ItemPrice * ItemQty;

}

public int getItemQty() {

return ItemQty;

}

public void setItemName(String ItemName)

{

this.ItemName = ItemName;

}

public void setItempPrice(double ItemPrice)

{

this.ItemPrice = ItemPrice;

}

public void setItemQty(int ItemQty)

{

this.ItemQty = ItemQty;

}

@Override

public String toString()

{

String state = ItemName + " - €" + ItemPrice + " x " + ItemQty+ " x " + totalCost;

return state;

}

}

Please check once.. any querries comment here. Thank you all the best

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote