Question: JAVA The code submitted for all problems must be compliant with the AutoGrader. For each problem in this assignment you will read from a file
JAVA
The code submitted for all problems must be compliant with the AutoGrader. For each problem in this assignment you will read from a file containing a list of integers. If the integer read is nonnegative, you will add it to the data structure. If it is negative you will remove an item from the data structure and incorporate it into a running hash, the final value of which will be returned to the AutoGrader. The hash value is simply the sum of the products of the incorporated items and their respective indices. The first item removed from the data structure has an index of 1, the second an index of 2, and so on. If the contents of the data file result in attempting to remove an item from an empty data structure, then a NoSuchElementException should be thrown (this is an unchecked exception thrown by the appropriate methods in the Collections hierarchy). If the end of the file is reached and the data structure still contains data, then it should be treated as though the file contained sufficient trailing zeroes to exactly empty the data structure.
Problem #1 Instantiate a queue using a LinkedList object. int queueHash(String filename); Use a for-each loop to empty the queue once the end of the file is reached.
Implemented code: Audograder
package problem;
public class Solution { // **** Set minArgs to the number of required arguments for test() final static int minArgs = 2; // **** This function is the test driver and should be kept largely // **** as it is, adjusting it to parse the arguments correcly and // **** call the method being tested. The return statement may // **** need to be modified for the type of result that is returned. public static String test(String[] args) throws Exception { // Check for minimum number of arguments if (!(args.length >= minArgs)) return "Insufficient Arguments (got " + args.length + " (needed " + minArgs + ")";
// Get input from (pseudo) command line arguments, parsed as appropriate. int n = Integer.parseInt(args[0]); double x = Double.parseDouble(args[1]); String s = args[2];
// Invoke method under test to solve the problem // The return type should be whatever is appropriate for the method String result = methodUnderTest(n, x, s); // Write answer to a string, doing any needed formating, WITHOUT a newline! return String.format("%s", result); } // Example method under test // Depending on inputs, this method produces infinite results, NaN results, and throws exceptions public static String methodUnderTest(int m, double y, String t) { return String.format("%d : %.2f - (%s) * %.2f $ %d", m, y/m, t, Math.log(y), m / (m - 10)); }
ASCII text file:
3 7 2 -1 5 -1 0 9 -1 8 7 -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
