for Qustion number 5. import java.io.File; import java.io.FileNotFoundException;
ID: 3699553 • Letter: F
Question
for Qustion number 5.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class HoursWorked2 {
public static void main(String[]args)
throws FileNotFoundException{
Scanner input = new Scanner(new File("hours2.dat"));
while(input.hasNextLine()){
String text = input.nextLine();
processLine(text);
}
}
public static void processLine(String text) {
Scanner data = new Scanner(text);
int id = data.nextInt();
String name = data.next();
double sum = 0.0;
while (data.hasNextDouble()) {
sum+= data.nextDouble();
}
System.out.println("Total hours worked by " + name + " (id#" + id + " = " + sum);
}
}
Question 5 1.5 pts Which of the following statements CORRECTLY describe the program HoursWorked2 listed on pp 414-415? Check all that apply. On line 18, the Scanner object is constructed out of a string. Each line is stored as a string. The file is read line by line. Overall, a file is processed using token-based processing and then each token is processed using line-based processing O Each string is passed to another method called processString Question 6 1.5 pts Which of the following statements are TRUE? Check all that apply. When using files with PrintStream objects, Java convention requires that you write a throw statement in the header of a method containing File and PrintStream declarations. In order to write to files a PrintStream object needs to be constructed and connected to the particular file to be written. PrintStream output new PrintStream("results.txt"); shows correct syntax for constructing a PrintStream object. Once a PrintStream object is constructed and associated with a file, one can use System.out methods like println and print to write to it.Explanation / Answer
Answer :
b. Each line is stored as a String
c.The file is Read line by line
Explanation : d is false because each line is passed to processLine and not processString.
c is false because file is processed using line based processing.
Answer: a, b is True
c is True
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.