Objective: Create the foundation of a menu and ticket system for a restaurant po
ID: 3914252 • Letter: O
Question
Objective:
Create the foundation of a menu and ticket system for a restaurant point of sale (POS) system using Object Oriented Programming practices. In this project we will create Constructors,
Setters, Getters, and toString methods.
Grade Table:
Task Points
Documentation report 20
Jar file is executable and guidelines are followed 20
Driver class is created as described below 20
Menultem class is created as described below 20
Menu class is created as described below 20
Ticket class is created as described below 25
TOTAL (Points Possible) 125
Instructions:
In this project we are creating part of a restaurant point of sale (POS) system. In future projects we will add additional functionality. For this project you will need to create the following four class files with the listed attributes and methods:
Menultem
String name
Double price
String description o Int orderCode
Each of the above attributes needs appropriate setters and getters o The class needs a toString method
Menu
String restaurantName o ArrayList of Menultems o A method to add items the above ArrayList of Menultems o Setters and getters for the restaurantName o A toString method that prints the name of the restaurant followed by all of the items in theMenu
Ticket
Int tableNumber
ArrayList of Menultems
A method to add items to the above ArrayList of Menultems
Setters and getters for tableNumber
A getTotal method that returns the total of the items in the ArrayList of Menultems
(this is a calculated field) A toString method that prints tableNumber
All of the items in theTicket o The total of the items in ArrayList of Menultems
Driver - A file to test the above classes, the driver should contain the main method and needs to perform the following:
Instantiate 10 Menultems objects with the proper attributes.
Instantiate 1 menu object.
Add the above 10 Menultems to the menu o Print the menu to the screen
Instantiate 2 ticket objects
Add 3 different Menultems to each of the ticket objects
Print both tickets to the screen
Explanation / Answer
Solution: You need to provide all the details thought the file correct file address.
src
Driver.java(Main Method)
DRIVER CLASS CODE:
import static java.lang.System.out;
import java.util.HashMap;
import java.util.Iterator;
import contrainter.net.pos.Item;
import controller.net.pos.MenuCart;
import controller.net.pos.MenuItem;
public class Driver {
public static void main(String[] args)
{
MenuItem itemS = new MenuItem();
HashMap<String, Item> itemMap = itemS.getAllItems();
Iterator<String> iterator = itemMap.keySet().iterator();
out.println("****** List of Available Items **** ");
while(iterator.hasNext())
{
Item item = itemMap.get(iterator.next());
out.println(item.printStatus);
}
out.println("---");
MenuCart cart = new MenuCart();
cart.start();
cart.checkOut();
out.println("Thank you for coming, Have nice day ..!!");
}
}
MENUCART CLASS CODE:
package controller.net.pos;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
import contrainter.net.pos.Customer;
import contrainter.net.pos.Item;
import contrainter.net.pos.Machine;
import contrainter.net.pos.Operator;
import contrainter.net.pos.Transaction;
import dao.net.pos.MenuCartDao;
public class MenuCart {
MenuCartDao cartDao = new MenuCartDao();
@SuppressWarnings("resource")
public void start()
{
int choice = 0;
Scanner scanner = new Scanner(System.in);
do
{
System.out.println("Enter [1 = Add, 2 = Delete, 0 = Exit]");
choice = scanner.nextInt();
switch(choice) {
case 1 :
add();
break;
case 2 :
Scanner sc = new Scanner(System.in);
System.out.println("Enter Item id to be removed = ");
String itemId = sc.next();
delete(itemId);
break;
case 0 :
break;
default:
System.out.println("Invalid choice.");
}
}
while (choice != 0);
}
public void add()
{
cartDao.create();
}
public void checkOut()
{
ArrayList<String> itemIds = cartDao.read();
ArrayList<Item> purchaseditems = cartDao.loadItemDetails(itemIds);
double total = 0;
System.out.println("++++++ List of items purchased ++++++");
for (Item item : purchaseditems) {
total = total + item.getPrice().getAmount();
System.out.println(item.printStatus());
}
System.out.println("-----------------------------------");
System.out.println("Total amount : " + total);
System.out.println("+++++++++++++++++++++++++++++++++++");
recordTransaction(purchaseditems);
}
private void recordTransaction(ArrayList<Item> purchaseditems)
{
Transaction transaction = new Transaction();
transaction.setId("T-788");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
transaction.setDate(dateFormat.format(new Date()));
Operator operator = new Operator();
operator.setId("O-005");
transaction.setOperator(operator);
Machine machine = new Machine();
machine.setId("M-101");
transaction.setMachine(machine);
Customer customer = new Customer();
customer.setId("C-101");
transaction.setCustomer(customer);
Item[] items = purchaseditems.toArray(new Item[purchaseditems.size()]);
transaction.setItems(items);
try {
FileWriter writer = new FileWriter("Bills.txt", true);
BufferedWriter bufferedWriter =new BufferedWriter(writer);
for (Item item : items) {
bufferedWriter.write(transaction.getId());
bufferedWriter.write(",");
bufferedWriter.write(transaction.getDate());
bufferedWriter.write(",");
bufferedWriter.write(transaction.getOperator().getId());
bufferedWriter.write(",");
bufferedWriter.write(transaction.getMachine().getId());
bufferedWriter.write(",");
bufferedWriter.write(transaction.getCustomer().getId());
bufferedWriter.write(",");
bufferedWriter.write(item.getId());
bufferedWriter.write(",");
bufferedWriter.write(String.valueOf(item.getPrice().getAmount()));
bufferedWriter.write(" ");
}
bufferedWriter.flush();
bufferedWriter.close();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void delete(String itemId)
{
cartDao.delete(itemId);
}
}
MENUITEM CLASS CODE:
package controller.net.pos;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;
import contrainter.net.pos.Item;
import contrainter.net.pos.Price;
public class MenuItem
{
@SuppressWarnings("resource")
public HashMap<String, Item> getAllItems()
{
HashMap<String,Item> itemMap = new HashMap<String,Item>();
File itemFile = new File("abc.txt");
{
try
{
Scanner scannner = new Scanner(itemFile);
while(scannner.hasNext())
{
String fileRecord = scannner.nextLine();
String[] fileRecordSplit = fileRecord.split(",");
Item item = new Item();
item.setId(fileRecordSplit[0]);
item.setDescription(fileRecordSplit[1]);
Price price = new Price();
price.setAmount(Double.parseDouble(fileRecordSplit[2]));
price.setCurrency(fileRecordSplit[3]);
item.setPrice(price);
itemMap.put(item.getId(), item);
}
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
return itemMap;
}
}
}
MENUCARTDAO:
package dao.net.pos;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import contrainter.net.pos.Item;
import controller.net.pos.MenuItem;
public class MenuCartDao
{
static ArrayList<String> itemIdList = new ArrayList<String>();
public void create()
{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
String itemId = "0";
do
{
System.out.println("Enter ItemId, [0 = Exit] : ");
itemId = scanner.next();
if (!itemId.equals("0"))
{
itemIdList.add(itemId);
}
}
while (!itemId.equals("0"));
}
public ArrayList<String> read()
{
return itemIdList;
}
public void update()
{
}
public void delete(String itemid)
{
itemIdList.remove(itemid);
}
public ArrayList<Item> loadItemDetails(ArrayList<String> itemIds)
{
ArrayList<Item> purchasedItemList = new ArrayList<Item>();
MenuItem itemS = new MenuItem();
HashMap<String,Item> allItems = itemS.getAllItems();
for (int i = 0; i < itemIds.size(); i++)
{
purchasedItemList.add(allItems.get(itemIds.get(i)));
}
return purchasedItemList;
}
}
CUSTOMER CLASS CODE:
package contrainter.net.pos;
public class Customer
{
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
PRICE CLASS CODE
package contrainter.net.pos;
public class Price {
private double amount;
private String currency;//USD
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
}
TRANSACTION CLASS CODE:
package contrainter.net.pos;
public class Transaction
{
private String id;
private Operator operator;
private Machine machine;
private Customer customer;
private String date;
private Item[] items;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public Item[] getItems() {
return items;
}
public void setItems(Item[] items) {
this.items = items;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
public Machine getMachine() {
return machine;
}
public void setMachine(Machine machine) {
this.machine = machine;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
OPERATION CLASS CODE:
package contrainter.net.pos;
public class Operator {
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
ITEM CLASS CODE:
package contrainter.net.pos;
public class Item
{
private Price price;
private String id;
private String description;
public Object printStatus;
public Price getPrice() {
return price;
}
public void setPrice(Price price) {
this.price = price;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String printStatus()
{
return id + "," +
description + "," +
price.getAmount() + "," +
price.getCurrency()
;
}
}
MACHINE CLASS CODE:
package contrainter.net.pos;
public class Machine
{
private String id;
private String model;
private String vendor;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.