You are to write a program to that finds lowest n closing


Priority Queue and Application

You are to write a program to that finds lowest N closing Dow Jones Industrial averages and their dates in order by closing average. The program should prompt for:

• N: the number of lowest closing averages requested by the user to be output.

•The name of a file containing the Dow Jones Industrial average (djia) data which is assumed to be in the following format. Each line contains 3 items separated by whitespace: ?date

?opening average

?closing average

For example:

17-Mar-2006 11294.94 11279.65
16-Mar-2006 11210.97 11253.24
15-Mar-2006 11149.76 11209.77
14-Mar-2006 11076.02 11151.34

You write all code involved by yourself.

1. Class MinPQ

public class MinPQ>
{
...
}

The MinPQ class must implement these methods:

•MinPQ() - constructor
•E deleteMin() - removes and returns the minimum item; throws NoSuchElementException exception if the class is empty.
•E min() - return the minimum item (but don't delete it); throws NoSuchElementException exception if the class is empty.
•void insert(E item) - add item to this min priority queue
•boolean isEmpty() - is the priority queue empty?
•int size() - return the number of items in the priority queue

You must implement MinPQ using a Java LinkedList as the data storage. You must also keep the list sorted. You do so by placing the element at the right position at every insertion. You may NOT sort the whole list at NO time (by Collections.sort() or any other way). Doing so will result in significant reduction in points.

By keeping the list sorted, the complexity of the methods would become:

•deleteMin() - complexity: O(1)
•min() - complexity: O(1)
•insert - complexity: O(n) (where n is the size of the priorty queue at the time of the insertion)
•size() and isEmpty() - complexity: O(1)

2. Class Djia

This class should have three members to hold one date's djia data: the date, opening, and closing average. For date, use the Java LocalDate class. The class would then look like:

public class Djia {
// instance variables
private LocalDate date;
private double opening;
private double closing;

This class should also have the following public members:

•public Djia(String dt, double opening, double closing) - constructor
•public String date()
•public double opening()
•public double closing()
•public int compareTo(Djia djiaItem)
•public String toString()

Notes:

•The constructor's first parameter, String dt, should expect the form "28-Feb-2006 " (i.e., day-of-month (up to 2 digits), "-", month in a string of length 3 with the first character being an upper case, "-", year (in 4 digits)).
•The toString() method should return a string of the form "16-Mar-2012"
•The compareTo() method should compare the closing average of 'this' and of djiaItem and return -1 if this.closing is < djiaItem.closing; return 0 if they are equal; and return 1 if this.closing > djiaItem.closing.
•The toString() method should return a string of the form "16-Mar-2006, xxxxx, yyyyyy" -- a string representation of date, followed by opening, then closing, with ", " between the fields.

3. Application Program

The application class should be named DjiaApp. The application must use your MinPQ and Djia classes. In particular, the application should have this declaration:

MinPQ pq = new MinPQ();

Data Files

Two data files are provided

•tinyDjia.txt (20 djia items)
•djia.txt (19,449 djia items)

JUnit Test

A JUnit class (in MinPQTest.java) is provided to unit test your MinPQ before you use it in your DjiaApp application.

Sample Run

Here is a sample output of the program for input file tinyDjia.txt:

This program finds the N lowest closing averages in a file of Dow Jones Industrial Average closing records.

N: 5

File: tinyDjia.txt

The 5 lowest closing averages are:

Date Opening Closing

6-Mar-2006 11022.47 10958.59
9-Mar-2006 11005.66 10972.28
7-Mar-2006 10957.31 10980.69
28-Feb-2006 11096.75 10993.41
8-Mar-2006 10977.08 11005.74

Testing

•Be sure to test your MinPQ class (with the provided JUnit test).
•Test your DjiaApp class! Use tinyDjia.txt input file. If that gives the expected result, you could try the bigger djia.txt file to see if your program is acceptable fast enough.

Submission

Zip up all files, including .java as well as input files, and submit the zip file on D2L as usual.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: You are to write a program to that finds lowest n closing
Reference No:- TGS01174170

Now Priced at $30 (50% Discount)

Recommended (98%)

Rated (4.3/5)