/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindTwoHighestScores.java |
package mp3_calebfontenot;
import java.util.Scanner;
@author
public class FindTwoHighestScores {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double highScore1 = 0, highScore2 = 0, score;
String bestStudent1 = "", bestStudent2 = "", student;
int numberToIterate = 0;
System.out.print("Enter the number of students: ");
numberToIterate = input.nextInt();
for (int i = 0; i != numberToIterate; i++) {
System.out.print("Enter a student name: ");
student = input.next();
System.out.print("Enter " + student + "'s score: ");
score = input.nextDouble();
if (score > highScore1) {
if (highScore1 != 0) {
highScore2 = highScore1;
bestStudent2 = bestStudent1;
}
highScore1 = score;
bestStudent1 = student;
}
}
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);
}
}