|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
Consider a class Dog, which has this interface. Could you write this class? Sure you could! (If not, it'd be a great practice problem.)
Go ahead an make several Dogs in BlueJ; declare and initialize the variables from Code Pad. You may use (the test fixture from) this .jar file (see how to get .jar files into BlueJ).
Dog myDog; myDog = new Dog( "rex", 5 ); Dog movieStar; movieStar = new Dog( "Air Bud", 3 ); |
Now we want to represent another, second class: Kennel. In our model, every Kennel has an address, and two Dogs being boarded. In addition, it seems that every kennel also has a third resident dog who is fifteen and is named “Bowser”.
Write a class to represent kennels. What do its setters/getters look like? What does its constructor look like? Write it!
Kennel a1Doggies; a1Doggies = new Kennel( "123 puppy lane", movieStar, myDog ); |
the environment: The object bench (the “heap”) Dog +--------+ +------------------------+ ___myDog___ | *---|----------------------------------------------> | ___________ | +--------+ | name | "rex" | | Dog | ----------- | +------------------------+ | ___________ | | ___________ | | age |____5______| | +--------+ | name | "Air Bud" | | /->| ___________ | _movieStar_ | *---|------> | ----------- | | | sound | "woof" | | +--------+ | ___________ | | | ----------- | | age |____3______| | | +------------------------+ /--> | ___________ | | | | sound | "woof" | | | | | ----------- | | | +------------------------+ | | | Dog | | +------------------------+ | | | ___________ | | | | name | "Bowser" | | | | | ----------- | | | | ___________ | | | /-> | age |___15______| | \--------------------------------------\ | | | ___________ | | | | | sound | "woof" | | | | | | ----------- | Kennel | | | +------------------------+ +-----------------------------+ | | | +--------+ | _________________ | | | | _a1Doggies_ | *---|------> | address | "123 Puppy Lane"|| | | | +--------+ | ----------------- | | | | | ___________ | | | | | dog1 | *-----|------|---/ | | | ----------- | | | | ___________ | | | | dog2 | *-----|------|-------/ | | ----------- | | | ___________ | | | resident | *-----|------|-----------/ | ----------- | +-----------------------------+You'll need to draw a similar picture for hw07a.
To consider: How to write a function so that people can ask any Kennel “what is the average age of the three Dogs you contain?”?
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2008, Ian Barland, Radford University Last modified 2008.Jan.24 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |