This project requires the use of the following Java program files:
|
Download them to your PC before doing this project.
Abide to the Emory Honor code when doing assignments.
|
|
The details on what to do is in the next section of the write up.
The super class Animal class that represents a "animal" contains 2 variables: name and sound. The class contains a constructor and a toString() method:
public class Animal { private String name; private String sound; public Animal(String n, String s) { name = n; sound = s; } public String toString() { return name + " - " + sound; } } |
Part 1 requires you to write 3 classes. I will detail them below in 3 steps
Step 1:
|
Step 2:
|
Step 3:
|
When you finish all these 3 steps, you can use TestA1.java, TestB1.java and TestC1.java to test your code.
You must not see any compile error messages when you compile these test programs.
In Part 2, you must write the AnimalTrap class that is a parameterized subclass of the Trap class.
The AnimalTrap class does not have any additional instance variables nor methods. (Again, I kept it simple to focus on generics)
You must not make any changes to the Trap, Mosue and Bear class when you do Part 2
When you finish, you can use TestA2.java, TestB2.java and TestC2.java to test your code.
You should see the same output for TestA2 and TestB2.
But TestC2 will fail to compile (this is the correct behavior !)
FYI, the only difference between the test files in Part 1 and Part 2 is this line:
Line 10 in test files in Part 1 uses: new Trap<>() Line 10 in test files in Part 2 uses: new AnimalTrap<>() |
In Part 3, you will be using the provided InsertionSort.java program to sort animals by their weight in increasing/ascending order.
The Animal class contains the getWeight() method that returns the weight of an animal.
The InsertionSort.java program can sort an array of MyComparable object
The MyComparable interface is defined as follows:
public interface MyComparable { // Return true if this object is less than x public boolean isLessThan(MyComparable x); } |
For Part 3 of the assignment:
|
When you finish, you can use Test3.java to test your code.
You must be on Emory campus (e.g.: Emory unplugged) in order to turn in an assignment
Use your web browser and visit the cs171 turnin website: click here
|
Follow the instructions given in homework 1 to turn in.
You must be on Emory campus (e.g.: Emory unplugged) in order to make extension requests
Use your web browser and visit the cs171 turnin website: click here
Use assignment code hw5 to request extension for this homework.
Follow the instructions given in homework 1 to request extension.