hamster
Class Hamster

java.lang.Object
  extended by hamster.Hamster

public class Hamster
extends Object

A simple class that represents a hamster. The minimum age for a hamster is initially 100 days, but class provides a method for clients to change this value.

Author:
CSE1030Z

Constructor Summary
Hamster()
          Creates a hamster with name and age of the previous hamster created.
Hamster(String name, int age)
          Creates a hamster with a given name and age.
 
Method Summary
 boolean equals(Object obj)
          Compares two hamsters for equality.
 int getAge()
          Get the hamster age.
static int getMinimumAge()
          Get the minimum age in days for a hamster.
 String getName()
          Get the hamster name.
 boolean setAge(int age)
          Set the age of the hamster.
static boolean setMinimumAge(int age)
          Set the minimum age in days for a hamster.
 boolean setName(String name)
          Set the name of the hamster.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hamster

public Hamster()
Creates a hamster with name and age of the previous hamster created. If no previous hamster has been created then the name is set to "Hammy" and the age is set to the current minimum age for a hamster.


Hamster

public Hamster(String name,
               int age)
Creates a hamster with a given name and age. If the name is null or empty then the name will be set to the name of the previous hamster created. If the age is less than the minimum hamster age then the age will be set to the age of the previous hamster created.

Parameters:
name - The desired name of the hamster.
age - The desired age of the hamster.
Method Detail

getMinimumAge

public static int getMinimumAge()
Get the minimum age in days for a hamster.

Returns:
The minimum hamster age.

setMinimumAge

public static boolean setMinimumAge(int age)
Set the minimum age in days for a hamster. If the desired minimum age is less than 0 then the minimum age for a hamster remains unchanged.

Parameters:
age - The minimum hamster age.
Returns:
true if age >= 0; false otherwise

getName

public String getName()
Get the hamster name.

Returns:
The name of the hamster.

getAge

public int getAge()
Get the hamster age.

Returns:
The age of the hamster.

setName

public boolean setName(String name)
Set the name of the hamster. If the name is null or empty then the name of the hamster remains unchanged.

Parameters:
name - The desired name of the hamster.
Returns:
true if name is not null and not empty; false otherwise

setAge

public boolean setAge(int age)
Set the age of the hamster. If the age is less than the minimum hamster age then the age remains unchanged.

Parameters:
age - The desired age of the hamster.
Returns:
true if age >= minimum hamster age; false otherwise

equals

public boolean equals(Object obj)
Compares two hamsters for equality. The result is true if and only if the argument is not null and both hamsters have the same names and ages.

Overrides:
equals in class Object
Parameters:
obj - The object to compare with.
Returns:
true if the hamsters are equal; false otherwise.