final_exam.pdf

CSC 300/Data Structures I Final exam 85 points

Instructions

1. In Eclipse, create a package called finalexam. 2. Download and place into the package the file TestFinal.java. 3. Copy into the package the Chord class you created in an earlier assignment. 4. In the package, create a class called Final. All of the static methods you are asked to write will go in this class. 5. You will also eventually add to the package a reference class called CTATrain.

The first problem (your name) is worth 5 points; each of the other four are worth 20 points.

Your name

Define and place into the Final class a method with the signature:

public static String yourName()

that returns a string containing your name in the format "lastname, firstname". For example, for me the method would return the string "Rogers, John".

Priority queue

In the package algs24, you will find a class MinPQ, which implements a minimum priority queue. You are to use it to define in the Final class a generic sort method with the signature:

public static <Item extends Comparable<? super Item>> void minpqSort(Item[] a)

The code in the method should:

1. Create a MinPQ object. This class implements a minimum priority queue and is found in the algs24 package. 2. Insert each value in the parameter array into the min priority queue. 3. Using the delMin method, remove values from the min priority queue and place them into the array, overwriting the values that were there.

Done correctly, the array will now be sorted in ascending order.

FIFO Queue

Define in the Final class a generic method called reverseQueue with the signature:

public static <Item> Queue<Item> reverseQueue(Queue<Item> queue)

It modifies its parameter so that, when it returns, the values in the queue are reversed. For example, if the queue q1 contains the integer values 13, 15, 9, 10, and 25 (in that order), the following call:

q2 = reverseQueue(q1);

will result in q2 having the values 25, 10, 9, 15, 13 (in that order).

Use the queue class defined in algs13.

Reference class

Write a reference class called CTATrain that models information about a CTA "L" train making its run. The instance variables should contain information about the train's:

run number, an integer; line color, a string containing one of the values "red", "green", "blue", "purple", "brown", "pink", "orange", or "yellow"; next station, a string containing the name of the station it will next arrive at; arrival time, a string of the form "hh:mm:ss" indicating when it is expected to arrive at that station.

The API consists of:

a four-parameter constructor; individual methods for retrieving the value of each instance variable (i.e., accessor methods). For example, the signature of the one retrieving the line color will be public String getLineColor() toString() method that produces a string looking like this: [brown, 421, Rockwell, 13:34:54>, where the values are the line color, run number, next station, and arrival time; compareTo(CTATrain that) method that compares CTA train objects based on their run number, which means you should define the class so that CTATrain objects are comparable.

The test program has been written to read data from the file CTAdata.txt. Place this in your data folder in Eclipse. The test program then sorts an

array list of trains in a couple of different ways, each time printing the list.

Swan song

Using the Chord class you created in a previous assignment, define in the Final class a method with the signature

public static ArrayList<Chord> createRisingChordList(double duration, double[] frequencies, int count)

that creates, fills, and returns an array list of Chord objects. It will fill it with count chords. Every chord will have the duration specified. The first chord will have the frequencies specified in the parameters. The next chord is formed by multiplying each entry in the frequencies array by the value 1.224. So you'll have a loop that:

1. creates a chord from the duration and frequencies; 2. adds it to the array list 3. updates every value in the frequencies array by multiplying it by 1.224;

Follow that with a loop that plays the chords using the play() instance method in the Chord class.

Testing your code

The TestFinal program will test every one of your methods and classes. It produces (a lot) of output and it will be obvious whether your code works.

Submission instructions

Your finalexam package should contains three files:

1. Final.java, which contains the static methods your wrote; 2. CTATrain.java, which is the reference class you wrote for this exam; 3. Chord.java, which is the reference class written for a previous assignment;

It is not necessary to include the TestFinal.java program class. If you do, that's fine but when grading, I'll use my own copy. Please do not place the CTA train data file in the package!

As usual, zip the package folder containing these files into a zip file called finalexam.zip (and NOT finalexam.java.zip or some other variation!). Please MAKE SURE the package folder is zipped with the files! Submit the zip file into the drop box provided.

Last update: June 1st, 2017