// Read in hours worked data and print out totals for each employee
// William #4556 4 6 2 9 9

// William: 6

import java.util.*;
import java.io.*;

public class HoursWorked {
	public static void main(String[] args){ 
		File f = new File("hours_worked.txt");
	
		printAvgHours(f);
		findEmplID(f);	
	}
	
	public static void findEmplID(File f) {
		Scanner in = new Scanner(System.in);
		System.out.print("What do you want to search for? ");
		String search = in.next();
		try {
			Scanner fileScan = new Scanner(f);
			boolean found = false;
			while(fileScan.hasNextLine()) {
				Scanner lineScan = new Scanner(fileScan.nextLine());
				String name = lineScan.next();
				if(name.equalsIgnoreCase(search)) {
					found = true;
					String id = lineScan.next();
					System.out.println(name + "'s ID is " + id);
				} 
			}
			if(!found) {  // same as found == false
				System.out.println(search + " is not in the file!");
			}

		} catch(FileNotFoundException e) {
			System.out.println(e);
		}
	}
	
	public static void printAvgHours(File f) {
		try {
			Scanner fileScan = new Scanner(f);
			while(fileScan.hasNextLine()) {
				String data = fileScan.nextLine();
				Scanner lineScan = new Scanner(data);
				String name = lineScan.next();
				lineScan.next();
				int total = 0;
				int days = 0;
				while(lineScan.hasNextInt()) {
					total += lineScan.nextInt();
					days++;
				}
				System.out.println(name + ": " + total/(double)days);
			}
		} catch(FileNotFoundException e) {
			System.out.println(e);
		}	
	}
}
