Assignment 6: Abstract Classes, Interfaces, and Package Practice

Objective: To get experience using abstract classes and interfaces.

Due: Before class on Friday.

Using Abstract Classes (20)

Start a new project in Eclipse but say that you're using existing source code and give the path to your Assignment 4 code (the game).

Modify the GamePiece class so that it is an abstract class with an abstract method move.

Test your new code.

In comments in GamePiece, discuss why this is a better approach to organizing the code.

Proper equals Method in Birthday Class (20)

In assignment 3, you implemented a Birthday class and its equals method. At the time, we did not know all the techniques to implement the equals method properly.

Copy the Birthday class into this assignment's directory and modify your equals method to execute the following procedure, which should be followed for all equals methods you implement in the future:

  1. Use the == operator to check if the argument is a reference to this object. (If the variables are references to the same object, they're clearly equal!)
  2. Use the instanceof operator to check if the argument has the correct type. (Note: if a variable is a null reference, then instanceof will be false, so we don't need to check if the other object is null separately.)
  3. Cast the argument to the correct type.
  4. For each "significant" field in the class, check if that field of the argument matches the corresponding field of this object. Note: for doubles, use Double.compare and for floats use Float.compare
Source: Effective Java

Using Packages (15)

Modify your Assignment 5 classes excluding the Driver program to belong to a package. Use Eclipse to make the packages and move your classes into the package. Move is part of the Refactor menu. Name the package edu.wlu.cs.yourusername

Modify your driver program to import the classes from the package.

Using Interfaces (45)

Modify your Assignment 5 MediaItem classes to implement the Comparable interface.

In your driver program, sort the elements in the array.

Turnin

Copy your code into an assign6 directory in your turnin directory.

Grading (100 pts)

You will be evaluated based on the following criteria: