Coffee Shop

Published by Helen Yu in

Write a class called Coffeeshop, which has three instance variables:

  1. name : a string
  2. menu : an array of items, with each item being a hash containing the keys :item (name of the item), :type (whether it is a food or a drink), and :price.
  3. orders : an empty array

and four methods:

  1. add_order: add the name of the item to the end of the orders array if it exists on the menu. If not, return "This item is unavailable, sorry!"
  2. fulfill_order: if the orders array is not empty, return "The #{item} is ready!". If the orders array is empty, return "No orders to fulfill!"
  3. cheapest_item: return the name of the cheapest item on the menu.
  4. drinks_only: return the names of only the drink items on the menu.

Note: Orders are fulfilled in a FIFO (first-in, first-out) order.

Examples

cs1.add_order("hot cocoa") ➞ "Sorry, this item is unavailable."
# A Little Spice coffee shop does not sell hot cocoa

cs1.add_order("cinnamon roll") ➞  "Order added!"
cs1.add_order("iced coffee") ➞ "Order added!"
cs1.orders ➞ ["cinnamon roll", "iced coffee"]
# All current orders are listed.

cs1.fulfill_order ➞ "The cinnamon roll is ready!"
cs1.fulfill_order ➞"The iced coffee is ready!"
cs1.orders ➞ []
# All orders have been fulfilled

cs1.cheapest_item ➞ "lemon tea"
cs1.drinks_only ➞ ["hot chocolate", "lemon tea", "iced coffee", "vanilla chai latte"]

Notes

N/A

Watch a quick demo on how Edabit works.