Question
Alright, this has to be done in java here, and I am going to list the code that I already have completed first. These classes,
Alright, this has to be done in java here, and I am going to list the code that I already have completed first. These classes, the abstract MenuItems class, Desert Extends MenuItems class, Drink Extends MenuItems Class, Entree Extends MenuItems class, Menu class, and, Ticket class, are all all completed. What needs worked on is the Driver class, which I will have at the bottom, although I dont have any methods or anything at it. My questions will be down there, just above the Driver class, as well so you don't have to continue to scroll up and down through the entire page constantly.
abstract public class MenuItems{ private String name; //name to label all items private String orderCode; //two letter code that selects an item private double price; // price field public String getName(){return name;} public String getOrderCode(){return orderCode;} public double getPrice(){return price;} public void setName(String name){this.name = name;} public void setPrice(double price){this.price = price;} public MenuItems(String name, String orderCode, double price){ this.name = name; this.orderCode = orderCode; this.price = price; } //setOrder has an error catcher so program wont crash if input != 2 characters public void setOrderCode(String orderCode){ if(orderCode.length() == 2) this.orderCode = orderCode; else throw new IllegalArgumentException("Order code must have two " + "characters only!!"); } @Override public abstract String toString(); }
public class Drink extends MenuItems{ private char size; private boolean checkID; public void setSize(char size){this.size = size;} public char getSize(){return size;} public void setCheckID(boolean checkID){this.checkID = checkID;} public boolean getCheckID(){return checkID;} //constructor that extends from MenuItems public Drink(char size, boolean checkID, String name, String orderCode, double price) { super(name, orderCode, price); this.size = size; this.checkID = checkID; } @Override public String toString(){ return "Drink{" + "Name=" + getName() + "Price=" + getPrice() + " OderCode=" + getOrderCode() + "size=" + size + ", chekID=" + checkID + '}'; } }
public class Desert extends MenuItems{ private boolean glutonFree;
public Desert(boolean glutonFree, String name, String orderCode, double price){ super(name, orderCode, price); this.glutonFree = glutonFree; } public boolean getGlutonFree(){return glutonFree;} public void setGlutonFree(boolean glutonFree){this.glutonFree = glutonFree;} @Override public String toString() { return "Dessert{" + "Name=" + getName() + "Price=" + getPrice() + " OderCode=" + getOrderCode() + "glutonFree=" + glutonFree + '}'; } }
public class Entree extends MenuItems{
private boolean vegan; public void setVegan(boolean vegan){this.vegan = vegan;} public boolean getVegan(){return vegan;}
//constructor that extends from MenuItems public Entree(boolean vegan, String name, String orderCode, double price) { super(name, orderCode, price); this.vegan = vegan; } @Override public String toString() { return "Entree{" + "Name=" + getName() + "Price=" + getPrice() + " OrderCode=" + getOrderCode() + "vegan=" + vegan + '}'; } }
public class Menu{ private MenuItems[] menuItems;//array of classes MenuItems int n; //counter number //reserves 20 indexes for objects in array public Menu(){ menuItems = new MenuItems[20]; n = 0; } //lists all items NAME, ORDERCODE, PRICE. public void listAllItems(){ for(int i = 0; i < n; i++){ // System.out.println(menuItems[i].getName()+menuItems[i].getOrderCode() // "\t$" + menuItems[i].getPrice()); System.out.print(menuItems[i].getName()+"\t"+menuItems[i].getOrderCode()); System.out.println("\t$"+menuItems[i].getPrice()); } } public void addItems(){ } //sets up for taking input of orderCode and compare input to orderCode field public MenuItems getItem(String orderCode){ for(int i = 0; i < n; i++) if(menuItems[i].getOrderCode().equals(orderCode)) return menuItems[i]; return null; } }
public class Ticket{ private MenuItems[] menuItems; int n; public Ticket(){ menuItems = new MenuItems[20]; n = 0; } public void addItem(Menu menu, String orderCode){ MenuItems menuItem = menu.getItem(orderCode); if (menuItem != null) menuItems[n++] = menuItem; } public void deleteTicket(){ n = 0; } public void viewTicket(){ for(int i = 0; i < n; i++){ System.out.print(menuItems[i].getName()+"\t"+menuItems[i].getOrderCode()); System.out.println("/t$" + menuItems[i].getPrice()); } } public void tabOut(){ int total = 0; for (int i = 0; i < n ; i++) total += menuItems[i].getPrice(); System.out.println("Total of all item is: " + total); } }
Right now, I need help with getting the arrays established for the drink items, desert items, and entree items. I dont know how to get the arrays established in this polymorphisim so I can hardcode like an entree what an entree's name, price, and if it's vegan or not.
Then I need to put all the MenuItems array into the Menu, and call the menu class so every object prints out.
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