Question 1 of 5
Northwick Beacon stores integer blink counts in blinks.txt. Write readTotal(String path) that returns the sum of every int token. Include imports in your answer, throws IOException, a hasNext loop, and close.
Responses receive AI feedback against a rubric after submission. Scores are practice estimates.
Northwick Beacon stores integer blink counts in blinks.txt. Write readTotal(String path) that returns the sum of every int token. Include imports in your answer, throws IOException, a hasNext loop, and close.
A line of crate data is already in memory as String row = "11 20 4";
(a) Write code that uses split(" ") to print the middle integer 20. (b) Explain why split(",") would not isolate 20 from this line. (c) Explain why a regex such as split with a character class is out of scope here.
Write loadFlags(String path) that reads only boolean tokens with nextBoolean and returns true if at least one token is true. Use hasNext, close, and throws IOException. Do not use System.in.
Harborwick invoices use comma tokens with no spaces, such as 30,oak. Write sumCodes(String path) that adds Integer.parseInt of the piece before the comma for every token. Trace the return value for tokens 30,oak and 12,pine.
A student claims three things about Topic 4.6. Respond to each.
(a) "After my program ends, notes.txt disappears." (b) "I can skip import java.io.File if I import Scanner." (c) "If the file name is wrong, hasNext just returns false."