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.
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.
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.
Class KinPerson will have the following fields, all of which should be private. You can choose the names of these fields.
String)String)int)int)int)boolean)KinPerson object)KinPerson object)int)int)
Here are a few specifications about the fields of class KinPerson:
String values: "male" and "female". true if the person
has a criminal record and false otherwise. KinPerson
objects that correspond to this person's parents. They are null
if not known.KinPerson OBJECT IS CREATED, THIS FIELD SHOULD BE INCREASED BY 1. 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 |
|---|---|
|
|
Constructor: a new |
|
|
Constructor: a new |
| Method | Description |
|---|---|
|
|
= the full name of this person (a String) in th form "last-name, first-name" |
|
|
= the last name of this person |
|
|
= the gender of this person (a String). |
|
|
= the day of the month this person was born (an int).
|
|
|
= the month in which this person was born, in the range 1..12 (an
int). |
|
|
= the year in which this person was born (an
int). |
|
|
= (the name of the object representing) the father of this person
(a KinPerson). |
|
|
= (the name of the object representing) the mother of this person
(a KinPerson). |
|
|
= the number of children of this person (an int). |
|
|
Static method. = the number
of KinPerson objects created thus far (an int).
|
|
|
= "this person is a criminal" (a boolean) |
|
|
Set the name of this person to n. |
|
|
Set the gender of the person to g. Precondition: g is one of "male" and "female". |
|
|
Set the day of the month this person was born to i.
|
|
|
Set the month of birth for this person to i. |
|
|
Set the year of birth for this person to i. |
|
|
Set whether this person is guilty of a crime to b
(true or false). |
|
|
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. |
|
|
Set this person's mother to fm. Precondition: This person's
mother is null, fm is not null,
and fm is female. |
|
|
= "this person is older than fm" (a |
|
|
Static function. = " |
|
|
Static function. = |
|
|
= " |
|
|
= " |
|
|
Static method. = " |
|
|
= "this person is |
|
|
= "this person is |
|
|
= "this person is |
|
|
Static method. = " |
|
|
= "this person is an evil twin of |
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.
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:
KinPerson, your test suite
should have at least one test case that tests that method.
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.
KinPerson, compiling
often as you proceed.KinPerson.KinPersonTester that tests whether the first constructor and all the getter methods work.KinPersonTester
to test them, and test them. KinPersonTester
to test them, and test them.At each step, make sure all methods are correct before proceeding to the next step. When adding a new method, cut and paste the comment and the header from the assignment handout.
.java.
Be careful about this, because in the same place as your .java
files you may also have files that end with .class or .java~.
but otherwise have the same name. In particular:
KinPerson.java~". The ~ indicates
that the file is a backup file, which happens to be an older version
of your program.
Since
.classfiles 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!
if statements
when completing this assignment. For boolean expressions the &&
(AND), || (OR), and ! (NOT) operators are sufficient to implement all
the methods shown above. You will lose points for using if
statements.
KinPerson methods can be
implemented easily by using other KinPerson methods that
you have already created. Look for these cases, and take advantage of them
as much as possible.
substring, toUpperCase, and toLowerCase
in class String may be useful.
String literal is enclosed
in double quotation marks and a char literal is enclosed in
single quotation marks.
.equals to compare objects
(including String objects) for equality and == to compare primitive values for equality.
null.
So comparisons between primitive types and null are not legal.
File
->�New JUnit Test Case, and then replace the testX method
with many methods that test your KinPerson functionality.