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

The following is to be done with Java. The directions are critical for the proje

ID: 3853780 • Letter: T

Question

The following is to be done with Java.

The directions are critical for the project, I know there are easier ways, but the project calls for the specifics to be followed please.

1) Create classes "MenutItem", "Dessert", "Drink", "Entree", "Menu", "Ticket", and "Driver".

2) "MenuItem" class is an abstract class that "Entree", "Dessert", and "Drink" classes will inherit from. This class needs three attributes: String name, double price, and String orderCode. The orderCode should be a two letter code that the user will enter to select an item. Each attribute should have the needed setters and getters. This class should have an abstract toString Method that will enforce all inheriting classes to implement.

3) "Dessert", "Drink", and "Entree" are concrete class that inherits from (Is-A) MenuItem. Dessert needs one attribute glutonFree and any extra setters and getters for new attributes. Drink is a concrete class that inherits from(Is-A) MenuItem, with 2 attributes: char size and boolean checkID, and any extra setters and getters for new attributes. Entree is a concrete class that inherits from(Is-A) MenuItem, with one attribute of boolean vegan and any extra setters and getters for new attributes.

4) "Menu" Concrete class that contains an Array of MenuItems(up to 20). This needs methods that: A) List all the items on the menu B) Add an item to the menu C) select and get an item from the menu by the orderCode.

5) "Ticket" A concrete class that contains an Array of MenuItems(up to 20). This class should have methods that: A) tab out: Print the current ticket to the screen and show the total of the items order B) View ticket: List the items being ordered C) Add Item: Adds an item to the ticket D) Delete Ticket: Deletes the ticket and starts a new one.

6) "Driver" This class should contain the main method. It should create a Menu and MenuItems(Make up the restaurant and items. Have at least 5 of each concrete items: Entree, Drink, Dessert) It should present a simple command line interface that allows the user to: A) Show the menu(list all menu items) B) Show the current ticket(List all items on the current Ticket) C)Total of the current ticket D) Add Item: Add an item to the current ticket( will show menu and query to user to input an orderCode) E)Delete Ticket: Delete a ticket F)Quit: Quit the program G) Help: Display useful commands.

Most of these commands will be calls to the methods that are built into the Menu and Order objects. The driver acts as a conductor keeping everything organized. The program should have a help option. Be sure not to forget any of the details.

Explanation / Answer

The code contains too many classes, so it was not possible for us to formulate the Driver class within the allocated time. I hope you understand. Let me know if you have an urgency for the Driver class, I shall edit it in my free time.


/**
*
* @author Sam
*/
abstract class MenutItem {
    private String name;
    private double price;
    private String orderCode;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getOrderCode() {
        return orderCode;
    }

    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();
}

class Dessert extends MenutItem {
    private boolean glutonFree;

    public boolean isGlutonFree() {
        return glutonFree;
    }

    public void setGlutonFree(boolean glutonFree) {
        this.glutonFree = glutonFree;
    }

    @Override
    public String toString() {
        return "Dessert{" + "Name=" + getName() + "Price=" + getPrice() + " OderCode=" + getOrderCode() + "glutonFree=" + glutonFree + '}';
    }
  
  
}

class Drink extends MenutItem{
    private char size;
    boolean chekID;

    public char getSize() {
        return size;
    }

    public void setSize(char size) {
        this.size = size;
    }

    public boolean isChekID() {
        return chekID;
    }

    public void setChekID(boolean chekID) {
        this.chekID = chekID;
    }

    @Override
    public String toString() {
        return "Drink{" + "Name=" + getName() + "Price=" + getPrice() + " OderCode=" + getOrderCode() + "size=" + size + ", chekID=" + chekID + '}';
    }
  
}

class Entree extends MenutItem {
    boolean vegan;

    public boolean isVegan() {
        return vegan;
    }

    public void setVegan(boolean vegan) {
        this.vegan = vegan;
    }

    @Override
    public String toString() {
        return "Entree{" + "Name=" + getName() + "Price=" + getPrice() + " OderCode=" + getOrderCode() + "vegan=" + vegan + '}';
    }
  
}

class Menu {
    private MenutItem[] menutItems;
    int n;
    public Menu() {
        menutItems = new MenutItem[20];
        n = 0;
    }
  
    public void listAllItems (){
        for (int i = 0 ; i < n ; i++)
            System.out.println(menutItems[i].getName() + " " + menutItems[i].getOrderCode() + " $" + menutItems[i].getPrice());
    }

    public void addItem() {
      
    }
  
    public MenutItem getItem(String orderCode) {
        for (int i = 0 ; i < n ; i++)
            if (menutItems[i].getOrderCode().equals(orderCode))
                return menutItems[i];
        return null;
    }
}

class Ticket {
    private MenutItem[] menutItems;
    int n;

    public Ticket() {
        menutItems = new MenutItem[20];
        n = 0;
    }
  
    public void addItem(Menu menu, String orderCode) {
        MenutItem menutItem = menu.getItem(orderCode);
        if (menutItem!= null)
        menutItems[n++] = menutItem;
      
    }
  
    public void deleteTicket() {
        n = 0;
    }
  
    public void viewTicket() {
        for (int i = 0 ; i < n ; i++)
            System.out.println(menutItems[i].getName() + " " + menutItems[i].getOrderCode() + " $" + menutItems[i].getPrice());
    }
  
    public void tabOut() {
        int total = 0;
        for (int i = 0 ; i < n ; i++)
            total += menutItems[i].getPrice();
        System.out.println("Total of all item is: " + total);
    }
}

public class Driver {
    public static void main(String[] args) {
        //TODO
    }
}