Person class lab assignment
From WLCS
Person class
Create a Person class using the following specifications:
Attributes:
- first name
- last name
- birthdate
- id number
- height
- weight
- hair color
- eye color
Methods:
- Create a default constructor
- Create a specific constructor
- Create all the setters (mutators) for the listed attributes
- Create all the getters (accessors) for the listed attributes
Starting Template:
- Using PersonTestMain.java
- Create an instance of Person using the default constructor.
- Print out all the attributes using the getter methods.
- Change the attributes to different values by using the setter methods.
- Print out the attributes again.
toString() method
- Using the example below in your main() method, print out your Person variable:
Person p = new Person();
System.out.println(p); //automatically calls the toString() method
- What did you see when you tried to print the Person variable?
- Add a new method named toString() to your class
- toString() should return a String
- toString() should not have any parameters
- Create a String in the method that contains all your attributes
- return the String
- Now run your main() method again. What do you see?