public class studentManagerment {
Student [] list = new Student[100];
int index = 0;
// check group
public boolean sameGroup(Student s1, Student s2){
if (s1.getGroup().equals(s2.getGroup()) ) return true;
else return false;
}
// them student
public void addStudent(Student newStudent){
list[index] = newStudent;
this.index++;
System.out.println();
}
//Sap xep
public String studentByGroup(){
String listStudent = "";
for (int i=0;i<index-1;i++)
for (int j=0;j<index-1;j++) {
if (list[j].getGroup().compareTo(list[j+1].getGroup()) < 0){
Student temp = list[j];
list[j] = list [j+1];
list[j+1] = temp;
}
}
for (int i=0;i<index;i++){
if (i==0||!sameGroup(list[i],list[i-1])){
listStudent += list[i].getGroup() + "\n";
}
listStudent += list[i].getinfo() + "n";
}
return listStudent;
}
public void removeStudent(String id){
Student[] students = new Student[100];
int k = 0;
for (int i=0;i<index;i++){
if (list[i].getId().equals(id)){
students[k] = list[i];
k++;
}
}
list = students.clone();
index--;
}
public static void main(String[] args){
Student s1 = new Student("Nguyen Van B","17021000","K63AA");
addStudent(s1);
}
}
Lỗi
Error:(59, 9) java: non-static method addStudent(com.company.Student) cannot be referenced
from a static context