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

Hello, I need help creating this java class with this information. Imported Clas

ID: 3709265 • Letter: H

Question

Hello, I need help creating this java class with this information.

Imported Classes

java.util.ArrayList

java.util.Arrays

java.util.Random (optional)

cst8132.restaurant.Menu

cst8132.restaurant.Restaurant

Instance Variables

ArrayList<String> guests

String[] movies

String movieTitle

int movieTime

Restaurant restaurant

Menu menu

Bill bill

Class Variables

Random random

Methodspublic DoubleDate(String yourName, String… guests)

Initialize the guests instance variable by creating a new ArrayList<String>. Give your ArrayList a default capacity of 4.

Using the ArrayList add method, add your name to the ArrayList. This will insert your name in position 0 of the ArrayList.

If there are any additional guests to add, use the ArrayList addAll and Arrays.<String>asList(array) methods to add the optional guests to the ArrayList.

Initialize the restaurant by calling the static Restaurant.getInstance(String name) method.

Initialize the menu by calling the restaurant.getMenu() method, and then invoking the addMenuItems() method.

Initialize the bill by calling the default constructor of the Bill class.

Initialize the movies array by adding at least 3 movie titles to the array.

public String pickAMovie(String[] movies)

Using either the Math.random or Random.nextInt method, select a movie to attend, and return this value.

public int getShowing()

Using either the Math.random or Random.nextInt method, randomly return the value 6 or 10, to represent the time you will be attending the movie.

public void addMenuItems()

There is a method in the Menu class with the following signature:

public boolean addMenuItem(String itemType, String name, double price)

Using this method and the itemType values listed below, add at least 3 items of each type to your menu. Drink prices should be at least $5.00. Dessert and Appetizer prices must be evenly divisible by 2.

Drinks

Desserts

Appetizers

Entrees

Menu item names should be a maximum of 30 characters in length for optimal formatting of outpout.

public boolean placeOrder(String guest, String itemType)

Get a random MenuItem to order by calling the getRandomMenuItem(String itemType) method of the Menu class.

Add this MenuItem to this person’s order by calling the addOrderItem(String guest, MenuItem menuItem) method of the Bill class.

The addOrderItem method returns a boolean value, which should be returned by this placeOrder method.

public static void main(String[] args)

Initialize a new DoubleDate by passing name(s) to the constructor. The first name passed should be your own. The second name would be your date. The third name would be your date’s friend and the fourth name passed would be their date. Note that only the first name is mandatory.

Pass a String array of at least 3 movie titles (enter your own set of titles) to the pickAMovie method and assign the return value to the movieTitle instance variable.

Call the getShowing method and assign the return value to the movieTime variable.

Based on the movieTime, set the isHappyHour variable of your Bill by calling the setHappyHour(boolean isHappyHour) method.

For each guest at the restaurant, call the placeOrder(String guest, String itemType) method as needed, based on the requirements in the program description. This will add random menu items to your bill.

Print the DoubleDate object by implicitly calling its toString() method, like this:

public String toString()

Output the list of movie options, the selected movie, and show time.

Output the name of the restaurant, and based on the show time, whether you will be meeting there before or after the movie.

Output one of the following statements:

It's happy hour! $2 off drinks, and 1/2 price appetizers!!

We'll be missing happy hour, but we'll still be happy!

Output the menu, by calling its toString() method.

Output the bill, by calling its toString() method.

Explanation / Answer

import cst8132.restaurant.Menu;
import cst8132.restaurant.MenuItem;
import cst8132.restaurant.Restaurant;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;


public class DoubleDate extends JFrame {

    protected ArrayList<String> guests;
    protected String[] movies;
    protected String movieTitle;
    protected int movieTime;
    protected Restaurant restaurant;
    protected Menu menu;
    protected Bill bill;

    private JPanel inputPanel;
    private JPanel guestList;
    private JLabel addGuestPrompt;
    private JLabel guestListHeader;
    private JTextField newGuestName;
    private JButton addGuest;
    private JButton letsGo;


    private Random random;


    public static void main(String[] args) {

        DoubleDate date = new DoubleDate("Andrew", "Nina", "Connor", "Lisa");
        date.pickAMovie();
        date.getShowing();

        if (date.movieTime == 10) {
            date.bill.setHappyHour();
        }

        date.placeOrder("Andrew", "drinks");
        date.placeOrder("Nina", "drinks");
        date.placeOrder("Connor", "drinks");
        date.placeOrder("Lisa", "drinks");
        date.placeOrder("Andrew", "appetizers");
        date.placeOrder("Andrew", "entrees");
        date.placeOrder("Nina", "entrees");
        date.placeOrder("Connor", "entrees");
        date.placeOrder("Lisa", "entrees");
        date.placeOrder("Connor", "desserts");

        System.out.println(date);
    }

    public DoubleDate(String yourName, String... guests) {
        //initialize array list capacity and add your name
        this.guests = new ArrayList<String>(4);
        this.guests.add(0, yourName);

        //check to see if any other guests are coming with you
        if (guests != null) {
            this.guests.addAll(Arrays.asList(guests));
        }

        //initialize restaurant
        restaurant = Restaurant.getInstance("The Waverly");

        //initialize a menu
        menu = restaurant.getMenu();

        //populate the menu
        addMenuItems();

        bill = new Bill();

        movies = new String[4];
        movies[0] = "Snatch";
        movies[1] = "The Shawshank Redemption";
        movies[2] = "Baby Driver";
        movies[3] = "Snowpiercer";
    }

    public String pickAMovie() {
        double rando = Math.random();

        if (rando < .25) {
            movieTitle = movies[0];
        } else if (rando < .5 && rando >= .25) {
            movieTitle = movies[1];
        } else if (rando < .75) {
            movieTitle = movies[2];
        } else if (rando < 1) {
            movieTitle = movies[3];
        }

        return movieTitle;
    }

    // Flips a coin to decide what show time the group is going to see.

    public int getShowing() {
        double coinFlip = Math.random();

        if (coinFlip <= .5) {
            movieTime = 6;
        } else {
            movieTime = 10;
        }

        return movieTime;

    }

    // method populates the restaurant menu.

    public void addMenuItems() {

        menu.addMenuItem("Drinks", "Coke", 6);
        menu.addMenuItem("Drinks", "Beer", 8);
        menu.addMenuItem("Drinks", "Wine", 10);
        menu.addMenuItem("Drinks", "Sparkling Water", 4);

        menu.addMenuItem("Appetizers", "Spinach Dip", 14);
        menu.addMenuItem("Appetizers", "Wings", 16);
        menu.addMenuItem("Appetizers", "Nachos", 16);
        menu.addMenuItem("Appetizers", "Cheese Sticks", 12);

        menu.addMenuItem("Entrees", "Burger", 16);
        menu.addMenuItem("Entrees", "Club Sandwich", 16);
        menu.addMenuItem("Entrees", "Chicken Salad", 14);
        menu.addMenuItem("Entrees", "Striploin Steak", 28);

        menu.addMenuItem("Desserts", "Tiramisu", 14);
        menu.addMenuItem("Desserts", "Chocolate brownie", 12);
        menu.addMenuItem("Desserts", "Gelato", 14);
        menu.addMenuItem("Desserts", "Churros", 14);

    }

    //THe placeOrder method is used to generate a random order and add it to the bill.

    public boolean placeOrder(String guest, String itemtype) {
        MenuItem item = menu.getRandomMenuItem(itemtype);
        return bill.addOrderItem(guest, item);
    }

    @Override
    public String toString() {

        if (movieTime == 6) {
            return "Movies: " + " " + movies[0] + " " + movies[1] + " " + movies[2] + " " + movies[3] + " " + " " + "You have" +
                    " chosen " + this.movieTitle + "! " + "We will be meeting at " + this.restaurant.getName() + " after the movie." +
                    " " + "We will be missing happy hour, but we will still be happy! " + "MENU: " + menu.toString() + " " + bill.toString();
        } else {
            return "Movies: " + " " + movies[0] + " " + movies[1] + " " + movies[2] + " " + movies[3] + " " + " " + "You have" +
                    " chosen " + this.movieTitle + "! " + "We will be meeting at " + this.restaurant.getName() + " before the movie. " +
                    "It's happy hour! $2 off drinks, and 1/2 price appetizers!! " + "MENU: " + menu.toString() + " " + bill.toString();
        }
    }


}
----------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
import java.util.HashMap;

import cst8132.restaurant.Appetizer;
import cst8132.restaurant.Drink;
import cst8132.restaurant.MenuItem;


public class Bill {
    private HashMap<String, ArrayList<MenuItem>> orders = new HashMap<String, ArrayList<MenuItem>>(4);

    private boolean isHappyHour = false;
    private double subtotal;
    private double hstRate = 0.15;
    private final int MAX_MENU_ITEM_LENGTH = 30;

    public boolean addOrderItem(String guest, MenuItem item) {

        ArrayList<MenuItem> o = orders.getOrDefault(guest, new ArrayList<MenuItem>(4));
        o.add(item);

        orders.put(guest, o);

        subtotal += item.getPrice();

        return true;
    }


    public double getHappyHourDiscount() {

        double happyHourDiscount = 0;

        if (!isHappyHour)
            return 0;

        for (ArrayList<MenuItem> a : orders.values()) {

            for (MenuItem m : a) {

                if (m instanceof Drink) {
                    happyHourDiscount += 2;
                }

                if (m instanceof Appetizer) {
                    happyHourDiscount += m.getPrice() / 2;
                }

            }

        }

        return happyHourDiscount;
    }

    public void setHappyHour() {
        isHappyHour = true;
    }

    public String toString() {

        String s = "";
        String format = " %-" + MAX_MENU_ITEM_LENGTH + "s $%6.2f ";

        for (String o : orders.keySet()) {

            s += "Dinner Guest: " + o + " ";

            for (MenuItem item : orders.get(o)) {
                s += String.format(format, item.getName(), item.getPrice());
            }

            s += " ";

        }

        s += String.format(format, "Subtotal", getSubtotal());
        s += String.format(format, "Happy Hour Discount", getHappyHourDiscount());
        s += String.format(format, "HST " + (int) (hstRate * 100) + "%", getHst());

        s += String.format(format, "Total", getTotal());

        return s;
    }

    public double getSubtotal() {
        return subtotal;
    }

    public double getHst() {
        double hst;

        if (isHappyHour) {

            hst = (this.subtotal - this.getHappyHourDiscount()) * hstRate;

        } else {

            hst = this.subtotal * hstRate;

        }
        return hst;
    }

    public double getHstRate() {

        return hstRate;
    }

    public double getTotal() {
        if (isHappyHour) {

            return (this.subtotal - this.getHappyHourDiscount()) + getHst();

        }

        return this.subtotal += this.getHst();
    }
}


----------------------------------------------------------------------------------------------------------------------------------
import cst8132.restaurant.MenuItem;

public class Dessert extends MenuItem {
    public Dessert(String name, double price) {
        super(name, price);
    }
}
---------------------------------------------------------------------------------------------------------------------------------
import cst8132.restaurant.MenuItem;

public class Entree extends MenuItem{
    public Entree(String name, double price) {
        super(name, price);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote