CSci 450-01: Organization of Programming Languages
CSci 503-01: Fundamental Concepts in Languages
Fall 2014


Carrie's Candy Bowl ADT Problem Description

Note: This is based on the instructor's solution for Problem 4 on Exam 1in 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()
to create a new empty candy bowl
put(bowl,candyType)
to add one piece of candy of type candyType to the bowl
take(bowl,candyType)
to remove one piece of candy of type candyType from the bowl
has(bowl,candyType)
to determine whether or not the bowl contains any candy of type candyType
howMany(bowl)
to determine how many pieces of candy are in the bowl overall
howMany(bowl,candyType)
to determine how many pieces of candy of type candyType are in the bowl
isEmpty(bowl)
to determine whether or not the bowl is empty
inventory(bowl)
to return a list-style table of pairs {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)
returns the bowl resulting from pouring bowl1 and bowl2 together to form a "larger" bowl


Copyright © 2014, H. Conrad Cunningham
Last modified: Wed Sep 11 12:42:33 CDT 2013