/**********************************************************************************
 * The Pet class. This pet can speak, get information about itself, celebrate
 * a birthday, and determine its weight in a given number of days.
 **********************************************************************************/


public class Pet
{

 /* Instance variables. */
 private double currentWeight, growthRate;
 private int age;
 private String name;
 private String kindOfPet = "Unknown";

 /**********************************************************************************
  * The pet will say the appropriate sound if you invoke the method speak.
  **********************************************************************************/
 public void speak ()
 {
  if (kindOfPet.equals("Dog"))
   System.out.println("Woof!");
  else if (kindOfPet.equals("Cat"))
   System.out.println("Meow!");
  else if (kindOfPet.equals("Bird"))
   System.out.println("Tweet!");
  else
   System.out.println("Unknown pet type.");
 }//speak
 
 /**********************************************************************************
  * The pet will say the appropriate sound n times if you invoke this method.
  **********************************************************************************/
 public void speakNTimes (int n)
 {
  int times;
  for (times = 1; times <= n; times++){
    System.out.println("---In Pet, times="+times);
    speak();
  }
 }//speakNTimes
 
 /**********************************************************************************
  * The pet will ask for information about itself in this method.
  * Precondition: setKind() has been invoked to make this pet of a certain
  * kind (Dog, Cat, or, eventually, Bird).
  **********************************************************************************/
 public void readInfo ()
 {
  System.out.println("I\'m a " + kindOfPet + ". What\'s my name?");
  name = SavitchIn.readLine();
  System.out.println("Well, thanks, I think "+name+
           " is a great name for a " + kindOfPet + ".");
  System.out.println("What is my current weight?");
  currentWeight = SavitchIn.readLineDouble();
  System.out.println("Gee, I didn\'t know I weighed " + currentWeight + " pounds! Heavy...");
  System.out.println("How much do I gain each week?");
  growthRate = SavitchIn.readLineDouble();
  System.out.println(growthRate+" pounds a week! I guess I\'m a healthy "+kindOfPet+"!");
  System.out.println("By the way, how old am I?");
  age = SavitchIn.readLineInt();
 }//readInfo
 
 /**********************************************************************************
  * Celebrate the pet's birthday, updating its age.
  * Precondition: setKind() has been invoked to make this pet of a certain
  * kind (Dog, Cat, or, eventually, Bird), and readInfo() for other information.
  **********************************************************************************/
 public void celebrateBirthday ()
 {
  age++;
  System.out.println("I, " + name + ", am now " + age + " years old!");
 }//celebrateBirthday
 
 /**********************************************************************************
  * Determine the weight in a given number of days.
  * Precondition: setKind() has been invoked to make this pet of a certain
  * kind (Dog, Cat, or, eventually, Bird), and readInfo() for other information.
  **********************************************************************************/
 public double weightIn (int days)
 {
  double newWeight = currentWeight + days*growthRate;
  if (newWeight > 0)
   return newWeight;
  else
   return 0;
 }
 
 /**********************************************************************************
  * Retrieve the pet's name.
  * Precondition: readInfo() has been invoked.
  **********************************************************************************/
 public String getName() {
   return name;
 }

 /**********************************************************************************
  * Set the kind of pet that this is.
  **********************************************************************************/
 public void setKind(String newkind) {
   kindOfPet = newkind;
 }
}
