Create two classes a main class and an object class


Discuss teh below:

Q: Create two classes, a main class and an object class. The object class will be called Person and will collect data about individual people. The main class will be called ThreeFriends and will instantiate three Person objects to represent three people who are friends and loading data into these objects. The user will enter the data that needs to be loaded into each object. Once all the objects have been loaded with data the program will print out the information about the three people in order of oldest to youngest person by extracting it from the objects.

The Person class must have the following characteristics:

Data fields:
firstName (String) - The person's first name
middleInitial (String) - The person's middle initial
lastName (String) - The person's last name
age (int) - The person's age

Methods:
Person( String fName, String mInitial, String lName ) - A constructor that loads the name data into the new object.

String getFullName() - A method that puts the three components of the name (last name, first name, middle initial) together into the form "Last, First I." and returns it as a string.

Setters and getters to set and get all of the data fields. You will not use all of them in this program but you implement them all. The setAge() setter must perform a sanity check on the age that is being set. If it is negative or greater than 110 it will set the age to -1. The special "age" of -1 means that an invalid age was entered. You will not display any message when the setter detects this. To generate the final output you will detect the age of -1 and print "INVALID" instead of the negative number in your output as shown in the sample run below.

When ordering the final outputs you can treat the -1 invalid age indicators just like any other age so they will come last since -1 is less than any valid age. If there are two ages that are the same the first person entered should be the first person listed in the group of same ages.

The following is a sample run of the program. Your program should exactly duplicate this sample I/O format and should work correctly for any valid input. User input is shown in blue bold text:

Enter the data for the three friends below.

First friend
First name: George
Middle initial: M
Last name: Jones
Age: 25

Second friend
First name: Mary
Middle initial: L
Last name: Smith
Age: 28

Third friend
First name: Omar
Middle initial: J
Last name: Backus
Age: 74

The three friends from oldest to youngest are:
Backus, Omar J. Age: 74
Smith, Mary L. Age: 28
Jones, George M. Age: 25

Here is a second run that illustrates the response to an invalid age:
Enter the data for the three friends below.

First friend
First name: Mary
Middle initial: L
Last name: Smith
Age: -5

Second friend
First name: Omar
Middle initial: J
Last name: Backus
Age: 134

Third friend
First name: George
Middle initial: M
Last name: Jones
Age: 25

The three friends from oldest to youngest are:
Jones, George M. Age: 25
Smith, Mary L. Age: INVALID
Backus, Omar J. Age: INVALID

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create two classes a main class and an object class
Reference No:- TGS01934787

Now Priced at $25 (50% Discount)

Recommended (95%)

Rated (4.7/5)