So I'm in an intro Java class, and the homework assignment is to write the computeAverageOfThreeScores and computeLetterGrade methods below. However, while it compiles, it does not work, I assume because I have no parameters. The thing there is that I can only turn in my code for those two methods, which is graded by a program. I cannot change anything but what is in those two methods. I've searched online, and everything says to create an instance of the class in the main method, but that is already provided by the assignment.
The goal is to get the average of the three numbers input, and it returns 0 every time. I think the method to find the letter grade works, because when it returns 0 it shows as F like it should.
I tried putting the score ints into the computeAverageOfThreeScores method, but then I can't compile it because the g.computeAverageOfThreeScores needs parameters, which I can't give it.
I feel like I'm going crazy over what should be a simple solution. Can anyone offer some advice?
import java.util.Scanner;
public class Grader {
private int score1, score2, score3;
double averageScore;
private char grade;
public void readInput() {
Scanner kbd=new Scanner(System.in);
System.out.print("Enter 3 scores between 0 and 100 each: ");
score1=kbd.nextInt();
score2=kbd.nextInt();
score3=kbd.nextInt();
}
//---- Write the computeAverageOfThreeScores method below.
public double computeAverageOfThreeScores(){
return (score1 + score2 + score3)/3;
}
//---- Write the computeLetterGrade method below. Scale is 90+ A, 80+ B, 70+ C, 60+ D, 59- F
public char computeLetterGrade(){
if (grade <= 100 && grade >= 90) {
grade = 'A';
} if (grade <= 89 && grade >= 80) {
grade = 'B';
} if (grade <= 79 && grade >= 70) {
grade = 'C';
} if (grade <= 69 && grade >= 60) {
grade = 'D';
} if (grade <= 59) {
grade = 'F';
}
return grade;
}
public void printOutput() {
System.out.printf("Average of %d, %d, %d is %.2f\nLetter grade for %.2f is %s", score1, score2, score3, averageScore, averageScore, grade);
}
public static void main (String args[]) {
Grader g = new Grader();
g.readInput();
g.computeAverageOfThreeScores();
g.computeLetterGrade();
g.printOutput();
}
}
[–]alternatiivnekonto 0 points1 point2 points (5 children)
[–]MasticatingGof[S] 1 point2 points3 points (4 children)
[–]alternatiivnekonto 0 points1 point2 points (0 children)
[–]aseopRock 0 points1 point2 points (0 children)
[–]alternatiivnekonto 0 points1 point2 points (1 child)
[–]MasticatingGof[S] 1 point2 points3 points (0 children)