File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help please?

 
del barton
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic