Thursday, July 15, 2010

package org.cs212.hello;

public class Person
{
    // fields
    private String name; // the person's name
    private int maximumBooks;
  
    // constructor
    public Person()
    {
        name = "unknown name";
        maximumBooks = 3;
    }
   
    // getters and setters
    public String getName()
    {
        return name;
    }
  
    public void setName(String n)
    {
        name = n;
    }

    public int getMaximumBooks() {
        return maximumBooks;
    }

    public void setMaximumBooks(int maxBooks) {
        maximumBooks = maxBooks;
    }
   
    public String toString()
    {
        return getName() + " (" + getMaximumBooks() + " books)";
    }
  
}

No comments:

Post a Comment