Question
Use 3 files 1.TopM.java 2.tinyBatch.txt 3MinPQ.java TopM.java program reads a sequence of transactions from standard input; takes a command-line integer m; prints to standard output
Use 3 files 1.TopM.java 2.tinyBatch.txt 3MinPQ.java TopM.java program reads a sequence of transactions from standard input; takes a command-line integer m; prints to standard output the m largest transactions in descending order. Modify TopM.java to do the following: 1) Calculate and print the Average of the top M transactions. 2) Calculate the Median of the top M transactions. The median is the middle transaction in the Top M values. If there are an EVEN number of values, then the median is found by taking the mean (average) of the two middlemost numbers. Run your program for the Top 10 and Top 11 values separately and include in your results
tinybatch.txt
Turing 6/17/1990 644.08 vonNeumann 3/26/2002 4121.85 Dijkstra 8/22/2007 2678.40 vonNeumann 1/11/1999 4409.74 Dijkstra 11/18/1995 837.42 Hoare 5/10/1993 3229.27 vonNeumann 2/12/1994 4732.35 Hoare 8/18/1992 4381.21 Turing 1/11/2002 66.10 Thompson 2/27/2000 4747.08 Turing 2/11/1991 2156.86 Hoare 8/12/2003 1025.70 vonNeumann 10/13/1993 2520.97 Dijkstra 9/10/2000 708.95 Turing 10/12/1993 3532.36 Hoare 2/10/2005 4050.20
MinPQ.java
/****************************************************************************** * Compilation: javac MinPQ.java * Execution: java MinPQ implements Iterable
topm - Notepad File Edit Format View Help *Compilation: javac TopM.java *Execution: *Given an integer m from the command line and an input stream where * each line contains a String and a long value, this MinPQ client * prints the m lines whose numbers are the highest. * % java TopM 5 (m+1); while (StdIn.hasNextLine()) { // Create an entry from the next line and put on the PQ String line = stdin. readLine(); Transaction transactionnew Transaction (line); pq. insert(transaction); // remove minimum if m+1 entries on the PQ if (pq.size() > m) pq.delMin); // top m entries are on the PQ print entries on PQ in reverse order StdOut.println(); // print blank line for formatting StackTransaction for (Transaction transaction pq) stack new StackTransaction>(); = stack.push (transaction); for (Transaction transaction: stack) StdOut.println(transaction); topm - Notepad File Edit Format View Help *Compilation: javac TopM.java *Execution: *Given an integer m from the command line and an input stream where * each line contains a String and a long value, this MinPQ client * prints the m lines whose numbers are the highest. * % java TopM 5 (m+1); while (StdIn.hasNextLine()) { // Create an entry from the next line and put on the PQ String line = stdin. readLine(); Transaction transactionnew Transaction (line); pq. insert(transaction); // remove minimum if m+1 entries on the PQ if (pq.size() > m) pq.delMin); // top m entries are on the PQ print entries on PQ in reverse order StdOut.println(); // print blank line for formatting StackTransaction for (Transaction transaction pq) stack new StackTransaction>(); = stack.push (transaction); for (Transaction transaction: stack) StdOut.println(transaction)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started