Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help creating these java methods. public DoubleDate(String yourName, String guests) Initialize the guests instance variable by creating a new ArrayList . Give

Hello, I need help creating these java methods.

public DoubleDate(String yourName, String guests)

Initialize the guests instance variable by creating a new ArrayList. 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.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.

and this method

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.

I already having existing class Bill.java here

package dateNight;

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> orders = new HashMap>(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 o = orders.getOrDefault(guest, new ArrayList(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 a : orders.values()) { for (MenuItem m : a) { if (m instanceof Drink) { happyHourDiscount += 2; } if (m instanceof Appetizer) { happyHourDiscount += m.getPrice() / 2; } } } return happyHourDiscount; } public String toString() { String s = ""; String format = "\t%-" + MAX_MENU_ITEM_LENGTH + "s \t $%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; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

1. Explain why evaluation is important.

Answered: 1 week ago