


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: Object-Oriented Design; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Unknown 1989;
Typology: Lab Reports
1 / 4
This page cannot be seen from the preview
Don't miss anything!



File Dog.java contains a declaration for a Dog class. Save this file to your directory and study it—notice what instance variables and methods are provided. Files Labrador.java and Yorkshire.java contain declarations for classes that extend Dog. Save and study these files as well.
File DogTest.java contains a simple driver program that creates a dog and makes it speak. Study DogTest.java , save it to your directory, and compile and run it to see what it does. Now modify these files as follows:
./Labrador.java:18: cannot resolve symbol symbol : constructor Dog () location: class Dog
But if you look at line 18 of Labrador.java , it's just a {. In fact, the constructor the compiler can't find ( Dog() ) isn't called anywhere in this file. a. What's going on? (Hint: What did we say about constructors in subclasses?) =>
b. Fix the problem (which really is in Labrador ) so that DogTest.java creates and makes the Dog , Labrador , and Yorkshire all speak.
Fix the problem by adding the needed code to the Yorkshire class.
Save these changes and recompile DogTest.java. You should get an error in Dog.java (unless you made more changes than described above). Figure out what's wrong and fix this error, then recompile DogTest.java. You should get another error, this time in DogTest.java. Read the error message carefully; it tells you exactly what the problem is. Fix this by changing DogTest (which will mean taking some things out).
File IntList.java contains code for an integer list class. Save it to your directory and study it; notice that the only things you can do are create a list of a fixed size and add an element to a list. If the list is already full, a message will be printed. File ListTest.java contains code for a class that creates an IntList , puts some values in it, and prints it. Save this to your directory and compile and run it to see how it works.
Now write a class SortedIntList that extends IntLis t. SortedIntList should be just like IntList except that its elements should always be sorted. This means that when an element is inserted into a SortedIntList , it should be put into its sorted place, not just at the end of the array. Think carefully about what methods and instance variables you have to define in SortedIntList and what you can inherit directly fro m IntList — don't override anything you don't have to.
To test your class, modify ListTest.java so that after it creates and prints the IntList , it creates and prints a SortedIntList containing the same elements.
File Player.java contains a class that holds information about an athlete: name, team, and uniform number. File ComparePlayers.java contains a skeletal program that uses the Player class to read in information about two baseball players and determine whether or not they are the same player.
Use this strategy to define an equals method for the Player class. Your method should take a Player object and return true if it is equal to the current object, false otherwise.
Test your ComparePlayers program using your modified Player class. It should give the results you would expect.