Write a program to that finds lowest n closing dow jones

Assignment Help JAVA Programming
Reference no: EM13880849

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<E extends Comparable<E>>
{
...
}

The MinPQ<E> 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<Djia> pq = new MinPQ<Djia>();

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.

Reference no: EM13880849

Questions Cloud

Research ways of optimizing data organization : Using the Argosy University online library resources and the Internet, research ways of optimizing data organization
Create an implementation plan to integrate business analytic : Create an implementation plan to integrate business analytics
The mchs conducted a walk your pet day fundraising drive : The MCHS conducted a Walk Your Pet Day fundraising drive
Proposal that provides catacomb with converged network : Using this case study, you are to identify a minimum of five (5) requirements, analyze them, and offer a proposal that provides Catacomb with a converged network solution and explains how the components of the solution, and the solution as a whole..
Write a program to that finds lowest n closing dow jones : 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 the number of lowest closing averages requested by the user to be output.
Create a spreadsheet similar to the given example : Create a spreadsheet similar to the given example. Only the quantity cell (C5) contains a numerical value. All other cells are linked by formulas to the quantity cell.
Information concerning its postretirement benefit for 2012 : information available concerning its postretirement benefit plan for 2012.
Determine the critical path and identify the activities : Develop an estimated duration for each activity and determine the critical path and identify the activities that make up the critical path.
What equilibrium price will prevail in the short run : In a perfectly competitive market, the cost structure of the typical firm is given by C = 25 + Q2- 4Q, and industry demand is given by Q = 400 - 20P. Currently, 24 firms serve the market - Create a spreadsheet

Reviews

Write a Review

JAVA Programming Questions & Answers

  Explain the legal doctrine benefits balancing

Explain the legal doctrine "Benefits Balancing" as it pertains to applying the reasonable standard of care doctrine in the medical fields. Does a defense that the majority of physicians normally do not give a particular diagnostic test in the normal ..

  Write the string copy and string concatenation functions

Write the string copy and string concatenation functions and first version should use array subscripting, and the second version should use pointer arithmetic.

  Implement a thread for each creature representing a task

Implement a threads and a GUI interface using advanced Java Swing classes.

  You are a mighty warrior and armed with your trusty bow and

you are a mighty warrior and armed with your trusty bow and 3 arrows you enter the caves in search of the mighty

  What is an illustration of a javascriptreg framework in the

what is an example of a javascriptreg framework? in the framework you have described what is an example of an

  Describe how you would design a class for it

A class is a blueprint for an object. A class may have a default constructor, a constructor with arguments, accessor methods, public fields, private fields, and mutator methods.

  Develop an application to hold details of all the cabins

Develop an application to hold details of all the cabins on the site, including their cost per night, and produce a report which includes a list of cabins and some summary statistics.

  Write applet which reads five numbers-draw equivalent stars

Write the applet which reads five numbers (each between 1 and 30). For each number read, your program must design line containing that number of adjacent asterisks.

  Difference between string and stringbuilder

What is the difference between string and StringBuilder? What are the advantages and disadvantages of a StringBuilder

  The drink machine should have a supply

When the applet starts, the drink machine should have a supply of 20 of each of the drinks. The applet should have a text field where the user can enter the amount of money he or she is giving the machine. The user can then click on a button to selec..

  Compute the distance between the first two points

Compute the distance between the first two points and initialize the variable that represents the second shortest distance - Display the second shortest distance and the second closest two points.

  What about percent values and currencies

List three debugging techniques, within the debugger, that can be used to locate logical error in the Java code. For each of these tools, explain what purpose it serves, and how it relates to the debugging process.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd