Question
Programme should be write in java: The Person Class: Create a class called Person to hold two facts about a member of your family: rst
Programme should be write in java:
The Person Class:
Create a class called Person to hold two facts about a member of your family: rst name, and age. In this class, provide two private data members and a constructor with two parameters.
Also provide a toString() method and a getAge() method.
The main function.
In main function, do all of the following:
Output a heading on the screen that gives my name(siva) and the assignment name, P3: Family.
Find out how many people are in the users family and allocate the right size array of Person.
In a loop, read in the name and age of each family member. Use these to create a Person object and store it in the family array.
When input is nished, call the function named compute, described below, and receive a return value that is the average age of the family members.
Print the array of family members and print their average age. The average age should be formatted to show two decimal points. Do not worry about rounding.
The compute function.
In compute function, do all of the following:
Take one parameter, an array of Person objects.
Use a for-all loop to walk through the array.
For each Person in the array, get the age. Use the ages to compute the average age.
Return the average age. The average age should be calculated and include decimal points.
Testing to be done as per following:
Test every line of code in your program.
Test the program at least three times, once with a family of 0 Persons, again with 1 Person, and nally with more.
For 0 people, the program must end gracefully.
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