Note: This is based on the instructor's solution for Problem 4 on Exam 1 in CSci 658 (Software Language Engineering) in Fall 2013 Exam 1. (This was a take-home exam.)
Carrie's Candy Bowl. As you may have noticed, Carrie, the Department's Administrative Assistant, has a candy bowl on her desk. Often this bowl gets filled with candy, which is quickly consumed by students and professors. Your task in this exercise is to represent that candy bowl by a Lua module.
Design and implement Carrie's Candy Bowl as either a module or a class. Your module/class likely will need functions/methods similar to the following:
CandyBowl()
put(bowl,candyType)
candyType
to the bowl take(bowl,candyType)
candyType
from the bowl
has(bowl,candyType)
candyType
howMany(bowl)
howMany(bowl,candyType)
candyType
are in the bowl isEmpty(bowl)
inventory(bowl)
{candyType, count}
. The list should be in
ascending order by candyType
.
For example, if candyType
is denoted by a string and
there are two Snickers and one Hershey Kiss in the bowl, then the list
returned would be something like { {'Hershey Kiss', 1},
{'Snickers', 2} }
. combine(bowl1,bowl2)
bowl1
and bowl2
together to form a "larger" bowl