Computer Science 501
Data Stuctures and Algorithm Analysis
Fall 2013, The College of Saint Rose
This week's lab is designed to introduce (or reintroduce) the power of Java's Comparator interface as it applies to writing a generalized sorting method. You will extend the functionality of an existing class using inheritance, you will implement a simple sorting procedure within this extension, and you will learn about Comparators, which provide a more flexible mechanism for ordering objects than the Comparables we have seen in class.
You may work alone or with a partner on this lab. Of course, collaboration with your partner is unrestricted. You may discuss the lab with your classmates and give and receive some help, but your submission must be your own work (or that of you and your partner, if you choose to pair up with a classmate).
Lab Program
Do the laboratory at the end of Chapter 6 in Bailey.
Please note the following clarifications, modifications, and explanations relating to the lab procedure outlined in the text:
public class MyVector<T> extends structure5.Vector<T>
Keep in mind that as an extension of structure5.Vector, methods of MyVector will have access to instance variables and methods declared as protected in the structure5.Vector implementation. Make good use of this fact!
Important Note: The elementData array in structure5.Vector is declared as private rather than protected for type safety reasons. This means, unfortunately, that MyVector will not be able to access the array directly. Fortunately, Vector has methods that are almost as good as direct access to the array.
You may choose from the data files I have provided in the "labs/comparators" directory in the class shared area. See the README file there for more information. You may also use some other data that you find interesting.
Thought Questions
Answer the thought questions at the end of the lab. Include your responses in the README file described below.
Submitting Your Work
When you're finished, create a tar or zip file (or some similar archiving format) that includes the following:
Before 6:00 PM, Wednesday, October 23, 2013, submit your Java program for grading. There are two things you need to do to complete the submission: (i) upload a copy of your tar or zip file (for your program, please include .java files only, no .class files) using Submission Box under assignment "Comparators", and (ii) print and turn in a hard copy of your program.
Don't forget to check your programs for compliance with the Style Guide for CSC 501 Programs
Grading
Grading Breakdown | |
Program design | 2 points |
Program style | 3 points |
Program documentation | 5 points |
Program correctness: MyVector | 6 points |
Program correctness: Comparators | 5 points |
Program correctness: sorting applications | 3 points |
"Interestingness" of sorting applications | 2 points |
Thought questions | 4 points |