Objective: In this assignment, you will
Due: Before next Wednesday's class.
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.
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).
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.
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:
toString methodDon'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.
You can execute the test code in the main method using
several different methods:
main method OR
Follow one of the above procedures for executing the code you write in the rest of the assignment.
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:
String for the rating.
MediaItem's method for getting the
playing time.)Audio books have the following additional characteristics and behaviors:
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:
bin
directory of your Assign6 project directory and run java
edu.wlu.cs.username.Driver > ../outputfile The command
puts the output file in the parent directory so that you can see
it in Eclipse. If you don't see it in Eclipse, refresh the
navigator display.
Alternatively, the following command may work
(students report mixed results)
java
edu/wlu/cs/username/Driver > ../outputfile
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.
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.
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.
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.
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.
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.
.bash_profile. The file is in your
home directory, but you may not be able to see it because it's a
hidden file. You can open it using something like jedit ~/.bash_profile. Below the line that looks something like:
PATH=$PATH:$HOME/.local/bin:$HOME/binadd a line that says
PATH=$PATH:/csdept/local/courses/cs209/shared
source
~/.bash_profile, which updates your bash (the shell we use)
settings. Then, run the command echo $PATH to see if
your path now includes the CS209 directory.
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.
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.
You will be evaluated based on the following criteria:
Comparablemain
methods and the driver program