Share
Explore BrainMass

A Complete Java Program with Arrays and Objects

Analyzing Age and Weight

In this project you will combine the use of arrays and objects to perform some analysis of the age and weight relationships among a group of people. You have been contracted to write a program into which data about people, including their ages and weights, will be entered. As output the program will provide two listings of people who have particular characteristics within the group:

People who are both above the average age and above the average weight.
People who are both below the average age and below the average weight.

The program will ask the user for the number of people who need to be added to the list. It will then get the name, age, and weight data for that number of people. After the list has been entered it will analyze the data and generate lists of the people who fall into each of the categories listed above. If no one falls into one of these categories the program will just report "NONE" in place of the listing of people. The order that people appear in the lists is not important. Prior to displaying the two listings it will display the average age and average weight.

The following technical characteristics are requirements for the program:

The Person class from the previous program will be modified to include a weight field and the getter and setter for it.
The Person objects will be stored in an array.
Once the array has been created whenever the number of people in the array is needed by the program the length attribute will be used to provide that information.

The size of the array will the number of people to be added to the list.
A method named loadData() will be created to load all the data from the keyboard into a Person object. This method will take two parameters: a reference to the object to be loaded with data and a reference to a Scanner object to be used for input of the data.

A template program, AgeAndWeight.java is attached below. It provides some structure and guidance for the development of this program. You will use a modified version of the Person class developed for the previous project as the Person class for this project. I will make the sample solution for Person.java available to you as soon as you turn in the homework but you can alternatively use your own if you want to.

*****NOTE***** it is necessary to add a default constructor to the Person class. (in addition to the existing constructor that sets the name components). OR create the new Person objects inside the loadData() method and return the newly created and loaded object instead of receiving an empty object as a parameter and loading the data into it that will be OK. In that case Person would not have to have a default constructor and loadData() would receive only the Scanner object as a parameter. In the second case it is OK for Person to have a default constructor if you want one and you can use it instead of the parameterized constructor to create the new object if you want to and then load all the data into the object with the setters.

The following is a sample run of the program. User input is in bold blue text. Your input/output format should duplicate this as closely as possible.

Enter the number of people in the group: 4

Enter the data for the 4 people:

Person #1:
First name: George
Middle initial: M
Last name: Jones
Age: 25
Weight: 146.8

Person #2:
First name: Elizabeth
Middle initial: H
Last name: Morton
Age: 63
Weight: 225.7

Person #3:
First name: Alex
Middle initial: B
Last name: Butler
Age: 17
Weight: 92.3

Person #4:
First name: Amy
Middle initial: C
Last name: Rockwell
Age: 46
Weight: 179.3

Average age: 37.8
Average weight: 161.0

People above average age and weight:
Morton, Elizabeth H.
Rockwell, Amy C.

People below the average age and weight:
Jones, George M.
Butler, Alex B.

The following is a second data set that you can use for testing along with the expected results:

Arnold K. Smith, 56 yrs, 136.2 lbs
Joe S. Perez, 74 yrs, 136.0 lbs
Alice R. Styles, 17 yrs, 254.7 lbs
Rick E. Rudd, 23 yrs, 237.4 lbs

Average age: 42.5
Average weight: 191.1

People above average age and weight:
NONE

People below the average age and weight:
NONE

Attachments

Solution Preview

This solution requires creating modifying two Java classes: Person, AgeAndWeight. The Person class needs to have a new data member and associated getters/setters. The new data member is for storing a person's ...

Solution Summary

This solution provides a complete Java program with arrays and objects. The primary class is a Person class. The main program creates an array of Person objects and does some basic statistics on the set of data.

$2.19