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

public class Lab6 {

    public static int lastDiveNum=0;  // Global to allow two methods to share same variable
    
	public static void printIntro() {
		System.out.println("Welcome to the Diver Scoring program. This program will calculate an");
		System.out.println("  overall score for a diver, based on individual dives.\n");
	}
	
	public static double calculateDiveScore(String diveLine) {
		Scanner data = new Scanner( diveLine );
		lastDiveNum = data.nextInt();  // Get rid of diveNum
		double degreeDiff = data.nextDouble();
		double sum = 0.0;
		double min = Double.MAX_VALUE;
		double max = Double.MIN_VALUE;
		while (data.hasNextDouble()) {
			double next = data.nextDouble();
			sum += next;
			min = Math.min(min,  next);
			max = Math.max(max, next);
 		}
		data.close();
		sum -= (min + max);  // Subtract out minimum and max dive scores
		return sum*degreeDiff*.6;
	}
	
	public static void processDives(Scanner file) {
		int cnt=0;
		double sum=0.0;
		while (file.hasNextLine()) {
			String diveLine = file.nextLine();
			double diveScore = calculateDiveScore( diveLine );
			sum += diveScore;
			cnt++;
            System.out.printf("The diver's score for dive %d is %.2f.\n", lastDiveNum, diveScore);
		}
		file.close();
		System.out.printf("\nThe average score for these dives is %.2f.\n", sum/cnt);
	}
	
	public static void main(String[] args) throws FileNotFoundException {
		Scanner file = new Scanner(new File("DiveData.txt"));  // File scanner
		printIntro();
		processDives(file);
	}
}