Hey guys I can't seem to figure out how to get the minimum score using Math.min() I can do it if I only enter in two values but not more than than. If I enter three in it just returns the minimum value before the max in. My other problem is I can't seem to figure out how to return the names of students that have gotten two of the highest scores. For instance if a student has a high score then my program displays his/her name, but I'm not sure how to do that for lets say two or three people that got a 100 how would i be able to return all of their names. I have been trying this for hours and feel like a complete tool for not being able to figure this out. I'm pretty sure its a somewhat simple solution but i just can't seem to wrap my head around it. Any help would be appreciated. Thanks Guys! Here's my code:
import java.util.Scanner;
public class Assignment2
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int numberOfExams = 0;
System.out.print("Please Enter The Number Of Exams You Wish To Enter: ");
numberOfExams = input.nextInt();
while(numberOfExams != 0)
{
String asteriskA = "";
String asteriskB = "";
String asteriskC = "";
String asteriskD = "";
String asteriskF = "";
String name = " ";
String newName = " ";
int gotAnA = 0;
int gotAB = 0;
int gotAC = 0;
int gotAD = 0;
int gotAnF = 0;
double score = 0;
double total = 0;
double maximum = 0;
double minimum = 0;
double average = 0;
for(int i = 1; i <= numberOfExams; i++)
{
System.out.print("Please Enter Your Students Name And Grade Seperated By A Space: ");
name = input.next();
score = input.nextDouble();
total += score;
average = total/numberOfExams;
//minimum = score;
//minimum = Math.min(score, score);
maximum = Math.max(maximum, score);
if(score > 89)
{
gotAnA++;
asteriskA += "*";
}
else if(score > 79)
{
gotAB++;
asteriskB += "*";
}
else if(score > 69)
{
gotAC++;
asteriskC += "*";
}
else if(score > 59)
{
gotAD++;
asteriskD += "*";
}
else
{
gotAnF++;
asteriskF += "*";
}
}
System.out.println("\nThe Total For Your " + numberOfExams + " Exam Scores Is: " + total);
System.out.println("The Average Of Your Exam Scores Is: " + average);
System.out.println("The Minimum Exam Score Entered In This Set Is: " + minimum);
System.out.println("The Maximum Exam Score Entered In This Set Is: " + maximum + " by " + newName);
System.out.println("\n" + gotAnA + " Got An A.");
System.out.println(gotAB + " Got A B.");
System.out.println(gotAC + " Got A C.");
System.out.println(gotAD + " Got A D.");
System.out.println(gotAnF + " Got An F.");
System.out.println("\nA: " + asteriskA);
System.out.println("B: " + asteriskB);
System.out.println("C: " + asteriskC);
System.out.println("D: " + asteriskD);
System.out.println("F: " + asteriskF);
System.out.print("\nPlease Enter The Number Of Exams You Wish To Enter: ");
numberOfExams = input.nextInt();
}
if(numberOfExams == 0)
{
System.out.print("\nThank You For Using This Program! Have A Nice Day!");
}
}
}