Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

q3: Write a public static method named q3 that takes no parameters and has retur

ID: 3729398 • Letter: Q

Question

q3: Write a public static method named q3 that takes no parameters and has return type *HashMap of String to Integer. In this method, you may assume there is a file named *"annually.csv" with lines in the format *"along (Integer),up(Integer),free(Integer), south(Integer),while(String)" where each Integer column contains only well-formed integers. There is no header line in this file. This * method will return a new HashMap that maps "while" to "up" by putting one key-value pair into the HashMap for each line in "annually.csv"

Explanation / Answer

public static HashMap q3() { HashMap map = new HashMap(); try { Scanner fin = new Scanner(new File("anually.csv")); String line; String[] words; while (fin.hasNextLine()) { line = fin.nextLine(); words = line.split(","); map.put(words[4], Integer.parseInt(words[1])); } fin.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } return map; }