CS100J    Fall 2005    Assignment A2    
Due (submitted on the CMS) on Wednesday, 21 September

Introduction

Read the WHOLE handout before you begin to write the assignment. You may do this assignment with one other person. If you are going to work together, then, as soon as possible, get on the CMS for the course and do what is required to form a group. We will give some hints on doing this in class.

CBS is planning on launching a gritty new drama series, called The Greeces, kind of like As the World Turns. The producers of this show have a problem, however: the Greece clan is so large that they have trouble keeping track of who is related to whom, what the relation is between any two characters, and which couples can't get married because they're cousins.

That's where you come in, as the CBS's resident computer expert. They've asked you to devise a system that will keep track of all the kinfolk in this show and allow them to add relatives and keep track of relatives as the show progresses. Make sure that the Java class you implement to store information on the Greece clan is a good one --or they may not renew your job for next season.

Requirements

For this assignment, you are required to design two classes. Class KinPerson is the class that is used by CBS to keep track of people. It has lots of fields and methods, but each method is simple. If you do one thing at a time, not worrying about the overall picture, you should have little trouble.

Class KinPersonTester is used to test class KinPerson. We will describe how to do this on 15 September. Do not think too much about it when first reading this handout.

Class KinPerson

An instance of class KinPerson represents a single person in this big family (in this case, one of the Greece relatives). It has several fields that one might use to describe a relative, as well as methods that operate on these fields.

KinPerson Variables

Class KinPerson will have the following fields, all of which should be private. You can choose the names of these fields.

Here are a few specifications about the fields of class KinPerson:

KinPerson Methods

Class KinPerson supports the following methods. Pay close attention to the parameters and return values of each method. The descriptions, while informal, are complete.

Constructor Description

KinPerson(String name, String gender,
int day, int month, int year)

Constructor: a new KinPerson. Parameters are, in order, the name of the person, their gender, the day, month, and year of birth. The new person is not a criminal and its parents are not known. Precondition: gender is one of "male" and "female".

KinPerson(String name, String gender,
KinPerson father, KinPerson mother,
int day, int month, int year)

Constructor: a new KinPerson. Parameters are, in order, the name of the person, their gender, their father and mother (not null), and the day, month, and year of birth. The new person is not a criminal. Precondition: gender is one of "male" and "female".

Method Description

getName()

= the full name of this person (a String) in th form "last-name, first-name"

getLastName()

= the last name of this person

getGender()

= the gender of this person (a String).

getDOB()

= the day of the month this person was born (an int).

getMOB()

= the month in which this person was born, in the range 1..12 (an int).

getYOB()

= the year in which this person was born (an int).

getFather()

= (the name of the object representing) the father of this person (a KinPerson).

getMother()

= (the name of the object representing) the mother of this person (a KinPerson).

getNumberChildren()

= the number of children of this person (an int).

getFamilySize()

Static method. = the number of KinPerson objects created thus far (an int).

isCriminal()

= "this person is a criminal" (a boolean)
   

setName(String n)

Set the name of this person to n.

setGender(String g)

Set the gender of the person to g. Precondition: g is one of "male" and "female".

setDOB(int i)

Set the day of the month this person was born to i.

setMOB(int i)

Set the month of birth for this person to i.

setYOB(int i)

Set the year of birth for this person to i.

setGuilt(boolean b)

Set whether this person is guilty of a crime to b (true or false).

setFather(KinPerson fm)

Set this person's father to fm (and increment fm's number of children).
Precondition: This person's father is null, fm is not null, and fm is male.

setMother(KinPerson fm)

Set this person's mother to fm. Precondition: This person's mother is null, fm is not null, and fm is female.
   

isOlder(KinPerson fm)

= "this person is older than fm" (a boolean). Precondition: fm is not null.

areSameAge(KinPerson fm1,
KinPerson fm2)

Static function. = "fm1 and fm2 are not null and are the same age --i.e. have the same birth date " (a boolean).

haveSameLastName(KinPerson fm1,
KinPerson fm2)

Static function. = "fm1 and fm2 are not null and have the same last name" (a boolean). Capitalization is not important --e.g. "Greece" and "greece" are the same last name.

isBrother(KinPerson fm)

= "fm is this person's brother" (a boolean). Note: a guy is called your brother if you and he (has to be a "he") are different and have at least one parent in common. Precondition: fm is not null.

isSister(KinPerson fm)

= "fm is this person's sister" (a boolean). Note: a gal is called your sister if you and she (has to be a "she") are different and have at least one parent in common. Precondition: fm is not null.

areSiblings(KinPerson fm1, KinPerson fm2)

Static method. = "fm1 and fm2 are not null and fm1 and fm2 are siblings (brothers or sisters)" (a boolean).

isMotherOf(KinPerson fm)

= "this person is fm's mother" (a boolean). Precondition: fm is not null.

isFatherOf(KinPerson fm)

= "this person is fm's father" (a boolean). Precondition: fm is not null.

isParentOf(KinPerson fm)

= "this person is fm's parent" (a boolean). Precondition: fm is not null.

areTwins(KinPerson fm1,
KinPerson fm2)

Static method. = "fm1 and fm2 are not null and fm1 and fm2 are siblings and have the same birth date" (a boolean).

isEvilTwin(KinPerson fm)

= "this person is an evil twin of fm --'evil' means having a criminal record. Precondition: fm1 is not null.

Make sure that the names of your methods match those listed above exactly, including capitalization. The number of parameters and their order must also match. The best way to ensure this is to copy and paste. Our testing will be expecting those method name names and parameters, so any mismatch will fail during our testing. Parameter names will not be tested --you can change the parameter names if you want.

Each method must be preceded by an appropriate specification, as a Javadoc comment. The best way to ensure this is to copy and paste. Note that a precondition should not be tested by the method; it is the responsibility of the caller to ensure that the precondition is met. As an example, in method isMotherOf, the method body should not test whether fm is null. However, in function areSiblings, the tests for fm1 and fm2 not null MUST be made.

The number of children of a newly created person is 0. Whenever person P is made the mother or father of another person, P's number of children should increase by 1.

It is possible for person P1 to be P2's mother, and visa versa, at the same time. We do not check for such strange occurrences.

Your method bodies should have no if statements. Your method bodies should contain only assignments and return statements. Points will be deducted if if statements are used.

Class KinPersonTester

How do you know whether class KinPerson that you are designing is correct? The only way you can be sure is to test it, to see if it does what it is supposed to do. It is not enough simply to try out your class KinPerson in the interactions pane. Every time you write a method for your class KinPerson, you should also write a couple of tests for it. And run your collection of tests frequently to make sure that everything works correctly.

Class KinPersonTester will contain your JUnit test suite; it will perform these testing tasks for you. Make sure that your test suite adheres to the following principles:

Remember that if you change static variables in an early test, they will retain their values in later tests. Also, the tests are not necessarily run in the order in which you list them in your test suite. So when testing static variables, record their initial value at the beginning of the test, and test that the change in the value is what you expect.

Hints and Tips

Since .class files cannot be read by TAs or run with our testing programs, submitting the wrong files creates havoc with grading your assignment. Every year, a half-dozen students submit the wrong file. Don't do it!