/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package mp3_calebfontenot;

import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class FindTwoHighestScoresDoWhile {

    public static void main(String[] args) {
        // Create scanner
        Scanner input = new Scanner(System.in);

        // Define variables
        double highScore1 = 0, highScore2 = 0, score;
        String bestStudent1 = "", bestStudent2 = "", student;
        int numberToIterate = 0;
        
        // Compute
        System.out.print("Enter the number of students: ");
        numberToIterate = input.nextInt();
        int i = 0;
        do {
            System.out.print("Enter a student name: ");
            student = input.next();
            System.out.print("Enter " + student + "'s score: ");
            score = input.nextDouble();

            if (score > highScore1) { // New high score detected

                if (highScore1 != 0) {
                    highScore2 = highScore1; // assign highScore1 to highScore2
                    bestStudent2 = bestStudent1;
                }
                highScore1 = score; // assign current score to high score
                bestStudent1 = student;
            }
            i++;
        } while (i != numberToIterate);
        System.out.println("Best score belongs to " + bestStudent1 + ", with a score of " + highScore1);
        System.out.println("Next best score belongs to " + bestStudent2 + ", with a score of " + highScore2);
    }
}
