// TO DO: add your implementation and JavaDocs.
//These are all the imports you are allowed, don't add any more!
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
public class StockMonitor {
// NO ADDITIONAL CLASS/INSTANCE MEMBERS SHOULD BE ADDED
// YOU CAN ADDITIONAL PRIVATE HELPER METHODS
public ThreeTenDLList fileToPriceList(String filename) throws IOException {
//Given a file name, open that file in a scanner and create a list of prices:
// - the values in the list should be the integers read in each time you call
// nextInt() on the scanner;
// - from head to tail, the values should follow the order from the input file
// return an empty list if file is empty
//default return, remove or updated as needed
Scanner scanner = new Scanner(new File(filename));
ThreeTenDLList priceList = new ThreeTenDLList<>();
while (scanner.hasNextInt()) {
priceList.addTail(scanner.nextInt());
}
// Close the scanner
scanner.close();
// Return the price list
return priceList;
}
public int stepProcess(int day, int price) {
//perform one step of span measurement:
// - determine and return the span of the given day and price using recordStack
// - additional updates to perform:
// - add the measured span to the back of spanList
// - add the pair of to the top of recordStack
// - update priceSpanMap as needed to ensure it always records the max span
// of each price we have processed
//
// Assume day and price are always non-negative
//
// With your implementation of this method, the updating loop in runPrograms()
// should be O(n) in non-debug mode (i.e. excluding printing overhead)
// where n is the number of prices processed
// - assume hashMap updating and searching is O(1)
//default return, remove or updated as needed
// Initialize the span to 1
int span = 1;
// Check if the price is already in the map
if (priceSpanMap.containsKey(price)) {
// If it is, increment the span by the maximum span seen so far for this price
span += priceSpanMap.get(price);
}
// Update the price span map with the new span for this price
priceSpanMap.put(price, span);
// Add the pair to the top of the record stack
recordStack.push(new Pair<>(day, price));
// Return the span
return span;
}
public int reportMaxSpan(int price){
// Use priceMap to find out and return the current max span for the given price
// if price is not present in priceMap, return 0
// O(1) if hashMap searching is O(1)
//default return, remove or updated as needed
// Check if the price is in the map
if (priceSpanMap.containsKey(price)) {
// If it is, return the maximum span seen so far for this price
return priceSpanMap.get(price);
} else {
// Otherwise, return 0
return 0;
}
}
public String spanRecordToString(){
// return a string to report the max span of each price in priceList
// - only report each price once
// - follow the same order as the first occurence of each price
// - each price report should use the same format of "price:maxSpan"
// - a single space should be padded between price reports
// - no leading or trailing whitespaces in the return string
// - return an empty string if priceList is empty
// O(n) where n is the length of price list
// - assume hashMap updating and searching is O(1)
//
//default return, remove or updated as needed
return null;
}
public static void testMain() {
//edit this as much as you want, if you use main without any arguments,
//this is the method that will be run instead of the program
System.out.println("You need to put test code in testMain() to run StockMonitor with no parameters.");
}
Include java docs please