I've been searching every where but couldn't find an answer.
I'm trying to make an ArrayList to store 10 grades in a user defined class so I can then call it in the Client class and input the grades with a Scanner(System.in) and then output them all together but I don't know if its possible to do it and I've searched everywhere for an answer. Please Help.
This is what I have so far of my user defined class
import java.util.ArrayList;
public class Student {
private String student;
private String courseName;
private double grade;
private double avg;
private double total;
private double max;
private double min;
//Constructor w/o arguments
public Student() {
this.student = "";
this.courseName = "";
this.grade = 0.0;
}
//Constructor with arguments
public Student(String student, String courseName, double grade, double avg, double total, double max, double min) {
this.student = student;
this.courseName = courseName;
this.grade = grade;
}
//Getters
public String getStudent(){
return this.student;
}
public String getCourseName() {
return this.courseName;
}
//Setters
public void setStudent(String student) {
this.student = student;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
//Returns average off the 10 grades
public double calculateAvg() {
total += grade; //add all grades for average
avg = total / 10;
return avg;
}
//Highest Grade
public double highGrade() {
return max = Math.max(grade, max);
}
//Lowest Grade
public double lowGrade() {
return min = Math.min(grade, min);
}
ArrayList<Student>listGrades = new ArrayList<Student>();
List<Student> listGrades = new ArrayList<>();would work too, java does not need the type specification in the second part (at least not in newer versions). You can do the same with doubles.