U
U
up72019-12-26 10:09:59
Java
up7, 2019-12-26 10:09:59

How can I make multiple grades for the Student class?

There is a task.

Create class Student. The grades received by students in a session are attributes of the Student class. Determine:
....
b) the average score of each student;

d) the number of students who have "2".
..........

In general, the usual OOP task, but it is not clear how to store multiple ratings? sketched out the code

public class Student {
    private int mark;

  public void setMark(int mark) {
    this.mark = mark;
  }
    
  public int getMark() {
     return this.mark;
  } 
}


However, when a class is instantiated, only one evaluation is created. Make fields for each item? Same thing - only one estimate will fit. Or accept arrays as input? That is, create a constructor with arrays? However, how then for arrays to get and set values? also getters and setters?

Tell me please. With an example, if possible.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2019-12-26
@up7

public class Student {
    private List<Integer> marks = new ArrayList<>();

    public void addMark(int mark) {
        this.marks.add(mark);
    }

    public List<Integer> getMarks() {
        return marks;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question