자바(Java) 정렬 질문
-
게시물 수정 , 삭제는 로그인 필요
Model.java
public class Model{
public ArrayList studentList;
studentlist = new ArrayList();
for(int i=0; i<5; i++){
Student a = new Student();
studentList.add(a);
}
}
Student.java
public class Student{
public int math;
public int korean;
public int english;
public Student(){
math = (int)(Math.random()*100) ;
korean = (int)(Math.random()*100) ;
english = (int)(Math.random()*100) ;
}
프로그램은 대강 이렇습니다.
이렇게 짜면 studentList 에 순서대로 student 1, student 2,...., student 5 이렇게 들어갈텐데요.
여기서 student는 수학, 국어, 영어 점수를 가지게 됩니다.
그런데 여기서 이 랜덤하게 생성된 점수를 가지고
수학 성적 순으로 정렬을 해서,
수학 성적이 가장 높은 학생이 studentlist에서 가장 첫 번째 자리를 차지하게 하고,
그 다음 사람이 studentlist의 2번째, 이렇게 정렬하고 싶습니다.
알려주세요~~!
Model.java
public class Model{
public ArrayList studentList;
studentlist = new ArrayList();
for(int i=0; i<5; i++){
Student a = new Student();
studentList.add(a);
}
}
Student.java
public class Student{
public int math;
public int korean;
public int english;
public Student(){
math = (int)(Math.random()*100) ;
korean = (int)(Math.random()*100) ;
english = (int)(Math.random()*100) ;
}
프로그램은 대강 이렇습니다.
이렇게 짜면 studentList 에 순서대로 student 1, student 2,...., student 5 이렇게 들어갈텐데요.
여기서 student는 수학, 국어, 영어 점수를 가지게 됩니다.
그런데 여기서 이 랜덤하게 생성된 점수를 가지고
수학 성적 순으로 정렬을 해서,
수학 성적이 가장 높은 학생이 studentlist에서 가장 첫 번째 자리를 차지하게 하고,
그 다음 사람이 studentlist의 2번째, 이렇게 정렬하고 싶습니다.
알려주세요~~!