15-100: Introductory/Intermediate Programming (Section F)
Fall 2006
Exercise   
10/23/2006
Modify Names
Due:  Friday, November 3
11pm
 (NOTE DIFFERENT DUE TIME)

Relevant Reading:

  • Chapters 1-4 of Head First Java

Assignment:  (worth 10 exercise points)

Use the files in the folder of ex10-28.zip file as your basis for this assignment.    This exercise is intended to take less than 2 hours.  If you take longer, you may wish to seek help.

In this assignment, you are to create two classes, Dog and ShowDog.  They should meet the specifications below.   


Dog:
The class represents dogs that have a name (a String), a breed (a String), and an age (an integer in years).
There are two constructors with the following headers:
public Dog (String name, String breed, int age)
public Dog(String name, String breed)   // assumes the age is 0

The following methods:
public String getName()
public String getBreed()
public int getAge()
public String toString()  // returns a string in the following form:
         // name, a breed, is n years old
public void oneYearOlder()  // adds one to the age of the dog


ShowDog:
This class represents dogs that are winning points at dog shows.   Dogs that have at least 15 points are considered to be champions.  This class should extend Dog.  There are three constructors with the following headers:
public ShowDog(String n, String b, int age, int pts)
public ShowDog(String n, String b, int pts)   // assumes age 0
public ShowDog(String n, String b)  // assumes age 0 and points 0

The following methods should be available to instances of ShowDog:
public String getName()
public String getBreed()
public int getAge()
public int getPoints()
public String toString()  // returns a string in the following form:
         // name, a breed, is n years old, with p points, CHAMPION or NON-CHAMPION
public void oneYearOlder()  // adds one to the age of the dog

public boolean isChampion()  // true if points at least 15, false otherwise
public void addPoints(int p)   // add the parameter to the number of points


Testing:
You are provided with a tester program that will test to see that your classes are correct.   
  • If your console output has any line that begins with "PROBLEM:", there is a problem with your code.
  • Be sure to check all toString output for correctness.
  • At the end of this handout is sample output from the Tester program.
  • All of the testing code that is provided is code that you should be able to understand what is happening, although you should not need to look at the code.
  • Sample output upon running the Tester clas is included at the bottom of this page.
  • IF YOU WANT TO TEST THE DOG CLASS BEFORE YOU START THE SHOWDOG CLASS:

Notes and Reminders:

  • Be sure to make effective use of inheritance so as not to duplicate code and effort.
  • Your name and a description should go at the top of each file you create or modify, in order to take credit for that work.
  • Methods or groups of methods should have descriptive comments.
  • Methods and fields that can be declared as private should be declared private.


Handin:
  • Be sure to read the general handin instructions on the exercises page.
  • Rename the folder containing all of the files to be "lastname-firstname-100SectionLetter-dogs".   For example, if I were in Section Z, I would rename my folder to be:  "McElfresh-Scott-100Z-dogs"  (without the quotes).   
  • Create a zip file of this folder, with the same name as the folder (except with the .zip ending this time). Instructions for zipping can be found in the system and software handouts linked on the main course page.
  • Submit this file via the electronic handin.  If you have problems, contact me.

---------------
Testing dog named: Spot
    toString:Spot, a Dalmation is 2 years old.
---------------
Testing dog named: Fido
    toString:Fido, a Bulldog is 8 years old.
---------------
Testing dog named: Fifi
    toString:Fifi, a Poodle is 6 years old.
Testing puppy Dog named: Rover
    toString:Rover, a Bloodhound is 0 years old.
Testing puppy Dog named: Max
    toString:Max, a Shepherd is 0 years old.
*** Testing of Dog class complete.
---------------
Testing ShowDog named: Spot
Check all toString output to determine that the Champion status is correct.
    toString:Spot, a Dalmation is 2 years old. with 16 points, Champion
Adding 3 points...
Adding 3 points...
    toString:Spot, a Dalmation is 11 years old. with 19 points, Champion
Adding 3 points...
    toString:Spot, a Dalmation is 11 years old. with 22 points, Champion
Adding 3 points...
    toString:Spot, a Dalmation is 11 years old. with 25 points, Champion
Adding 3 points...
    toString:Spot, a Dalmation is 11 years old. with 28 points, Champion
Adding 3 points...
    toString:Spot, a Dalmation is 11 years old. with 31 points, Champion
---------------
Testing ShowDog named: Fido
Check all toString output to determine that the Champion status is correct.
    toString:Fido, a Bulldog is 8 years old. with 4 points, non-Champion
Adding 3 points...
Adding 3 points...
    toString:Fido, a Bulldog is 17 years old. with 7 points, non-Champion
Adding 3 points...
    toString:Fido, a Bulldog is 17 years old. with 10 points, non-Champion
Adding 3 points...
    toString:Fido, a Bulldog is 17 years old. with 13 points, non-Champion
Adding 3 points...
    toString:Fido, a Bulldog is 17 years old. with 16 points, Champion
Adding 3 points...
    toString:Fido, a Bulldog is 17 years old. with 19 points, Champion
---------------
Testing ShowDog named: Fifi
Check all toString output to determine that the Champion status is correct.
    toString:Fifi, a Poodle is 6 years old. with 2 points, non-Champion
Adding 3 points...
Adding 3 points...
    toString:Fifi, a Poodle is 15 years old. with 5 points, non-Champion
Adding 3 points...
    toString:Fifi, a Poodle is 15 years old. with 8 points, non-Champion
Adding 3 points...
    toString:Fifi, a Poodle is 15 years old. with 11 points, non-Champion
Adding 3 points...
    toString:Fifi, a Poodle is 15 years old. with 14 points, non-Champion
Adding 3 points...
    toString:Fifi, a Poodle is 15 years old. with 17 points, Champion
---------------
Testing puppy ShowDog named: Rover
Check all toString output to determine that the Champion status is correct.
    toString:Rover, a Bloodhound is 0 years old. with 8 points, non-Champion
Adding 3 points...
    toString:Rover, a Bloodhound is 9 years old. with 11 points, non-Champion
    toString:Rover, a Bloodhound is 9 years old. with 14 points, non-Champion
    toString:Rover, a Bloodhound is 9 years old. with 17 points, Champion
    toString:Rover, a Bloodhound is 9 years old. with 20 points, Champion
    toString:Rover, a Bloodhound is 9 years old. with 23 points, Champion
---------------
Testing puppy ShowDog named: Max
Check all toString output to determine that the Champion status is correct.
    toString:Max, a Shepherd is 0 years old. with 4 points, non-Champion
Adding 3 points...
    toString:Max, a Shepherd is 9 years old. with 7 points, non-Champion
    toString:Max, a Shepherd is 9 years old. with 10 points, non-Champion
    toString:Max, a Shepherd is 9 years old. with 13 points, non-Champion
    toString:Max, a Shepherd is 9 years old. with 16 points, Champion
    toString:Max, a Shepherd is 9 years old. with 19 points, Champion
---------------
Testing new puppy ShowDog named: Ginger
Check all toString output to determine that the Champion status is correct.
    toString:Ginger, a Poodle is 0 years old. with 0 points, non-Champion
    toString:Ginger, a Poodle is 9 years old. with 3 points, non-Champion
    toString:Ginger, a Poodle is 9 years old. with 6 points, non-Champion
    toString:Ginger, a Poodle is 9 years old. with 9 points, non-Champion
    toString:Ginger, a Poodle is 9 years old. with 12 points, non-Champion
    toString:Ginger, a Poodle is 9 years old. with 15 points, Champion
---------------
Testing new puppy ShowDog named: Cookie
Check all toString output to determine that the Champion status is correct.
    toString:Cookie, a Beagle is 0 years old. with 0 points, non-Champion
    toString:Cookie, a Beagle is 9 years old. with 3 points, non-Champion
    toString:Cookie, a Beagle is 9 years old. with 6 points, non-Champion
    toString:Cookie, a Beagle is 9 years old. with 9 points, non-Champion
    toString:Cookie, a Beagle is 9 years old. with 12 points, non-Champion
    toString:Cookie, a Beagle is 9 years old. with 15 points, Champion
*** Testing of ShowDog class complete.