Skip to main content.

Assignment 6: Eclipse, Inheritance, Interface and Collections Practice

Objective: In this assignment, you will

Due: Before next Wednesday's class.

Overview

You are to implement four classes, MediaItem, CD, DVD, and AudioBook. CD, DVD, and AudioBook 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 override 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"

If you have used Eclipse before, create a new workspace for this class: go to File --> Switch Workspace, choose Other and then make a new workspace directory (e.g., cs209_workspace).

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 audio books 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 AudioBook

DVDs have the following additional characteristics and behaviors:

Audio books 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:

Using Interfaces with Type Parameter (30)

Modify your MediaItem class to implement the Comparable interface. It is up to you how you compare the items, although it should be something that makes sense.

Let Eclipse do most of the work for you. (Note that this would be a little more straightforward in Eclipse if you added that the class should implement an interface during creation of the class, but I didn't want to give you too much to start.) When you start typing to implement the Comparable interface, use control-spacebar to let Eclipse complete "Comparable", which will automatically add the type parameter. Eclipse will give you an error about unimplemented methods; click on the error and select to implement methods. That will give you the method template--you still need to fill in the method.

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

Save your output in a file named witharray.out.

Modifying Library Driver: Using Collections (35 pts)

Create a copy of your driver program, named CollectionDriver

We discussed several different types of collections: lists, sets, and maps. In your new driver program, instead of an array, use an appropriate collection to store your items. Before making your choice, consider how easily you can implement the same functionality, e.g., store and retrieve items, and sort items, and what new functionality the collection will add/allow.

This part is underspecified on purpose. In comments in your driver program, defend your choice of collection.

Save your output in a file named withcollection.out.

Cleaning Up Your Code

If I have been giving you feedback about poor variable names, poor method naming, poor coding practices, poor formatting, inefficient code, not encapsulating, etc., clean up your code before submitting. Use Eclipse's refactoring and formatting tools and note any warnings too and see if you can clean up your code a bit.

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

We're having some technical difficulties with the new CS dept web server. Some things are set up differently than in the past. Bear with me.

If you do not have a public_html directory in your home directory, then we need to make the link by running the following command in a terminal in your home directory:

ln -s /home/www/users/MYUSERNAME public_html

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

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

Open a web browser and point to http://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. If you're getting permission denied errors, you can navigate directly to http://cs.wlu.edu/~yourusername/cs209/assign6 (If the above link doesn't work, try http://hydros.cs.wlu.edu/~yourusername/cs209/assign6)

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.

My web pages are not showing up on this server yet because PHP does not seem to be enabled.

Setting Up Your Path

In the hopes of having a smoother submit process while the server/system set up continues to be updated, I'm going to put some Bash scripts in our course's shared directory. We'll set up your PATH variable so that the shell will find these scripts.

Turnin

From the CS Machines

Export the project from Eclipse as a Jar file, as discussed in class, exporting the source files too. Save the file as assign6.jar in your cs209 directory.

Run the script submitJar.sh assign6. If you get an error message, make sure that your path is correct.

From Remote

Eclipse Remote System Access instructions.

Export the project from Eclipse as a Jar file, as discussed in class, exporting the source files too. Save the file as assign6.jar. Using Eclipse, copy the assign6.jar file into your (remote) cs209 directory.

Open an ssh terminal by right-clicking on Ssh Shells in the fred.cs.wlu.edu hierarchy, and choosing Launch Shell. In the shell that opens, run submitJar.sh assign6. If you get an error message, make sure that your path is correct.

Grading (200 pts)

You will be evaluated based on the following criteria: