The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

gradebook

Hey guys new to the forum and im a beginner with java and I need to write a basic gradebook program. Part of our assignment is to
"Add the following method header outside your main method, but still inside your GradeBook class:
public static char calculateGrade(double score) { }
The body of this method will perform the task of translating a numeric value into a letter grade. To accomplish this task, the method accepts a double value, representing a single score, and returns a char value of either A, B, C, D or F. Within the method body, you will need to use a nested selection statement, like the one shown on page 82 of the 10th Edition textbook.
The calculateGrade() method should be invoked AFTER the user inputs a score. Following the invocation of calculateGrade(), the program should output a message like The score 72.0 is a C for every score that is entered. Because calculateGrade() returns a char value, a switch can be used to print this output message."

System.out.println ("Enter a grade between 0 and 100 and type -1 when you are finished.");

do{

grade=keyboard.nextInt();

if(grade !=-1){

sum= sum + grade;

}

if(grade >= 0.0){
numberofgrades++;

if(grade>=90.0 && grade <= 100.0){

A++;

}
if(grade>=80.0 && grade <= 89.9){

B++;

}

if(grade>=70.0 && grade <= 79.9){

C++;

}

if(grade>=60.0 && grade <= 69.9){

D++;

}

else if(grade>=0.0 && grade <= 59.9){

F++;
}

}

}

while (grade >= 0.0);

avg= sum/ numberofgrades;
System.out.println("Total number of grades is "+ numberofgrades);
System.out.println("Total number of A's is "+A);
System.out.println("Total number of B's is "+B);
System.out.println("Total number of C's is "+C);
System.out.println("Total number of D's is "+D);
System.out.println("Total number of F's is "+F);
System.out.println("Average score is "+ avg);

Re: gradebook

Looks like you need to make a class called GradeBook and inside that class make the calculateGrade() method. it should take in a double as a parameter. Like calculateGrade(double grade){} then you want your grade selection code that you have in your main method in that method, but instead of increment the amount of people who received that grade, instead System.out.println("The score " + grade + " is a C"); But instead of just C, put whatever grade falls under the proper selection. It can also increment the amount of grades recieved like you already have. Then in your main method you could set grade = 0, then

The calculateGrade(grade) will then print out a message saying what grade that score is and increment the grade counter. You should also put a check in calculateGrade to make it exit if grade == -1 in order for the while loop i said to work. If they entered -1 calculateGrade() would exit, then it would go to beginning of while loop and be like "oop! we are done!" then carry on with the rest of your main method.

Re: gradebook

Hello. I don't understand what all this is for:

avg= sum/ numberofgrades;
System.out.println("Total number of grades is "+ numberofgrades);
System.out.println("Total number of A's is "+A);
System.out.println("Total number of B's is "+B);
System.out.println("Total number of C's is "+C);
System.out.println("Total number of D's is "+D);
System.out.println("Total number of F's is "+F);
System.out.println("Average score is "+ avg);

The assignment did not ask for you to do that. From my understanding of your assignment, all it asked you to do was to check if the score you inputted is a A or B or C or D or F. The method that is used to check the score has to be called from the main method, so it would make sense for you to do something like Bawnawgwa said.

This part of the code should go into the static method (calculateGrade).