Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M91549356
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Java

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As