Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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);

}

}

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions