Class Dog


public class Dog extends Object
Represents a Dog and keeps track of the number of times the dog has performed bodily functions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Dog(String name)
    Creates a dog with the specified name
    Dog(String name, boolean walksFast, int productionRate)
    Creates a dog with the specified information
  • Method Summary

    Modifier and Type
    Method
    Description
    The name of the dog
    int
    The total number of times the dog has peed.
    int
    The total number of times the dog has pooped.
    A description of the dog as a string.
    boolean
    walk(int minutes, boolean fast)
    Walk the dog either fast or slowly.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Dog

      public Dog(String name)
      Creates a dog with the specified name

      Half of the times a new Dog is created, the dog walks fast, the other half of the time, the dog walks slowly.

      The number of poops per hour should be randomly generated but never zero.
      Parameters:
      name - name of the dog
    • Dog

      public Dog(String name, boolean walksFast, int productionRate)
      Creates a dog with the specified information
      Parameters:
      name - name of the dog
      walksFast - true if this is a fast walking dog
      productionRate - the average number of times the dog poops when walking for one hour, if the value passed is less than one, it should be set to 1.
  • Method Details

    • toString

      public String toString()
      A description of the dog as a string. The description should match this format:

      Spot is a fast walker who peed 12 times and pooped 1 time.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the dog object
    • getName

      public String getName()
      The name of the dog
      Returns:
      The name of the dog
    • walk

      public boolean walk(int minutes, boolean fast)
      Walk the dog either fast or slowly.

      If the dog walks slowly but this is a fast walk, the dog will refuse to go on the walk 25 percent of the time.

      Otherwise, the method simulates the dog going on a walk. The number of times the dog pees is a random value between zero and the number of minutes the walk is.

      The method also displays a summary of the walk to the console. For example:

      Spot went on a fast 41 minute walk and even pooped.

      or

      Spot went on a fast 41 minute walk.

      or

      Spot is slow walker and refused to go on this fast walk.

      The method determines whether the dog poops on the walk in a randomized way based on the dog's average poops per hour information.
      Parameters:
      lengthInMinutes - Number of minutes the dog is walked
      fast - true if and only if this is a fast walk
      Returns:
      true if and only if the dog pooped on the walk
    • getTotalTimesPeed

      public int getTotalTimesPeed()
      The total number of times the dog has peed.
      Returns:
      The total number of times the dog has peed.
    • getTotalTimesPooped

      public int getTotalTimesPooped()
      The total number of times the dog has pooped.
      Returns:
      The total number of times the dog has pooped.