Connecting Tech Pros Worldwide Forums | Help | Site Map

Almost got it, need just a little help with this java grader program to output correc

Newbie
 
Join Date: Sep 2006
Posts: 16
#1: Nov 2 '06
This program is supposed to calculate the number of grades entered and also how many a's, b's, c's, d's, and f's are entered. I have the number of grades part right but can't figure out how to fix my code to make it output the correct number of each letter grade. Can someone please look at my code and tell me where I messed up? I appreciate all help I can get. Thanks!

Here is my code:

import java.util.*;

public class Grades
{
public static void main(String[] args )
{
int numberofstudents,score;
double next;
char grade;
String answer;


do
{
System.out.println("Enter scores for all students.");
System.out.println("Enter a negative one after");
System.out.println("you have entered all the scores.");
Scanner keyboard = new Scanner(System.in);

numberofstudents = 0;
score = 0;
grade=0;
next = keyboard.nextDouble();
while (next >=0)
{
numberofstudents++;
next = keyboard.nextDouble();
}
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 = keyboard.next();
}while (answer.equalsIgnoreCase("y"));
}
}

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Nov 3 '06

re: Almost got it, need just a little help with this java grader program to output correc


Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class Grades
  4. {
  5. public static void main(String[] args )
  6. {
  7. int numberofstudents,score;
  8. double next;
  9. char grade;
  10. String answer;
  11.  
  12.  
  13. do
  14. {
  15. System.out.println("Enter scores for all students.");
  16. System.out.println("Enter a negative one after");
  17. System.out.println("you have entered all the scores.");
  18. Scanner keyboard = new Scanner(System.in);
  19.  
  20. numberofstudents = 0;
  21. score = 0;
  22. grade=0;
  23.  
  24. //Or maybe you could an array here
  25. int a = 0;
  26. int b = 0;
  27. int c = 0;
  28. int d = 0;
  29. int f = 0;
  30.  
  31. next = keyboard.nextDouble();
  32. while (next >=0)
  33. {
  34.     numberofstudents++;
  35.     //next = keyboard.nextDouble();
  36.     //numberofstudents = grade;
  37.     //Process the data as it is being entered
  38.     if (next >= 90){
  39.     //grade ='A';
  40.     a++;
  41.     }
  42.     else if (next >= 80){
  43.     //grade ='B';
  44.     b++;
  45.     }
  46.     else if (next >= 70){
  47.     //grade ='C';
  48.     c++;
  49.     }
  50.     else if (next >= 60){
  51.     //grade ='D';
  52.     d++;
  53.     }
  54.     else if (next < 60){
  55.     //grade ='F';
  56.     f++;
  57.     }
  58.     next = keyboard.nextDouble();
  59. }
  60.  
  61. if (numberofstudents > 0) {
  62. System.out.println("Total number of grades " + (numberofstudents));
  63.  
  64.  
  65. System.out.println("Number of A's = " + a);
  66. System.out.println("Number of B's = " + b);
  67. System.out.println("Number of C's = " + c);
  68. System.out.println("Number of D's = " + d);
  69. System.out.println("Number of F's = " + f);
  70. }
  71.  
  72. System.out.println("Want to score another exam?");
  73. System.out.println("Enter y for yes or n for no.");
  74. answer = keyboard.next();
  75. }while (answer.equalsIgnoreCase("y"));
  76. }
  77. }
Reply