Question: public static void main (String [] args) throws FileNotFoundException { Scanner input = new Scanner (new File (hours.txt)) while (input.hasNextLine()) { //while it is not

public static void main (String [] args) throws FileNotFoundException {

Scanner input = new Scanner (new File ("hours.txt"))

while (input.hasNextLine()) { //while it is not end of file // process each person

String line = input.nextLine();

Scanner lineScan = new Scanner (line);

int id = lineScan.nextInt();

String name = lineScan.next();

double totalHours = 0; int day =0;

while (lineScan.hasNextDouble()) {

totalHours += lineScan.nextDouble();

day++;

}

System.out.println (name + " (ID#"+id+") worked "+totalHours+" hours ( "+totalHours/day+ " hours/day)");

Modify this program we did in class to search for a person by ID:

  • Example:

Enter an ID: 456

Brad worked 36.8 hours (7.36 hours/day)

  • Example:

Enter an ID: 293

ID #293 not found

For this assignment, write two methods as follows:

// Locates and returns the line of data about a particular person.

public static String findPerson(Scanner input, int searchId) {

// Totals the hours worked by the person and outputs their info.

public static void processLine(String line) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!