/** A class to represent a Dog. * @see http:www.radford.edu/itec120/2007spring/Homeworks/hw03.html * @author Ian Barland * @version 2007.Feb.20. */ class Dog { /** This dog's age, in whole years. */ private int age; /** The sound this dog makes (written as a String -- not an audio object). */ private String sound; /* A Named constant. Really, should be a static field (and, public final). */ private int DOG_YEARS_PER_YEAR = 7; /** Constructor. */ public Dog() { this.age = 0; this.sound = "woof"; } /** age getter. * @return this Dog's age to (in whole years). */ public int getAge() { return this.age; } /** age setter. * @param revisedAge The amount to set this Dog's age to (in whole years). * If a negative number is passed in, 0 is used instead. */ public void setAge( int revisedAge ) { if (revisedAge >= 0) { this.age = revisedAge; } else { /* Optional: print an message to the system error log. */ System.err.println( "setAge: Tried to set this dog's age to " + revisedAge + "; used 0 instead." ); this.age = 0; } } /** sound getter. * @return this Dog's sound (written as a String -- not an audio object). */ public String getSound() { return this.sound; } /** sound setter. * @param revisedSound The text to set this Dog's sound to (written as a String). */ public void setSound( String revisedSound ) { this.sound = revisedSound; } /** Speak, doggy -- speak! * @return The sound made when this dog is told to speak (written as text). */ public String speak() { return this.getSound() + ", " + this.getSound() + "."; } /** Return the age of this dog, in (whole) dog years. * @return Return the age of this dog, in (whole) dog years. */ public int getAgeInDogYears() { return this.getAge() * DOG_YEARS_PER_YEAR; } /** return a string describing this Dog. * @return a String describing this Dog. */ public String toString() { return "[Dog: " + "age: " + this.getAge() + "sound: \"" + this.getSound() + "\"" + "]"; } /** Age the dog one year (in human years). */ public void ageOneYear() { this.setAge( this.getAge() + 1 ); } }