Assignment 6: Eclipse, Inheritance, Interface and Collections Practice

Objective: In this assignment, you will create 4 classes that could be used to maintain the storage of media items in a library or that an individual owns. These classes will represent generic media items, CDs, DVDs, and books on tape. You will also write a driver program that uses these classes and illustrates polymorphism. You will use the Eclipse IDE and its features to ease the implementation of the classes.

Due: Before next Monday's class.

Overview

You are to implement four classes, MediaItem, CD, DVD, and BookOnTape. CD, DVD, and BookOnTape must all extend MediaItem. You must provide at least one constructor for each class that takes parameters to set all instance variables. You should make all the instance variables private in all classes. (Use the super mutator methods when appropriate.) You are not to repeat instance variables from MediaItem in the classes that extend it. You will have to override some of the methods in MediaItem in the various child classes, as appropriate.

Using Eclipse

Start Eclipse on the command line by typing eclipse.

If necessary, click the arrow button that says "Go to Workbench"

Set Up

Create a new Java project. Depending on your Eclipse perspective, you should be able to select File --> New --> Project and then Java to create a new Java project. Otherwise, you may need to do a search or something similar to select Java Project. Name the project Assign6. (I believe all the default values are correct and you can click OK to all the dialog boxes.) The Assign6 project is stored in a directory in your Eclipse workspace directory, which is located in your home directory by default.

Creating a class

With the Assign6 project selected, create a new class from the File menu. Name it the MediaItem class. The package name should be edu.wlu.cs.yourusername. Make the class abstract. You can have Eclipse create a default main method and generate comments for you if you select those checkboxes, which I recommend.

All media items have the following characteristics:

Create appropriate instance variables for this data.

Create a constructor. Consider the benefits of having a constructor in an abstract class. You can automatically generate constructors from the Source menu.

All media items have the following behaviors:

Don't just write these methods. Use Eclipse to do the heavylifting for you. Right click on your program, and select Source --> Generate Getters and Setters or Override/Implement Methods and select the appropriate methods. (See how much easier that is?)

Make sure you test each class along the way. You can put your test code in the main method of the class. It's easier to catch errors if you test small parts.

Executing Your Code

You can execute the test code in the main method using several different methods:

Follow one of the above procedures for executing the code you write in the rest of the assignment.

Creating Child Classes

CDs, DVDs, and books on tape have all of the characteristics and behaviors of media items.

Create a CD class. In the "New Class" window, make sure you enter the name of the parent (i.e., super) class (MediaItem).

CDs have the following additional characteristics and behaviors:

Create classes for DVD and BookOnTape

DVDs have the following additional characteristics and behaviors:

Books on tape have the following additional characteristics and behaviors:

A driver program

To test your classes, you will write a driver program that uses them. (Of course, you were testing each of your classes along the way too, right?)

The driver program emulates a library that keeps track of all the media that is in a library. Your driver program will

Save the output in a file. The alternatives:

Javadocs

Using Eclipse, generate template Javadocs for all of your classes, including your driver program. You may find it useful to refer to these while you're developing too. Make sure you fill in the templates with useful information about the method/class.

To generate the Javadoc, use File --> Export and under Java, select Javadocs. Make sure that all the classes are selected, not just one class.

Putting the Javadocs on the Web

From your home directory, go into your public_html directory and create a cs209 directory. Inside the cs209 directory, create a assign6 directory.

Open a web browser and point to http://www.cs.wlu.edu/~yourusername
You should see your cs209 directory, if you don't already have a home page. Click on the link. You should see your assign6 directory. If you already have a homepage, you can make a link to your cs209 directory from the web page, or you can navigate directly to http://www.cs.wlu.edu/~yourusername/cs209

Copy the Javadocs you generated into your ~/public_html/cs209/assign6 directory. OR, export the Javadocs again and make the destination be this directory.

Load the HTML documentation for your classes up in a browser, by clicking on the assign6 link. Check if the Javadocs are complete. If not, go back and update them in Eclipse and regenerate them. If you want examples of Javadocs, just look at the Java classes API.

Turnin

Copy the workspace/Assign6 project into your turnin directory, under a directory named assign6. To be clear, when you copy your project directory into your turnin directory, the location of your project directory will be /csdept/local/courses/cs209/turnin/username/assign6/Assign6

Grading (130 pts)

You will be evaluated based on the following criteria: