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


  1. What did you see when you tried to print the Person variable?
  2. Add a new method named toString() to your class
  3. toString() should return a String
  4. toString() should not have any parameters
  5. Create a String in the method that contains all your attributes
  6. return the String
  7. Now run your main() method again. What do you see?