aspose file tools*
The moose likes Beginning Java and the fly likes need help please? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help please?" Watch "need help please?" New topic
Author

need help please?

del barton
Greenhorn

Joined: Nov 20, 2004
Posts: 1
public class debgrader
{
public static void main(String[] args )
{
int numberofstudents,score;
double next;
char answer, grade;



do
{
System.out.println("Enter scores for all students");
System.out.println("Enter a negative numger after");
System.out.println("You have entered all the scores.");

numberofstudents = 0;
score = 0;
grade=0;
next = SavitchIn.readLineDouble();
while (next >=0)
{
numberofstudents++;
next = SavitchIn.readLineDouble();
}
if (numberofstudents > 0)
System.out.println("Total number of grades " + (numberofstudents));



{

numberofstudents = grade;
if (score >= 90){
grade ='A';
numberofstudents++;}
else if (score >= 80){
grade ='B';
numberofstudents++;}
else if (score >= 70){
grade ='C';
numberofstudents++;}
else if (score >= 60){
grade ='D';
numberofstudents++;}
else if (score < 60){
grade ='F';
numberofstudents++;}
}
System.out.println("Number of A's = " + (numberofstudents++));
System.out.println("Number of B's = " + (numberofstudents++));
System.out.println("Number of C's = "+ (numberofstudents++));
System.out.println("Number of D's = "+ (numberofstudents++));
System.out.println("Number of F's = "+ (numberofstudents++));

System.out.println("Want to score another exam?");
System.out.println("Enter y for yes or n for no.");
answer = SavitchIn.readLineNonwhiteChar();
}while ((answer == 'y') || (answer == 'Y'));
}
}

will not calculate the right number of letter grades
what am I doing wrong ?
please help Thank you.
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
first of all, make your posted code more readable by using
"code" and "/code" (replace my double quote marks w/ square brackets)
markers to get the proper formatting.


First problem I see in your code is that you initialize grade as 0 and never read into it (from input) any other value.
When you read a grade, you count that as one more student. You never actually record the grade itself.

Create a test input of about 4 grades.
Now write down the names of all your variables on a sheet of scratch paper. These are column headers.
Run through your program using the test input and write down under each
variable (in its column) the values that variable takes on as you run through the program. If it helps you can write down the changes taking place row by row (number the rows in your code and below your columns - graph papaer is good for this).

Are things working the way you planned?
[ November 20, 2004: Message edited by: Elouise Kivineva ]
Max Labaio-Burreal
Greenhorn

Joined: Nov 23, 2004
Posts: 3
Hey sorry im a newbie, i havent as much knowledge as others in the site, well i just wanted to say when you install your JDK doesnt it give you info if there are errors on your site?
also can i get help like tutorials from someone here?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Max Labaio-Burreal:
Hey sorry im a newbie, i havent as much knowledge as others in the site, well i just wanted to say when you install your JDK doesnt it give you info if there are errors on your site?
also can i get help like tutorials from someone here?

If this is a new question, you should click "Post a New Topic" to start your own thread.

Layne


Java API Documentation
The Java Tutorial
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by del barton:

... will not calculate the right number of letter grades
what am I doing wrong ?
please help Thank you.

Have you tried running through your code by hand? What I mean is that you should make a table with all of your variables. Step through the code one line at a time and determine what value that gives to the variables used in that line. Perhaps that will give you an idea of what your program is actually doing. It should also help you see what needs to be fixed to get it working.

HTH

Layne
 
Don't get me started about those stupid light bulbs.
 
subject: need help please?
 
Similar Threads
newbie question
Test score
What is he saying?
Grading Program--Need help, please!!!
Highest/Lowest output from integer input (Beginner)