Object Oriented Systems Concepts and Approach MSIS 198:640:60 Homework 2 Rules:

by user

Category: Documents





Object Oriented Systems Concepts and Approach MSIS 198:640:60 Homework 2 Rules:
Object Oriented Systems Concepts and Approach
MSIS 198:640:60 Homework 2
Instructor: Farid Alizadeh
Due Date: Friday March 10, 2000 by e-mail befor 8pm
March 1, 2000
Please note the following rules:
1. Assignments should be handed at the beginning of the class period
they are due.
2. Late submission will result in loss of 25% of the points.
3. very important: It is not possible to pass this course if you miss more
than one programming assignment regardless of your scores in other
assignments or exam.
4. Since this assignment is due on a date other than class date, you should
submit your work by e-mail. To submit the assignment by e-mail put
all the files in a single .zip file with your name and assignment
number as the name of the file: e.g. SmithJohnHw2.zip, then send
your files to me at [email protected], on or before the
due date.
Programming Project
The sort program I put in
http://karush.rutgers.edu/ alizadeh/CLASSES/00sprMIS640/Javacode/sort/sort.java
makes an attempt to be object oriented to some extent. However there are lots
of room for improvement.
1. (20 points) Before making any changes understand what is required and
draw a class diagram relating sort and comparable classes in their new
form as described in the next three questions. (Don’t bother with main, or
various IO utilities.) For class sort as described in question 3 below, and
class comparable give a detailed view including information about their
fields, constructors and methods. For others, inside the class diagram, a
MSIS 640, Spring 2000
Homework 2
Last changed March 1, 2000
Due date: 3/10/00
simple view (with the name and possible sterotype such as abstract, etc.)
will suffice. You may use a graphical software such as MS paint or Word’s
drawing capabilities. Alternatively you may wish to use a UML modeling
software such as TogetherJ or Rational Rose. See the resource page in the
course home page for pointers to these software.
2. (10 points) The internal data of classes sort and the three comparable
classes are all exposed to outside world. Make the classes, constructors,
data and methods either private, package, protected, or public in conformance with encapsulation principle. In your comments before each class,
constructor, method or data explain and justify your decision. (You will be
graded on your explanations.) Then adjust the code by creating accessor
and modifier methods when necessary.
3. (10 points) Extend the stringComparable class so that strings are compared without considering the case of the characters. You may use the
methods that are supplied by String class.
4. (25 points) Rename the current sort class to SelectionSort. Then
add a super class to it and name it sort. The new sort class should be
generic and should accommodate a number of different comparison-based
sorting algorithms. Decide whether you want to define the sort class as
an interface, abstract class or a regular class. Justify your decision in
comments before the sort class (you will be graded on this justification.)
Shift as many of the SelectionSort class’s responsibilities as possible to
this superclass. Then rewrite the SelectionSort so that it is a subclass
of the sort class. Add at least one of the following sort classes besides
SelectionSort as another extension of sort:
• QuickSort: (If you implement this you will get 15 bonus
points.) The quicksort algorithm works as follows: Choose a random
element of the list (using random number generator Math.random()
method1 ) and call it the pivot element. Move every entry smaller
than pivot to its left and every entry larger than its right (thus pivot
element itself ends up in its rightful position.) Then recursively apply the same algorithm to the entries to the left of pivot, and to the
right of pivot.
• InsertionSort (If you implement both quicksort and insertion sort correctly you will get 20 bonus points): Start from
the first item in the list; obviously a list with only one item is already
sorted. Then insert the second item into the sorted sublist to its left,
and continue on until the whole list is sorted. Thus, at the kTH iteration the entries from 0 to k-1 are already sorted and you need to
insert the KTH entry into the list.
1 Math.random() returns a “random” double number between 0.0 and 1.0. To get a random
integer, say between 1 and 10 you need to multiply the random number returned by 10, add
1 to it and then apply the Math.floor() method.
MSIS 640, Spring 2000
Homework 2
Last changed March 1, 2000
Due date: 3/10/00
5. (10 points)Write an Exception class NotAnAlphabeticListException
and adjust the getWord method so that it throws this exception when
reading a sequence of characters that are not alphabetical Strings. (Pattern this Exception after the NotAnIntegerException exception.)
6. (15 points) In the main method you need to read lines from the input
file and interpret the line as a list of either integers, alphabetical words,
or case-insensitive alphabetical words. Each line contains two flags: The
first character in each line is either i or I indicating the list to follow is
made of integers, S or s indicating the list to follow is made of alphabetical
words, or c or C indicating the list to follow is a list of alphabetical words
to be treated as case-insensitive. The second character should be either
s or S indicating Selection sort algorithm, i or I indicating insertion sort
algorithm, or q or Q indicating quicksort. After the first two characters
you may start the list to be sorted.
The program has to keep reading one line at a time, sort the list. It then
should print a line of output first indicating the sorting algorithm used,
the type of data encountered, followed by the sorted list. This should go
on until end-of-file condition is detected upon which the program should
terminate. Thus the following will be a typical input file:
ii 12 -32 45 8 0 -3 02
sq Hello how are things
Cs Hi there what is happening
And atypical output is:
Integers sorted by insertion sort: -32 0 2 8 12 45
Words sorted by quicksort: Hello are how things
Case-insensitive words sorted by selection sort: happening Hi is there what
To facilitate your input reading and writing I have created a package called
easyIO. Open it up in a directory and import it to the class that contains
the main method. Read the documentation of this class carefully to see
what it does. The package resides in:
http://karush.rutgers.edu/ alizadeh/CLASSES/00sprMIS640/Javacode/easyIO
7. (5 points) Create a package called mySort and put all of the classes
related to sorting into this package. Make sure to set your directory name
and the CLASSPATH environment variable properly so that the compiler
knows where to look for this package.
Please Note: In the zip file in which you hand in your assignment, the
directory structure of the packages should be preserved.
8. (5 points) Write documentation comments for each of public classes and
then run javadoc program on it to create the .html files for them. Make
MSIS 640, Spring 2000
Homework 2
Last changed March 1, 2000
Due date: 3/10/00
sure the .html files are ncluded on your zip archive. The documentation
comments should be succinct yet adequately describe what each class is
doing. Remeber some of the questions above require explanations that
you have to include in thedocumentation.
Fly UP