Reputation: 1
public static double[] displayGrades() {
Scanner input = new Scanner(System.in);
int students =12;
int questions = 10;
double correct =1.5;
double wrong = 0.5;
int[][]answers = {{3,4,2,5,0,2,1,3,2,4},{0,0,2,1,5,4,1,2,3,1},{3,3,2,5,4,1,2,5,0,3},{3,4,4,5,3,5,4,0,3,1},{3,4,2,5,4,3,1,2,3,2},{1,3,4,3,2,5,4,2,1,0},{2,0,3,4,2,0,1,5,4,2},{3,4,5,3,3,2,4,1,2,5},{3,5,3,5,1,2,3,4,5,6,0},{3,4,5,3,4,3,0,0,0,0},{3,4,5,2,1,2,3,2,5,3},{3,2,1,5,5,3,2,5,2,4}};
int[] correctA = {3,4,2,5,4,3,1,2,3,1};
double score [] = new double [students];
for (int i =0; i<students ; i++) {
for (int j=0; j<questions; j++) {
if (answers[i][j] ==correctA[j])
score[i] += correct;
else if (answers[i][j] != 0)
score[i] -= wrong;
}
}
return score;
}
public static void main(String[] args) {
displayGrades(score);
int[]id= {1,1,1,2,2,2,3,3,3,4,4,4};
System.out.printf("%s \t%s", "Student Group", "Score" );
for(int i=0; i<students; i++)
System.out.printf("\n %d \t\t%.2f", id[i], score[i] );
}
I'm new to Java, and I can't work this one out. Main method doesn't recognize the score
array and students
variable. I can't print them out. I have to do it with two methods according to my homework. Can somebody help?
Upvotes: 0
Views: 41
Reputation: 12819
displayGrades()
is a method that accepts no arguments, but you are trying to pass scores
to it. Also you haven't defined scores
I think what you wanted to do was:
double[] scores = displayGrades();
This will resolve the results of displayGrades()
to the double
array scores
Also instead of for(int i=0; i<students; i++)
, you could loop until scores.length
(Under the assumption that students == scores.length
. I.e. there are as many scores as students)
Upvotes: 2