January 29th, 2013, 02:54 PM
Result is not correct*answered*
I am working on this for homework and what I need the program to do is display the score and name of the person that has the highest score, the problem is that no matter what the last score is (highest, lowest or in between) that is what gets shown. I think I might be missing something, but I'm not sure what that could be. Also, we have not covered lists or arrays in this class yet, we are supposed to do this without a list or array. Any help with this would be greatly appreciated.
public static void main(String args)
Scanner input = new Scanner(System.in);
int count = 0;
double grade = 0, highestGrade = 0;
String name = "", highName = "", output="";
String numGrades =
("How many student grades are you entering: ");
numStudents = Integer.parseInt(numGrades);
//for(int count = 0; count < numStudents; count++)
while(count < numStudents)
// prompt for the user to enter grades
String inputName =
JOptionPane.showInputDialog("Enter a student name: ");
name = inputName;
//name = input.next(inputName);
String inputGrade =
JOptionPane.showInputDialog("What is that students grade: ");
grade = Double.parseDouble(inputGrade);
//grade = input.nextDouble();
if(grade > highestGrade)
highName = name;
highestGrade = grade;
(null, "The student with the highest score is " + highName +
" with a grade of " + highestGrade);
Last edited by crazyjdog; January 29th, 2013 at 03:07 PM.
Reason: Found the answer for myself.
January 29th, 2013, 03:01 PM
Where does the code print out the value of the highest grade?
Where does the code save the value of the highest grade?
What are the variables: grade and highestGrade used for?
What data is saved in each of them?
Last edited by NormR; January 29th, 2013 at 03:03 PM.
January 29th, 2013, 03:14 PM
I actually got it fixed, but as for the variables; grade is the input from the user and highestGrade is the value that is assigned to the highest grade. Also, there is no need to store anything as the if statement checks if the new input is higher and if not throws it away. Now if I were making this in a real world setting I would probably use a list or array to store the information for later use, but since this is a homework assignment and the instructor for the class has not "taught" us about lists or arrays we were not to use them.
Last edited by crazyjdog; January 29th, 2013 at 03:19 PM.
Reason: left out information