In this lab you will write a class file for the class Person, which will represent Person objects, and a PersonDriver class to test it. This is due Tuesday, 10/17 at 11:59pm.
Videos of the lesson for this topic are here: https://www.youtube.com/watch?v=P4nT9lU2rUI and https://www.youtube.com/watch?v=EgbvDTGtZY8
0. Please delete all old files in your turn in folder, including any Grader files I put in. Thanks!
1. Write the Person class (Person.java). This class will contain instance variables that represent that person's first name, last name, gender, and age. (age should be an int, the others should be Strings).
Your constructor should have 4 inputs for first name, last name, gender, and age, in that order. So if I wanted to create a Person representing Mr. Gravel, I would call your constructor like so:
Person gravel = new Person("Nick", "Gravel", "male", 21);
In addition to your constructor, you should include the following methods. You will need to decide the return types of some of these yourself:
//accessors, these methods take no inputs and just return each variable to whatever class calls them. They should not print anything
getFirstName( ) //this method should return the Person's first name and not change anything
getLastName( ) //this method should just return the last name
getGender( )
getAge ( )
//mutators for each variable, these void methods change some of the instance variables
changeFirstName(String [whatever]) //this method should input a name and change the first name to whatever is sent to the method
changeLastName(String [whatever])
genderSwap( ) //This method should take no inputs. If the person's gender is "male" it should be changed to "female" and vice versa. If the value of gender is something else, it will not make any changes. You may include other capitalization and cases if you want but I will only check the lower case versions.
//These four other methods
birthday( ) //this void method should take no inputs, just increase age by one and also println a happy birthday message.
numLetters( ) //this method takes no inputs and should return an int representing the number of letters in the person's name (both first and last). So, with my previous example, gravel.numLetters() should return 10.
isOldMan() //this method takes no inputs and returns a boolean. It should return true if the person has an age of at least 70 and has a gender of "male". Otherwise it should return false.
totalAge(Person other) //this method inputs a Person object and returns an int. It should returned the combined age of the current Person object and the other Person object. For example, if you have this code in a driver class:
Person chemSmith = new Person("Kathryn", "Smith", "female", 33);
Person principal = new Person("Jason", "d'Autremont", "male", 63);
Then calling either:
chemSmith.totalAge(principal)
OR
principal.totalAge(chemSmith)
should return 96 (33 + 63).
Remember to make your instance variables private and your methods public. MAKE SURE ALL YOUR METHOD NAMES AND SPELLING MATCH WHAT I HAVE WRITTEN.
2. Now, test your Person class by writing a driver class named PersonDriver. In this class, in a main method, you should create some (at least two) Person objects, then call each of their methods for each object. The whole point of this class if for you to get practice with the notation of creating objects and calling the methods of objects in other classes, as well as to allow you to test your code easily.
Submit Person.java and PersonDriver.java