Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 java program to search for a person by ID, example output should be:

Enter an ID: 456

Brad worked 36.8 hours (7.36 hours/day)

  • Example:

Enter an ID: 293

ID #293 not found

To modify the program, 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

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

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

2. Write two or three of your greatest weaknesses.

Answered: 1 week ago