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 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started