Exercise 1a        Name __________________        Score __/10

Modified: 

Use the following Java class definition for exercise questions:

  1. (1) What is the class name?

     
  2. (1) List the accessor method(s)?

     
  3. (1) List the mutator method(s)?

     
  4. (3) For the object at right, the printPerson method can be called by:

        person2.printPerson();

    Give the Java constructor or method call(s) to:
     
    1. create the object person2.


       
    2. change the name field of the person2 object to "George W. Bush".


       
    3. increment the age field to 60.



       
  5. (2) Write a complete accessor method for the name field.






     
  6. (2) Write a complete mutator method for the age field.






     
 public class Person
 {
 private int age;
 private String name;
 public Person(String newName)
 {
       name = newName;
       age = 0;
 }
 public Person (String newName, int newAge)
 {
       name = newName;
       age = newAge;
 }
 public void setName(String newName)
 {
       name = newName;
 }
 public int getAge()
 {
       return age;
 }
 public void incrementAge()
 {
       age=age+1;
 }
 public void printPerson()
 {
       System.out.println("Name:" + name + " Age:" + age);
 }
 }