Overview:

Patrons of a cinema may buy snack items or combos from concession vending machines. A combo may consist of two or more snack items offered together at a discounted price. A combo may also be made up of other combos.

Patrons pay for items or combos by making a cash payment based on the amount of money they have on hand or by making a card payment for the exact amount with a valid credit card (based on expiry date). After a payment is validated, the patron is given a receipt for their purchase. The receipt lists the number of bills and coins returned for cash payments. For card payments, the receipt indicates whether the payment was approved or not.

A Snack interface is defined as follows:

public interface Snack{
public int getID( ); // returns the ID of a Snack
public String getName( ); // returns the name of a Snack
public double getPrice( ); // returns the price of a Snack
public int getNumItems( ); // returns the number of items making up a Snack
public String getDetails( ); // returns the string representation of a Snack
}

An Item is a concrete class that implements the Snack interface. It represents a single snack that may be purchased from the vending machine. Item IDs start from 100 and are incremented by 100 thereafter.

A Combo is a concrete class that implements the Snack interface. It represents a combination of snacks that may be packaged together and offered for sale as a single snack. Use an appropriate collection to maintain a list of the combined snacks. A method must be provided to add snacks to a Combo. The price of a Combo is calculated as 80% of the net price of its items plus the cost of any sub-combos. Combo IDs start at 100000 and are incremented by 100000 thereafter. This class may or may not implement the Comparable interface as per the collection you use.

An Order class encapsulates the important details of a patrons order. It also lists the snack IDs that make up the order. This class is used to generate a receipt.

A Payment interface specifies a method validatePayment(Order order): boolean which works for both Cash Payments and Card Payments. Card payments are valid if the date on the card has not expired. Cash payments are valid if the cash supplied is more than or equal to the payment due for an order. For cash payments exceeding the total amount, the vending machine returns changes in the form of $20, $10, $5 or $1 bills or 25, 10, 5, 1 cent coins as necessary. For example, if a Patron has $100.00 cash on hand, and the cost of his snacks is $45.00 then the change due would be $55.00. The vending machine therefore dispenses two $20 bills, one $10 bill, and one $5 bill. The number of bills to be returned is calculated starting from the highest to the lowest denomination.

A VendingMachine class processes orders and prints the receipts for each order. It stores lists of items and combos.

Sample lists: (to be loaded using the text files supplied).

Snack Items see image.

Snack Combos see image.

Orders see image.

Assignment Tasks:

(a) Design
Draw a class diagram that models a solution for the scenario above using the Composite design pattern and the Strategy design pattern.

(b) Code
Write Java code to create a working solution based on your design in part (a). Document your program appropriately and ensure that any data files you use conform to the sample lists on page 2. Name your main class Cafeteria.java.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.