Question
Please help me with this java program You are to write a program to simulate the counter activity at a deli. The actions that can
Please help me with this java program
You are to write a program to simulate the counter activity at a deli. The actions that can be taken are given by the String[] in the DeliCounter class provided. Only the major components of the classes you are to write will be provided; other requirements will have to be derived and provided based on implied program behavior.
Write the following classes
MenuItem
Write an abstract class MenuItem. The delis menu is, simply, a collection of MenuItem objects. All MenuItems have a name and a price. Well assume that all names are a single word (no embedded spaces) and all prices can be represented as a double value. MenuItem has an abstract method, boolean isInventory(). More on inventory below.
PackagedItem
Some items on the delis menu are pre-packaged and considered inventory; bottles of water, cans of soft drinks, bags of chips are examples. These items, in addition to a name and unit price, have a quantity. For example, the deli may have 50 bags of chips on hand. The quantity must be adjusted as items are sold. (We wont worry about restocking for this program.) The owner of the shop wants to know the total value of his packaged inventory items.
PreparedItem
Some items on the delis menu must be prepared for each order. Such items are not considered to be inventory. In addition to a name and price, PreparedItems have a preparation time that is kept in minutes.
Additional Program Capability
Initially, the deli program starts with an empty menu. It should be able to save and restore the menu on demand. It should be able to offer customers the list of items that may be ordered, sell an item, add new items to the menu, and list the current value of the packaged items.
Sample Execution
The following is a sample execution.
[0] Restore Inventory
[1] Save Inventory
[2] List Total Packaged Item Value
[3] List Menu
[4] Order Item
[5] Add New Package
[6] Add New Cooked Item
[7] Exit
3
[0] Restore Inventory
[1] Save Inventory
[2] List Total Packaged Item Value
[3] List Menu
[4] Order Item
[5] Add New Package
[6] Add New Cooked Item
[7] Exit
5
Add a new packaged item:
Item name:
chips
Item price:
1.50
Item quantity:
10
**********************************
DeliCounter.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class DeliCounter {
public static final String[] ACTIONS = { "Restore Inventory", "Save Inventory", "List Total Packaged Item Value",
"List Menu", "Order Item", "Add New Package", "Add New Cooked Item", "Exit" };
public static void main(String[] args) {
ArrayList menu = new ArrayList<>();
Scanner kybd = new Scanner(System.in);
DeliCounter deli = new DeliCounter();
displayMenu(ACTIONS);
int activity = kybd.nextInt();
while (!ACTIONS[activity].equalsIgnoreCase("Exit")) {
if (ACTIONS[activity].equalsIgnoreCase("Restore Inventory")) {
menu = restoreInventory();
} else if (ACTIONS[activity].equalsIgnoreCase("Save Inventory")) {
saveInventory(menu);
} else if (ACTIONS[activity].equalsIgnoreCase("List Total Packaged Item Value")) {
displayPackageValue(menu);
} else if (ACTIONS[activity].equalsIgnoreCase("List Menu")) {
displayMenu(menu);
} else if (ACTIONS[activity].equalsIgnoreCase("Order Item")) {
System.out.println("Which item number do you want? ");
int itemNum = kybd.nextInt();
orderItem(itemNum, menu);
} else if (ACTIONS[activity].equalsIgnoreCase("Add New Package")) {
MenuItem newItem = newPackagedItem(kybd);
menu.add(newItem);
} else if (ACTIONS[activity].equalsIgnoreCase("Add New Cooked Item")) {
MenuItem newItem = addCooked(kybd);
menu.add(newItem);
} else {
System.out.println("Invalid input ignored");
}
displayMenu(ACTIONS);
activity = kybd.nextInt();
}
}
private static MenuItem addCooked(Scanner kybd) {
System.out.println("Add a new cooked item: ");
return null;
}
private static MenuItem newPackagedItem(Scanner kybd) {
System.out.println("Add a new packaged item: ");
return null;
}
private static void orderItem(int itemNum, ArrayList menu) {
}
private static void displayMenu(ArrayList items) {
System.out.println(" ");
System.out.println(" ");
}
private static void displayPackageValue(ArrayList menu) {
System.out.println(" ");
}
private static void saveInventory(ArrayList menu) {
}
private static ArrayList restoreInventory() {
return null;
}
public static void displayMenu(String[] items) {
System.out.println(" ");
for (int i = 0; i < items.length; i++) {
System.out.println("[" + i + "] " + items[i]);
}
System.out.println(" ");
}
}
*******************************
MenuItem.java
// stub to help DeliCounter compile initially
public class MenuItem {
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started