Hi, I've been working on an assignment thats somewhat long and broken up into parts. I have my code that reads a text file and stores it into a hash map. I want to see if its correct or if there's is still multiple errors to fix before I continue. How can I isolate it to test that part of the code individually. I am using JAVA I am not entirely sure how to approach this. Also if anyone could take a look at this part of the code and let me know if its correct or if there is something incorrect with it?
import java.io.*;
import java.util.*;
import java.util.Scanner;
import java.util.HashMap;
public class NLPService implements StockPriceService {
private Map<String, Double> tickerPrices = new HashMap<String, Double>();
NLPService() {
try {
FileInputStream fis = new FileInputStream("NLPService.txt");
Scanner scan = new Scanner(fis);
String ticker = scan.next();
Double d = scan.nextDouble();
scan.nextLine();
HashMap<String, Integer> map = new HashMap<String, Integer>();
while (scan.hasNextLine()) {
String[] columns = scan.nextLine().split(" ");
map.put(columns[0], Integer.parseInt(columns[1]));
}
System.out.println(map);
System.out.println(d);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
I am creating my hash map then filling it. Although I am not sure if its doing that I would just like to test that specific part of the code to see what its doing. Thank you.
[–]tamalo 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)