Lab 6: Dinner & A Movie solved



Program Description
You are planning a romantic evening for two when your date invites along another couple. When the night of the big outing rolls around, not everyone is able to make it due to the unpredictable weather. As the organizer you will definitely be in attendance, but you don’t know until you’re already out that you might be the only one who makes it out of the house that night. There will randomly be between 1 – 4 guests on the date night. You can assume that if only two people are going, it is you and your date.
Your evening plans consist of dinner and a movie, however you cannot decide what movie to go to or what time. As a group, you narrow the options down to 3 movies, all playing at either 6:00pm or 10:00pm. You randomly pull a movie title out of a hat and flip a coin to decide which of the two movie times to attend.
The restaurant servers a variety of menu items. The menu is broken up into 4 menu item types – Appetizers, Entrees, Drinks, and Desserts. You all agree to order 1 appetizer for the table, you each order your own entrée and drink, and each couple (or person flying solo) orders a dessert to share. In total, there should be 1 appetizer, 1 – 4 entrees, 1 – 4 drinks, and 1 – 2 desserts ordered by the end of the meal. Each order belongs to a specific guest. You’ve ordered the appetizer, as the host, so it should be part of your order. The desserts should be added to odd-numbered orders (assuming there are between 1 – 4 orders). At the end of the dinner, you will each be presented with your own detailed bill to pay.
The restaurant also has happy hour between 5 – 7pm. Note that if you go to the 6:00pm movie, you will have to eat after the movie, so you’ll miss out on the happy hour specials. Otherwise, if you are going to the late show, you need to apply happy hour discounts to your bills. Discounts should be displayed on the final bill, along with the original prices.

1. Create a new Eclipse project.
2. Add a folder named lib to your project.
3. Import the file CST8132_Restaurant.JAR to the lib folder of your project.
4. Add the JAR file to your Build Path.
5. Create a new Package named dateNight.
Package: dateNight
Class: Entree extends MenuItem
1. Imported Classes
2. Methods
a. public Entree(String name, double price)
i. Call the super constructor, passing the name and price parameters.
Class: Dessert extends MenuItem
1. Imported Classes
2. Methods
a. public Dessert(String name, double price)
i. Call the super constructor, passing the name and price parameters.
Class: Bill
1. Imported Classes
a. java.util.ArrayList
b. java.util.HashMap
2. Instance Variables
a. booleanisHappyHour
b. HashMap> orders
c. double subtotal
d. double hstRate
e. final intmaxMenuItemLength
3. Methods to Implement
a. public booleangetHappyHour()
i. Return the value of isHappyHour.
b. public void setHappyHour(Boolean isHappyHour)
i. Set the value of isHappyHour.
c. public HashMap>getOrders()
i. Return the value of the orders variable.
d. public double getSubtotal()
i. Return the value of subtotal.
e. public double getHst()
i. Return the calculated HST value.
ii. HST = (subtotal – happyHourDiscount) * hstRate
f. public double getHstRate()
i. Return the value of the hstRate.
g. public double getTotal()
i. Return the calculated total.
ii. Total = subtotal – happyHourDiscount + hst
h. public double getHappyHourDiscount()
i. Return the calculated happy hour discount, or 0 if no discount should be applied.
ii. Using the instanceof type comparison operator, apply the appropriate discounts for each Appetizer or Drink ordered. Discounts are described in requirements above.
iii. Hint – you can use nested enhanced for loops to iterate over the HashMap and ArrayList.
4. Implemented Methods
a. The following methods have already been implemented – they do not need to be modified, however you must add Javadocand comments to them to indicate your understanding of the methods.
i. public String toString()
ii. public booleanaddOrderItem(String guest, MenuItem item)
Class: DoubleDate
1. Imported Classes
a. java.util.ArrayList
b. java.util.Arrays
c. java.util.Random (optional)
2. Instance Variables
a. ArrayList guests
b. String[] movies
c. String movieTitle
d. intmovieTime
e. Restaurant restaurant
f. Menu menu
g. Bill bill
3. Class Variables
a. Random random
4. Methods
a. public DoubleDate(String yourName, String… guests)
i. Initialize the guests instance variable by creating a new ArrayList. Give your ArrayList a default capacity of 4.
ii. Using the ArrayListadd method, add your name to the ArrayList. This will insert your name in position 0 of the ArrayList.
iii. If there are any additional guests to add, use theArrayListaddAll andArrays.asList(array) methods to add the optional guests to theArrayList.
iv. Initialize the restaurant by calling the static Restaurant.getInstance(String name) method.
v. Initialize the menu by calling the restaurant.getMenu() method, and then invoking the addMenuItems() method.
vi. Initialize the bill by calling the default constructor of the Bill class.
vii. Initialize the movies array by adding at least 3 movie titles to the array.
b. public String pickAMovie(String[] movies)
i. Using either the Math.random or Random.nextInt method, select a movie to attend, and return this value.
c. public intgetShowing()
i. 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.
d. public void addMenuItems()
i. There is a method in the Menu class with the following signature:
public booleanaddMenuItem(String itemType, String name, double price)
ii. 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. Dessertand Appetizer prices must be evenly divisible by 2.
1. Drinks
2. Desserts
3. Appetizers
4. Entrees
iii. Menu item names should be a maximum of 30 characters in length for optimal formatting of outpout.
e. public booleanplaceOrder(String guest, String itemType)
i. Get a random MenuItem to order by calling the getRandomMenuItem(String itemType) method of the Menu class.
ii. Add this MenuItem to this person’s order by calling the addOrderItem(String guest, MenuItemmenuItem) method of the Bill class.
iii. The addOrderItem method returns a boolean value, which should be returned by this placeOrder method.
f. public static void main(String[] args)
i. 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.
ii. 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.
iii. Call the getShowing method and assign the return value to the movieTime variable.
iv. Based on the movieTime, set the isHappyHour variable of your Bill by calling the setHappyHour(booleanisHappyHour) method.
v. 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.
vi. Print the DoubleDate object by implicitly calling its toString() method, like this:
g. public String toString()
i. Output the list of movie options, the selected movie, and show time.
ii. Output the name of the restaurant, and based on the show time, whether you will be meeting there before or after the movie.
iii. 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!
iv. Output the menu, by calling its toString() method.
v. Output the bill, by calling its toString() method.
Class: Restaurant
Class: Menu
Class: MenuItem
Class: Drink extends MenuItem
Class: Appetizer extends MenuItem

Marking Scheme
Submission Requirements