Averaging Grades

I an new to JAVA and am stuck. I need to make a program that will allow input of grades. If an entered grade is less than 0 or more than 100 an error message needs to be displayed. The Loop function needs to end when a certain value is entered and then the other values need to be averaged. I have what I've come up with so far, but its still not working. I need to have this finished by tonight so if there is anyone out there that can send some help my way I would appreciate it.

Thanks!

import javax.swing.*;

publicclass Grades2

{

publicstaticvoid main(String[] args)

{

int count = 0;// Initialize these to zero.

int total = 0;// Initialize these to zero

int avg = 0;// Initialize these to zero.

int input;// Don't need to initialize, but it won't hurt

// Display a message requesting a grade between 0 and 100

System.out.println("Enter numerical grades");

input = value;// Store the input to variable input

while(input != 999){// If they entered 999, the while loop will not run.

if ((input >= 0) && (input <= 100))// Check if value is in the range of 0 to 100

{

count ++;// Increment the number of values input

total += input;// Add the input to the running total

}

else

{// the value was not between 0 and 100, the while loop will check to see if it is 999

JOptionPane.showMessageDialog(null,"Enter a valid grade",

"Grades Program", JOptionPane.INFORMATION_MESSAGE);

// Do not increment count

// Do not increment the total.

}

input = JOptionPane.showInputDialog("Enter a Final Grade: ");

// Input = new value;

}// This loop will continue to run until the user enters 999 as the input

if (count == 0){// I'm doing this check because you don't want to do a divide by zero

JOptionPane.showMessageDialog(null,"No grade has been issued",

"Grades Program", JOptionPane.INFORMATION_MESSAGE); ;

}

else{

System.out.println("The average is: " + total / count);

}

}

}

[3678 byte] By [FLLionEyEsa] at [2007-11-27 4:55:53]
# 1

Two points:

1) You seem to be mixing command-line input and output (System.out.println("...")) with some GUI input and output (JOptionPane.showMessage(...)). Shouldn't you stick to one or the other? Personally, I'd recommend sticking with the command line for now, it's easier and quicker to program.

2) You've left a lot to do at the last minute. I wish you luck. Most of what you have to do shouldn't be hard. I don't see it as your being stuck. You just have to sit down and do the work; we can't do it for you. If you have questions about specific parts of your code after you have created it, well, we can help you with that. Again, good luck.

/Pete

petes1234a at 2007-7-12 10:10:56 > top of Java-index,Java Essentials,New To Java...
# 2
On review of the code, there isn't that much left to do actually, and most of the code is functional. Just think through the logic, keep working at it, and you'll get it. Don't give up.
petes1234a at 2007-7-12 10:10:56 > top of Java-index,Java Essentials,New To Java...
# 3

Thanks Pete, I know I have a lot left with little time and that got way out of control this week. I usually have plenty of time, but this week I had to attend the Governor's Hurricane Conference from Wed-Fri in Ft Lauderdale FL, and then drive from there to Maryland late Friday after the conference. Unfortunately this left me very little time to do my work in the time frame necessary. Alas, I will get it done one way or another.

I do not want someone to do this for me, because I can't learn that way. I do appreciate your comments, they were helpful. I just needed some guidance on where to look because right now I am racking my brain and as I mentioned running out of time. Again, thanks so much!!

FLLionEyEsa at 2007-7-12 10:10:56 > top of Java-index,Java Essentials,New To Java...
# 4
Question: were the JOptionPanes put there by you or by your teacher?
petes1234a at 2007-7-12 10:10:56 > top of Java-index,Java Essentials,New To Java...