15-100:
Introductory/Intermediate Programming
(Section F) |
Fall 2006 |
Relevant Reading:
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.
Notes and Reminders:
Handin:
--------------- 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. |