다음은 코드입니다. 코드는 arraylist의 관련 데이터가있는 학생 목록을 반환해야합니다. 하지만 오류가 정적이 아닌 메서드에 대한 정적 참조를 만들 수 없다는 것을 말하고 있습니까 ??클래스의 Java에서 ArrayList 값을 반환하는 방법
메서드를 정적으로 만들려고했는데 다른 오류가 발생합니다.
//main function code
String forename = null;
String surname = null;
String grade = null;
String yesOrNo;
double mark;
int selection;
ArrayList<StudentClass> studentDetails = new ArrayList<StudentClass>();
switch(selection){
case 1: {
if (studentDetails.isEmpty()){
System.out.println("No Students Have Been Entered Yet");
main(null);
break;
}
else{
for(int i = 0; i < studentDetails.size(); i++){
StudentClass = studentDetails.get(i);
System.out.println(StudentClass.getForename() + " " +
StudentClass.getSurname() + " received a " + StudentClass.getGrade() +
" for their Student Mark of " + StudentClass.getMark() + ".");
}
}
break;
\\ Error:Exception in thread "main" java.lang.Error: Unresolved compilation problems:
StudentClass cannot be resolved to a variable
Cannot make a static reference to the non-static method getForename() from the type StudentClass
Cannot make a static reference to the non-static method getSurname() from the type StudentClass
Cannot make a static reference to the non-static method getGrade() from the type StudentClass
Cannot make a static reference to the non-static method getMark() from the type StudentClass
at students.main(students.java:60)
\\code for Class
public class StudentClass {
public String Forename;
public String Surname;
public String Grade;
public double Mark;
public StudentClass(String forename, String surname, double mark){
Forename = forename;
Surname = surname;
Mark = mark;
}
public void setForename(String forename)
{
Forename= forename;
}
public void setSurname(String surname)
{
Surname= surname;
}
public void setMark(double mark)
{
Mark= mark;
}
public String getForename()
{
return Forename;
}
public String getSurname()
{
return Surname;
}
public double getMark()
{
return Mark;
}
public String getGrade()
{
if (Mark < 40)
Grade = "FAIL";
else if ((Mark >= 40) && (Mark <= 64))
Grade ="PASS";
else if ((Mark >= 65) && (Mark <= 84))
Grade ="MERIT";
else if ((Mark >= 85) && (Mark <= 100))
Grade ="DISTINCTION";
return Grade;
}
}