Question: In this assignment, you will develop a class that represents Person information, and another (application) class to test the Person class. In addition, you must

In this assignment, you will develop a class that represents Person information, and another (application) class to test the Person class. In addition, you must create a UML class diagram for your Person class.

The Person Class

The Person class will contain basic information about a Person. Specifically, it will include

-first name

-last name

-age

-marital status

-gender.

You can decide the appropriate data types for the member variables. Keep in mind that the gender will need to represent either male, female, or unknown. Similarly, the marital status; this can be married, divorced, widowed, or single, or unknown. These will be the instance member variables of the class.

(sorry for the caps i just copied from assignment)

NOTE: IN ORDER TO ENCOURAGE ENCAPSULATION AND INFORMATION HIDING, YOUR PROGRAM SHOULD NOT ALLOW INSTANCE MEMBER VARIABLES TO BE DIRECTLY ACCESSED FROM OUTSIDE THE CLASSTHUS THESE MEMBER VARIABLES MUST BE PRIVATE. ANY ACCESS TO THE PRIVATE MEMBER VARIABLES FROM OUTSIDE THE CLASS WILL BE DONE THROUGH THE ACCESSOR METHODS, WHICH WILL BE PUBLIC.

In addition to the instance member variables, the class should include the following instance methods:

1. a default constructor that sets default values for the member variables. By default, the first name should be FIRST, the last name should be LAST, the age should be 0, and the marital status and genders should be unknown.

2. an overloaded constructor that takes the first and last names, gender, age, and marital status as formal parameters and then sets the corresponding member variables based on these parameter values.

3. a method called personInfo that returns a String which contains the information of a Person instance. This method should take a boolean parameter which indicates whether the full data of the person will be included or not. If the parameter evaluates to true, then the method should concatenate, with appropriate labels, the first and last names, age, gender and marital status of the person. If the parameter is false, then only the first and last names should be returned in the string.

4. a method called equals that takes a single String parameter and tests to see if that parameters value is equal to the persons name. Assume that the string contains the first name, followed by a space, followed by the last name. Your equals method should then compare this string parameter against the first and last name of the Person instance, and then should return a boolean value depending on that test result.

5. get- and set- (accessor and mutator) methods for each of the instance variables. NOTE: the Person class does not do any user input or output. All information sent to methods must be passed as parameters, and any information given from methods is done via return values.

The Test Driver Application Class

In a separate a .java file, you will create a class called TestPerson. This class is an application class. It should contain a main method whose purpose is to test all of the functionality of the Person class.

Specifically, you need to do the following:

1) create a Person instance using the default constructor

2) create a Person instance using the overloaded constructor

3) display Person instances by using the personInfo method (#3 above) passing a false value in order to only show the names of the persons.

4) display Person instances by using the personInfo method (#3 above) passing a true value in order to show the full information for the persons.

5) Use the set mutator methods to set values in all the member variables of a person instance with correct data, and then use the get accessor methods to retrieve the values (and display these values using your preferred technique).

6) Use the equals method (#4 above) to test if a persons name matches a parameter string value.

In your test driver application program, you can choose how to interact with the user. All your application needs to do is display results that show the results from the above 6 tasks.

Refining the Person Class

If you are able to code the Person and TestPerson classes to work correctly as above, this will be worth 7 out of the total possible 10 points. For the remaining 2 points (totaling 9 out of 10), you need to make some refinements to your Person class. Specifically, the following should be done:

1) The set mutator methods should ensure valid data. Age should be ensured to be a positive number. If the user enters an age less than 0, you should store it as 0. The best place to code this is in the setAge accessor method. Similarly, gender and marital status must be ensured to be a valid value. So these set accessor methods should set the variable to unknown if an invalid parameter is passed.

2) When the user enters Persons first or last names, the Person class should ensure that this is stored with correct case. The first character of the name must be upper case and all remaining characters must be lower case, no matter how the user initially entered the names. This transformation should be done in the set mutator methods for the first name and the last name, which will be called from the overloaded constructor based on the values that were passed as arguments.

3) In your equals method (the method that tests to see if the persons name equals the passed in string), it should be able to match strings even if they are in different cases. For example, if the real person's name stored is john doe but the parameter string is jOhN DoE the program should still recognize this as a match.

For refinements #2 and #3, you can use methods from the String class to help you. Specifically, the substring, charAt, toUpperCase, toLowerCase, and equals or equalsIgnoreCase, length and indexOf methods of the String class can all be useful for your programming efforts in these refinements.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!