CS110 Lab 18:

Java Class Practice

In this exercise you will write a program that allows the user to care for a virtual pet. To properly maintain the pet the user will need to feed it, interpret its mood, and walk it. Note: The pet will be embedded with communication skills so that it can communicate its state of mind, which can range from happy to mad.

    Task 1: Plan the Pet class
      The core of this application is the pet itself.
      Begin by planning the Pet class.
      Identify the private members that describe the pet.
      The pet will need to store independent hunger and boredom levels.
      As time passes, the pet becomes hungry and its boredom level rises.
      Expect the pet's mood to be dependent on its current hunger and boredom levels.
      The owner of the pet needs to be able to communicate with the pet.




    Task 2: Identify the public methods for this class
      1. The user needs to be able to feed and play
        with the pet to reduce its hunger and boredom levels.
        To do this, the pet will need to be able to communicate its mood to the user.
      2. You will also need to simulate the passage of time. This method will be
        private because it will only be called by other member methods (feed, walk, or talk).




    Task 3: Identify how the user will operate his/her pet
      Describe the basic operating procedures for using the pet.
      Here is sample pseudocode for the application program:

        Upon execution, a pet is created.
        Do-while the user doesn't want to quit
            Display a menu of choices to the user: Talk, Feed, Walk, or Bye to Exit.
            if the user wants to talk, the pet will describe its mood.
            if the user wants to feed his pet, make the pet eat a fixed amount.
            if the user wants to walk his pet, make the pet walk walk a mile.




    Task 4: Code the files for the Virtual Pet.
      Create the following files:

    Task 5: Modify Pet.
      Assume all pets will randomly misbehave. Implement misbehavior into your pet class. Use the following guidelines. :