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

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

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

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions