Lab 3: Designing Class Hierarchy.
Part A: Building your own project
In this part you will open a new project AnimalProject.
Follow the instructions to build the new project.
1. Download the files jpt.jar and base.jar to your Desktop.
2. Open the Metrowork Codewarrior. To do it
a. Go
to Start menu àPrograms à Metrowerk
CodeWarrioir à
3. In File menu select New
4. Select Java2SE Stationery
5. Type in the name for your project and hit return
6. Expand the Generic item and select Java Application
7. In the Project menu select CreateGroup and name it CodeBase
8. In Project menu select Add Files and select the file Base.jar
9. The window asks where to add files - select Java Application Release only
10. In Project menu select Add Files and select the file jpt.jar
11. The window asks where to add files - select Java Application Release only
12. If needed, move base.jar and jpt.jar into the CodeBase folder (not important, just nice)
13. Expand the Sources tab in the project file list.
14. Delete TrivialApplication.
15. Copy the skeleton of the test class (e.g. ExerciseSet1A.java) and re-name it in the file named AnimalTest.java.
16. In three
places change the Exerciseset1A
to AnimalTest.
17. Delete all
methods, but the main method.
18. In Edit menu select Java Application Release Settings near the bottom
19. On the left
select Java
Target and replace TrivialApplication with the name of
your test class AnimalTest.
20. In File menu select New
21. Select File tab, then Text File - make sure you see where is it stored.
22. Give the file the name of the class you will write: Animal.java for Class Animal (spelling preserve)
23. Add a
simple skeleton for your class Animal.
* Class represents an animal
*/
public class Animal{
}
24. Now run
your project. You will see nothing, but you should check if it might be
compiled and run.
Part B: Designing-Building a Hierarchy of Classes
In this part we will develop a class hierarchy to represent three different types of animals: dogs, cats, and cows. For each type of Animal we will record its name, weight, and its owner.
Part B.1
Part B.2
Part B.3
Part B.4
Part B.5