0
I have an exercise on vetores/array
with simple value, where I must correct a test, comparing it with the feedback and also calculate the percentage of students who reached the average.
6) Make a program to correct multiple choice tests. Each test has eight questions and each question is worth one point. The first data set to be read is the proof template. The others are the student numbers and the answers they gave to the questions. There are ten enrolled students. Calculate and show:
a. The number and grade of each student;
b. The approval percentage knowing that the minimum grade is 6.
My feedback will be declared right at the beginning, ie I have an arrayinstanciada already with the "answers"
The teacher provided an image as she intended the exercise to run
My code at the moment is :
import java.util.Scanner;
public class ExercicioVetor6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int arrayAluno[] = new int[10];
String[] gabarito = new String[] {"b", "d", "e", "a", "b", "c", "b", "a"};
String resposta;
int nota = 0;
for (int i = 0; i < 10; i ++) {
System.out.println("--- aluno " + (i+1) + " ---");
for (int j = 0; j < 8; j++) {
System.out.println("digite a resposta da " + (j+1) + " questão");
resposta = scan.next();
if (resposta.equals(gabarito[j]) ) {
nota++;
}
}
System.out.println("A nota do aluno " + (i+1) + " é : " + nota);
nota = 0;
}
}
}
But by the teacher’s exercise she wants me to keep the answers of the students, then the program will ask the number of the desired student,compare the answers and finally I must provide the percentage of students with average of 6 up! When I run the code it repeats 10 times so I can type in the students' answers,!
But I believe something is missing, I don’t know what to do to look like the image!
Array array, and each position of the student vector, Voce will need to store another vector, which is the 8 answers given by it. Although it is not very simple nor "elegant" to do this. Are you sure it is necessary to store notes from each student? By the content of the exercise, it is completely discardable to do this.
– user28595
now I’m more confused.. how will I do Array of Array?
– Carol M
"But I believe something is missing" Did it get confusing, believe or miss? : ) If you need to save the students' answer, a 10 position array will only allow you to have a student’s data. Have you used a two-dimensional array? Would that be:
int[][] arrayAluno= new int[10][8]
I mean, it supports 10 students with 8 grades each, so I was going to be able to save everything and calculate it as I want later. To save the data can simply be like this:arrayAluno[i][j] = scan.next()
, see if you can understand the logic, otherwise I give more details– Ricardo Pontual
Ricardo is missing something.. because I haven’t finished the exercise since I couldn’t even ask the user to enter the student’s number
– Carol M
Ricardo and me use a simple array? Faria an arrayAluno = new int[10] and a Abarito[8] ?
– Carol M
I insist that it is completely unnecessary to store the grade of each student to know the average of approved and the grade of each one. The exercise does not say at any time that one should store this.
– user28595
Articuno, even if the exercise asks me to type in the student I want to see the notes I don’t need an array to store the notes?
– Carol M
No, no need, the exercise says that are data "to be read", unless your teacher has asked orally that you store, the exercise does not ask for it. You can display the student and his grade immediately after checking his test feedback, following next time, and repeating the same procedure. At the end is that you will take the amount of students with grades above 6 hits and calculate the percentage. But still, it would not be necessary to know more the grade, and yes, how many students were approved.
– user28595
and how do I get the program to ask me to type in the student number and display the grades? just with a System.out.println ?
– Carol M
If you do it this way, with an array it will look very dirty, because you will either need 2 different arrays to store the student’s number and another one of his notes, or an array like Ricardo mentioned, however, with an extra input in the innermost array, to store the student’s number, something like
arrayAluno[10][9]
.There is no way out of this, with simple array it would sound like dirty code, or gambit.– user28595
I plead for what the staff said now in Ala the teacher that the notes are stored
– Carol M
Note only? Don’t need to store every question answered by every student, correct?
– user28595
That just the note
– Carol M
Create a two-dimensional student array, as we have explained, only instead of
[10][8]
, do[10][2]
, where you will keep in each of the 10 positions, the student number and your grade.– user28595
thanks for the help
– Carol M