Name __________________________                                                              Date: ___/___/____

Mr. Merlis                                                                                                                   Block ___  - BDF___

JAVA 1                                                                                                                       Day of Class: __38__

 

JAVA 1 – Making a Class and its App

 

Our job is to create a Person class and its application program PersonTester.  The Person class should keep track of a person’s first name, last name, age, and favorite color.  The Person class should have two constructors, one that takes no parameters and one that takes a parameter for each of the four instance variables.

 

The constructor that takes no parameters should create a Random object and use it to give the person either the name “John Doe” or “Jane Doe” with (approximately) a 50% likelihood of either.  It should make the person a random age between 0 and 80 years old with a favorite color of blue.

 

The four parameter constructor should initialize all of the private instance fields to its appropriate parameter in the constructor’s header.

 

The Person class should also contain accessor methods that return the values for the private instance variables. 

It should have the methods:

 

Lastly, be sure to include a toString() method to print all the information about the person.

 

 

The application program should do the following:

  1. Create an ArrayList.
  2. Populate it with five people à Make three with the zero parameter constructor (the other 2 with the 4 parameter con.)
  3. Print out everyone’s name in the ArrayList.
  4. Have a message that says: “The following people are old and like red: “
    1. It should then loop through the ArrayList, printing people who are older than 24 and like red.
  5. Lastly, determine how many people are unknown (have a name of Jane or John Doe) and print out the total number.