Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Lab3 - Sp2000
The citizens of Yakashaw, Alabama are aputtin' on another hoedown tonight. Spirits will be high, the spirits will be flowing, the music will be thumping, and the square
dancing will be wild beyond your belief. To get things rolling, everyone says hello....
Now, the people of Yakashaw are polite folk with real good upbringing. When a Yakashaw gentleman greets someone or is greeted, he not only says hello but he also bows.
And when a Yakashaw lady greets someone or is greeted, she not only says hello but she also curtsies. Assuming, of course, that the person being greeted isn't at feud with
the person doing the greeting. In that case, the greetee replies with a rude sniff and turns their back–about as rude as it gets in Yakashaw! (truly angry Yakashawians
sometimes resort to yo-mama jokes, but this is rare). Thankfully, all Yakashawians are very polite, and they save the bloodletting until after the hoedown.
The goal of the lab is to model what happens when one person at the hoedown greets another. Now, you've already seen in a previous lab what happens when one Muppet
greets another–they just say their bit and go on. However, Yakashaws are more complex; polite folk that they are, they actually respond to a greeting. If the person who
greeted them deserves it, of course.
The class candidates that come first to come to mind are Person, Gentleman, and Lady. Looking through the description for other nouns, the candidates Yakashaw (the
town), Hoedown, and Family seem like reasonable classes. Now let's refine this.
First, should Gentleman and Lady be subclasses of Person, or should there just be an attribute in Person to make the distinction? Well, for our purposes, the only difference
is that they have different greeting behavior (bowing versus curtsying). Furthermore, a given instance will never change from being a Gentleman to a Lady nor vice versa.
From these considerations, making them separate classes seems like a good way to go; we'll stick with that unless another consideration comes to mind.
Okay, well how should feud's be represented? We are going to need a way to ask questions like "Is Joe's family feuding with Sarah's family". So we need to represent which
families are feuding with which... and that's about all our system needs to know about feuds. To simplify, we will even assume that each family is feuding with at most one
other family (Anything more and we would have to start thinking about collections again)
So how should this be done? Maybe each Person should have a feudingWith attribute which says what family they are feuding with. Then, each Person also can have a
family attribute which says what family they are in. To check whether two people are feuding, check one of their feudingWith attributes and see if it matches the other's
That would work, but that seems a little repetetive. Since every member of a given family should be feuding with the same other family, the feuding information isn't really
specific to a Person, but to a Family. So let's put the feudingWith attribute in Family instances instead of Person instances; a person can still decide who they are at feud
with by querying the family they are a member of. We have already decided to give a family attribute to Persons, so we're set.
The above covers pretty much all the basic functionality. We are left with the following classes:
- I am an abstract Person. I know how to greet other people, and I know how to respond when other people greet me. In order to do this, I know my Family.
- I am a Gentleman. I am a Person, but when I greet other Gentlemen I extend my hand, and when I greet Ladies I bow.
- I am a Lady. I am a Person. When I greet anyone else or am greeted I curtsie.
- I am a Family. Different People know me as their family. There is possibly another family I am feuding with.
We have found no use for the following classes:
Now we go back and fill in much more detail for the classes and methods in our system.
- Family. I am a family of people. Each person belongs to one of me.
- name - name of this family
- feudingWith - reference to the Family being feuded with, if any. –Services:
- name - return the name of this family
- feudingWith - return the family we are feuding with, or nil if we are peaceful sorts.
You may notice there is no way for a family to know what its members are. Given a Person, you can figure out what Family they are in, but not vice versa. This functionality is not required, obvious though it may be, so it can be safely left unimplebented. (and it simplifies the code!)
- Person. I am a Person. I am abstract–there will only be instances of my subclasses, Gentleman and Lady. I know the basics of being Human in Yakashaw so far as is relevant to this lab; aspects which depend on gender are implemented in the appropriate subclass.
- name - my name
- family - the Family I am a member of
- greet: - greet another person. Gentleman and Lady override this method to do different things.
- greetedBy: - inform me that I have been greeted by someone; react accordingly. Gentleman and Lady override this method to do different things.
- isFeudingWith: - decide whether I am feuding with a given Person.
- family - return my Family. This is needed so that other people can decide whether they are feuding with me.
- say: - say something. For this project, just print to the Transcript, but this method can be modified if we ever want to do something more complex.
- Lady. I am a Lady. I am a peculiar sort of Person. I am the same as all other Persons except for the way I greet people and respond to greetingns.
- greet: - greet another person. I say hello to them, curtsey, and inform them via greetedBy: that they have been greeted.
- greetedBy: - I have been greeted by another person. If I am not at feud with them, I say hello in return and curtsey. If I am at feud with them, then I sniff and turn my away (and what I'd really like to do....) curtsey - do a curtsey. For this lab, just prints a message to Transcript.
- Gentleman. I am a Gentleman. I am a peculiar sort of Person. I am the same as all other Persons except for the way I greet people and respond to greetingns.
- bow - bow, like polite Yakashawian gentlemen do. In this lab, just prints to Transcript.
- greet: - greet another person. I say hello to them, bow, and inform them via greetedBy: that they have been greeted.
- greetedBy: - I have been greeted by another person. If I am not at feud with them, I say hello in return and bow. If I am at feud with them, then I sniff and turn my away (and what I'd really like to do....) bow - do a bow. For this lab, just prints a message to Transcript.
This is your part! Most of the details of the system have been laid out above. You need to create a new category, add the four classes (being careful about subclasses and
superclasses), and implement all the specified methods. Also, you will need to implement initialization methods not mentioned above: name:, family:, and feudingWith:.
When you're done, try the following code:
macyntire := Family new. macyntire name: 'Macyntire'.
macynzie := Family new. macynzie name: 'Macynzie'.
jones := Family new. jones name: 'Jones'.
smith := Family new. smith name: 'Smith'.
elphen := Family new name: 'Elphen'.
"set up feuds"
macyntire feudingWith: macynzie.
macynzie feudingWith: macyntire.
smith feudingWith: jones.
jones feudingWith: smith.
billyBob := Gentleman new. billyBob name: 'Billy Bob'. billyBob family:
billyJo := Lady new. billyJo name: 'Billy Jo'. billyJo family: macynzie.
bubba := Gentleman new. bubba name: 'Bubba'. bubba family: jones.
jane := Lady new. jane name: 'Jane'. jane family: smith.
lauralanthala := Lady new. lauralanthala name: 'Lauralanthala'.
lauralanthala family: elphen.
"do some greetings"
billyBob greet: billyJo. Transcript cr.
billyJo greet: billyBob. Transcript cr.
bubba greet: jane. Transcript cr.
jane greet: bubba. Transcript cr.
billyBob greet: bubba. Transcript cr.
jane greet: billyJo. Transcript cr.
bubba greet: lauralanthala. Transcript cr.
lauralanthala greet: bubba. Transcript cr.
It should give the following output:
Billy Bob says, "Salutations, Billy Jo"
Billy Bob bows.
Billy Jo sniffs and turns away.
Billy Jo says, "Salutations, Billy Bob"
Billy Jo curtsies.
Billy Bob sniffs and turns away.
Bubba says, "Salutations, Jane"
Jane sniffs and turns away.
Jane says, "Salutations, Bubba"
Bubba sniffs and turns away.
Billy Bob says, "Salutations, Bubba"
Billy Bob bows.
Bubba says, "Greetings, Billy Bob. A most exquisite evening for a
hoedown, is it not?"
Jane says, "Salutations, Billy Jo"
Billy Jo says, "Hi, Jane!"
Billy Jo curtsies.
Bubba says, "Salutations, Lauralanthala"
Lauralanthala says, "Hi, Bubba!"
Lauralanthala says, "Salutations, Bubba"
Bubba says, "Greetings, Lauralanthala. A most exquisite evening for a
hoedown, is it not?"
Follow the posted turn in instructions.
Link to this Page