Question
. Create a class named DonorsList that has the following private fields: [ 1 Pt ] donatedOrgans ( ArryList of type DonatedOrgan class) avgAge (
. Create a class named DonorsList that has the following private fields: [1 Pt]
- donatedOrgans (ArryList of type DonatedOrgan class)
- avgAge (double)
2. Provide a no-argument constructor to initialize the DonorsList object with an empty donatedOrgans ArrayList and avgAge set to 0.0. [1 Pt]
3. Provide setter and getter methods [1 Pt]
4. Override the toString() to return the String representation of the current object using the following format: [1.5 Pt]
Important Note 6: The String representation looks like:
Number of donated organs = 3
[DonatedOrgan(123, Upper Body, 13.445, 234, 25, Ahmed),
DonatedOrgan(234, Liver, 234.120, 234, 23, Fahd),
DonatedOrgan(983, Lung, 23.400 234, 44, Khaled)]
Average donor age = 30.666 years old
5. Add a method named addOrgan() that takes an input argument of type DonatedOrgan and adds it to the donatedOrgans list. The method must update the average age of the donors [2 Pt]
Part VI:
Add a main() method to the main class CS102FinalExam to do the following tasks:
1. Read the organs data from data file named organs.txt. Each line in this file contains information about the organs (simple organs or donated organs). [1.25 Pt]
A line with an Organ information has the following structure:
Organ: 123, Upper Body, 13.445
A line with a DonatedOrgan information has the following structure:
DonatedOrgan: 983, Lung, 23.4, 44, Khaled
Save all read data in HashSet of type Organ.
2. Print the number of the Organ objects. [1 Pt]
3. Print the number of the Donatedrgan objects. [1 Pt]
4. What is the age of the oldest donor? [1 Pt]
5. What is the age of the youngest donor? [1 Pt]
6. What is the average age of the donors? [1 Pt]
7. Print the name of the oldest donor [0.5 Pt]
8. Print the name of the youngest donor
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started