Lab 2(JAVA). Requirements: Create a program that serves as a storefront The foll
ID: 3695297 • Letter: L
Question
Lab 2(JAVA).
Requirements:
Create a program that serves as a storefront
The following items will be for sale
Ice Cream – $1.25
Burger – $3.50
Hot Dog – $4.00
Fries – $2.50
Slice of Cake – $6.75
The program will present a menu with the following options:
List items in cart
Display all items here along with their price.
Display the total cost
Add item to cart
they select it, display a confirmation of purchase text
Checkout
Print all the items and their price in the order as well as the total price, ask user to pay
If the payment is too small, reject and ask again
If payment is enough, inform the user what their change is(if any) and return to the main menu.
Each option will be a numeric value starting at 1
1. List Items in Cart
2. Add Item to Cart
3. Checkout
The main function must be inside of a class called Main.
If your program can be crashed, you will receive a 25 point deduction. This is to say, you should not trust user input. If a user enters an incorrect input, you should notify them of the error and ask them to enter the input again
Supply a scanned UML Class Diagram that details your design.
Include the class that will contain main
Grade Breakdown:
Correct Price and Change Calculation = 15 Points
Correct Input Handling = 15 Points
Correct Menus = 15 Points
Correct Class Diagram = 30 Points
Quality of Design = 25 Points
Total = 100 Points
ADDITIONALLY DO ALSO THIS.....
Requirements:
Create a program that satisfies all the requirements of Lab 2 and the following
The following additional items will be for sale
Burger and Fries Combo
The price should be equal to the combined process of Burger and Fries.
This shouldn’t be a hardcoded thing…If the price of burger and fries changes, this code shouldn’t have to be rewritten.
Hot Dog and Fries Combo
The price should be equal to the combined process of Hot Dog and Fries. This shouldn’t be a hardcoded thing…If the price of burger and fries changes, this code shouldn’t have to be rewritten.
Incorporate the Composite Pattern
Supply a scanned UML Class Diagram that details your design.
Include the class that will contain main
Grade Breakdown:
Correct Implementation of Composite Pattern = 45 Points
Correct Class Diagram = 30 Points
Quality of Design = 25 Points
Explanation / Answer
public class ShoppingItem { private String ItemName; private double ItemPrice; private int ItemQty; public ShoppingItem() { ItemName = "Fruit"; ItemPrice = 100; ItemQty = 1; } public ShoppingItem(String ItemName, double ItemPrice, int ItemQty ) { this.ItemName = ItemName; this.ItemPrice = ItemPrice; this.ItemQty = ItemQty; } 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; return state; } } import java.util.ArrayList; import java.util.Scanner; public class ShoppingList { ArrayList list = new ArrayList(); //Add a new ShoppingItem to the list public void addItem() { System.out.println(); System.out.println("enter in the name of your item"); Scanner keyboard = new Scanner(System.in); String ItemName = keyboard.nextLine(); System.out.println("enter in the price of your item"); double ItemPrice = keyboard.nextDouble(); System.out.println("enter in the Qty of your item"); int ItemQty = keyboard.nextInt(); ShoppingItem Item = new ShoppingItem(ItemName, ItemPrice, ItemQty); list.add(Item); System.out.println("Item Added"); } //Display list and total number of items. public void displayItem(){ System.out.println( list.size()+ " items. "); for (ShoppingItem x : list) { System.out.println(x.toString()); } } } import java.util.Scanner; public class Application { public static void main( String [] args) { Scanner input = new Scanner(System.in); ShoppingList myList = new ShoppingList(); int userOpt = 0; while (userOpt != 3) { System.out.println(""); System.out.println("----- Shopping List------"); System.out.println("(1) Add an item to the list. "); System.out.println("(2) Display list and total number of items. "); System.out.println("(3) Exit. "); userOpt = input.nextInt(); if (userOpt == 1) { myList.addItem(); } if (userOpt == 2) { myList.displayItem(); } } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.