Pet Shop v1 Application Project
This is the story about a pet shop with few pets but really cute ones. You will write an application designed to get information about this unusual pet shop. You will be applying concepts about polymorphism to develop your classes and driver program. This version one (v1) of Pet Shop will focus on inheritance. In addition, this application will help you better prepare for the AP exam Inheritance, and Polymorphism.
The way you should focus on this project:
1. DO NOT VIOLATE ENCAPSULATION
2. Use INHERITANCE CONCEPTS to re-use code and functionality.
Specifications:
You will create only one animal class and two of your classmates will share one of their own each for you to have a complete Pet Shop application.
The sample test below is given only to help you understand this assignment. Write your own test class but follow this general outline:
(NOTE: How close you follow the outline and polymorphism concepts will determine your grade)
- Create an object of PetSet.
- Create multiple instances of at least three different kinds of animals. Observe that they are Animal objects.
- Print each Animal object’s sound.
- Add them to the PetSet object.
- Print the PetSet object to display what the animals are.
Sample test:
… PetSet myPetShop = new PetSet(); Animal tweety = new Bird(45.00, "I am a bird"); Animal duffy = new Bird(5.00, "I am a bird"); Animal nemo = new Fish(62.00, "I am a fish"); Animal bear = new Dog(1100.00, "I am a dog"); … … myPetShop.add(tweety); myPetShop.add(duffy); myPetShop.add(nemo); myPetShop.add(bear); … System.out.println(myPetShop);
Sample output:
I can sing // phrase
…
I am a bird
I am a bird
I am a fish
I am a dog
1. PetSet class has the following members:
Attributes:
- an ArrayList of Animal objects (use type parameter)
- sum (type double)
- maxPrice (type double)
Behaviors:
- one constructor
- add() an animal to the ArrayList and keeps track of largest price, it also updates the sum variable with the price of the animal
- getAverage()
- getMaximum()
- toString()
- whatIam() uses the for each loop to create a string with all the strings. Look at the sample output above.
This class should be very similar to the DataSet class.
2. The Animal class has the following members:
Attributes:
- price (type double)
- animal (type String)
Behaviors:
- one constructor with one input argument, the “animal” or “price”
- whatIam()
- getPrice()
- setPrice()
3. Animal’s children classes:
Each animal ( as an example: Bird) has the following members:
Attribute:
- phrase (type String)
// For one choice of design. The other design, you do not have an instance field.
Behaviors:
- one constructor
- whatIam() returns “I am a bird”
- getPrice()
- a method of your choice unique to all animal’s child class. In the case of a bird, tweet() returns “I can sing”. This can be done in two different ways according to your design.
4. Driver and a bit more:
- Create your own driver with all the necessary components to test all parts of your application.
- Keep to the specification given so everyone can exchanges classes and have an easy integration into everyone’s application.
- Maintain good documentation so everyone understands your code.
- Talk to your classmates to find out what animal they are implementing so there is not unnecessary duplication.
- Since the specifications for each class have been already defined above, work on the animal’s child class first so you can share with your classmates before the end of the period.