©2005 Felleisen, Proulx, et. al.
A software house that is working with a grocery chain receives this problem statement:
Develop a program that keeps track of the items in the grocery store. For now, assume that the store deals only with ice cream, coffee, and juice. Each of the items is specified by its brand name, weight (grams) and price (cents). Each coffee is also labeled as either regular or decaffeinated. Juice items come in different flavors, and can be packaged as frozen, fresh, bottled, or canned. Each package of ice cream specifies its flavor.Design and implement the following methods:
unitPrice
, which computes the unit price (cents per gram) of
some grocery item;
lowerPrice
, which determines whether the unit price of some
grocery item is lower than some given amount;
cheaperPerUnit
, which determines whether one grocery item is
cheaper than some other, given in terms of the unit
cost.
Recall Homework 2, problem 2 that dealt with reading lists. Design and implement the following methods for these classes:
hasOldBooks
which determines whether there are any old
books in the list of books (books published before 1950).
allNewBooks
which check if all books in the list are
new books.
aCount
which computes how many books in the list were written by a given author.
Recall Homework 2, problem 3 that dealt with a maze game. We revise the game
a little bit, so that the girl starts the game with no fortune in a room
with elf. We also add the requirement that each wizard has a unique
name. The wizards are parameterized by
two magic numbers a
and b
and compute the girl's
final fortune as a function of her incoming fortune x
, using the
formula ax + b
. As before, the
game ends when a monster leaves the girl
with no fortune, or when the girl lands in a room containing a wizard.
Each move in the game consists of the following steps:
The elf, the monster, or the wizard adjusts girl's fortune.
A check is made whether the game is over.
If the game is not over, the girl moves to the next room of her choice (either left or right).
First, modify your existing class hierarchy to match the updated design specification.
Second, design and implement the following methods for the class hierarchy:
reward
which determines the girl's
new fortune, based on her current fortune and the fact that she is
currently in 'this' room.
gameOver
which checks if the game is over - again, it
needs to know the girl's current fortune and the room.
countRooms
which counts how many rooms are in the maze.
countElfRooms
, countMonsterRooms
and
countWizardRooms
which count how many rooms of each kind
are there in the maze.