|
Required reading: Savitch text Chapters 4 and 5.
This exercise should be done using only the material from Chapters
1 through 5.
Due dates: Check the Announcements.
Note you can do this and take an interview without turning in the
assignment, as long as it is before the turnin deadline (and until
the deadline is announced it is definitely before the deadline.)
Programming: You may work in teams of two students, but once
you form a team, you cannot change the team for this assignment.
You may work alone if you prefer.
Write a Person class that stores the following information about
a person as instance variables:
- name: of type String for the name
- sex: of type char for the sex "M" or "F"
- birthDate: of type Date (see below) for the date of birth
And the following variables that record preference for different
types of activities:
- quiteTime
- music
- reading
Each of these is of type int and must contain values in the range
0 to 10 (inclusive). 0 means the person hates the activity. 10 means
the person loves the activity.
The class Person has an inner class named Date with the following
instance variables:
- year: of type int in the range 1900-3000
- month: in the range 1 to 12 (January is 1)
- day: in the range 1 to 31 AND appropriate to the month.
(You can assume, contrary to actual fact, that February always has
28 days.)
The classes Person and Date have:
- suitable constructors
- accessor and mutator methods
- a method named input for input from the keyboard
- a method named output for output to the screen.
Use these classes to write a program (a class called Match) that
accepts data on two people and output a score in the range 0-10
(inclusive) of how well matched the people are to be dorm roommates.
The user is allowed to repeat this computation for more people.
The program ends when the user says he/she is finished.
How the match is selected:
Different sexes match is 0
otherwise match score is:
ageDifference = absolute value of difference in years born to a
maximum of 10.
interestScore = the sums of the absolute differences in their scores
for:
- quiteTime
- music
- reading
rawMatchScore = (30 - interestScore)/30 + (10 - ageDifference)/10
matchScore = rawMatchScore*5
Be sure to use numbers of type double, not int; otherise, round
off error will ruine the calculation.
You will design and debug your program to have two classes in two
files: Person.java, Match.java.
For turnin purposes you will make Person.java an inner class of
Match.java, but when we grade it, we will move the class Person
to a file by itself.
Note: It is possible to write the program Match without using
the class Person, but if you do it that way, you will get a zero.
You musts use the class Person in intrinsic ways. In particular,
you MUST uses the classes Person to store data and to do input and
output. Your program Match must work with variables of type Person.
You cannot use a bunch of smaller variables that shadow the instance
variables of Person.
Last Update: Jan 15, 2003 (by Nakul
Verma)
|