Reference no: EM132210339
Write a program in Java following the given description:
There are many different types of Creatures, and talking about the intelligence level of a Creature makes perfect sense.
HumanBeing is a Creature, each possessing, in addition to the intelligence level, a name and age. Male is a HumanBeing, and so is Female.
Animal is another Creature which possesses some Intelligence Level, and so is Bird.
In this assignment, you are required to implement a Creature as an abstract class containing an abstract method getIntLevel; a HumanBeing class described as above; a Male class and a Female class.
For each male, we wish to keep track of his height and weight, whereas for every female, we wish to keep track of her last degree.
Male and Female classes have all required accessor methods to return the values of their attributes. Both, Male and Female classes allow users to calculate intelligence level defined (absurdly) as follows:
Male: (Calculation proceeds in the order given here)
If age > 40, then IntLevel = 5
If age is < 5 years, then IntLevel = 1
If weight >= 150 pounds and height is > 70 inches then IntLevel = 5
If weight is between 120 and 149 pounds, and height > 70 inches, then IntLevel = 4
If weight is between 50 and 119 pounds, then IntLevel = 3
If weight is between 120 and 149 pounds, and height is between 55 and 69 inches,
then IntLevel = 2
In all other cases, the IntLevel = 3.
Female:
If lastDegree = "Ph.D.", then IntLevel = 5
If lastDegree = "MS", then IntLevel = 4
If last Degree = "BS", then IntLevel = 3
If last Degree = "AA", then IntLevel = 2
In all other cases, IntLevel = 1.
When a Male or Female object is created, the constructor checks if this is indeed a "valid" person. A "valid" male is someone whose weight is less than 400 pounds and height is less than 100 inches.
A "valid" female is someone whose age is less than 110 years. If the user tries to create an "invalid" person, the class constructors throw an exception called notHumanBeingException to the calling program. The calling program rejects that person from consideration.
In case the person was "valid", the constructor calculates the person's Intlevel and initializes it. Obviously, HumanBeing must provide a method that allows setting of one's IntLevel.
The test program will do the following:
From an input file (as always, get the name of the file from the user), read the basic information about Human Beings. Don't hardcode the file name, askt he user for the filename. Input file is given below. The first character identifies what type of Human Being this person is - M or F.
Information in the input file is in the following order:
Male: name, age, height (in inches), weight (in pounds).
Female: name, age, last degree.
Create an ArrayList of all persons, an array of males, and an array of females from this given data. That is, each person will be included in an ArrayList and one array.
Output unsorted ArrayList of persons.
Sort the ArrayList based on names, using "sort" method of the Collections interface.
Output the sorted ArrayList of persons.
Output unsorted list of Males.
Sort the array of males based on their heights using Arrays.sort (array_of_males, comparator) call.
Output the sorted array of males.
Output the unsorted list of females.
Sort this array based on age using Arrays.sort (array_of_females) call. Note that no comparator is passed in this call. Do whatever you need to do to achieve this.
Output the sorted list of females.
The output should be sent to an output file, and should be completely self-explanatory.
INPUT FILE:
M DanMarino 45 75 220
M SteveSmith 35 57 110
F MiaHamm 25 MS
F OhYeah 120 AA
M JackSmith 34 60 128
F Alexandra 55 Ph.D.
F Maria 24 BS
M DanMarinoJr 4 24 24
M MarkWho 38 72 144
M DumbOne 27 66 410
M Great! 77 110 333
F Alicia 46 BS
F Haydee 44 AA
F Irene 22 BS
F Martha 55 Ph.D.
M DavidWhite 39 71 155
M BillBlack 33 76 144
M WeiChen 28 55 112
M NormanSmith 33 55 166
F AnaSmith 52 Ph.D.
M PaulGirard 38 58 211
M PeterPan 3 18 22
M HumptyDumpty 77 36 500
F PaulaGrant 44 MS
F BonnieBert 27 AA
F BerthaTravis 11 Ph.D.
F YolyGarcia 23 BS
M JoseSanchez 2 18 22
M JulioSmith 38 55 165