Question
Java Programming: 1 Goal To write an entire class and a program. To use Strings. To use an array of objects. To use a for-all
Java Programming:
1 Goal To write an entire class and a program. To use Strings. To use an array of objects. To use a for-all loop. To write a getter and a string.
2 The Context This is a single-class project, the first for which I have not given you code to start from. It is not realistic, or useful, but it gives us a place to start. It is very important that you follow these instructions closely. They will guide you through learning a specific set of skills. Do not try to solve the problem some other way.
2.1 The Person Class Create a class called \Person" to hold two facts about a member of your family: first 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 your main function, do all of the following: Output a heading on the screen that gives your name and the assignment name, P3: Family. Find out how many people are in the user's 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 an input is finished, call the function named to 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 your 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. P.S: 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 finally with more. For 0 people, the program must end gracefully. After each run, capture the screen output with a mouse and paste it into a comment at the bottom of your .java le.
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