class Student {
String name;
int no, kor, eng, tot, avg, rank;
char grade;

Student(int no , String name, int kor, int eng) {
this.no = no;
this.name = name;
this.kor = kor;
this.eng = eng;
}

}

public class Sungjuk_v3 {
java.util.Scanner scan = new java.util.Scanner(System.in);
Student[] input = new Student[3];
void Input(){
for(int i=0; i<input.length; i++){
System.out.println("학번입력");
int no = scan.nextInt();
System.out.println("이름입력");
String name = scan.next();
System.out.println("국어점수입력");
int kor = scan.nextInt();
System.out.println("영어점수입력");
int eng = scan.nextInt();
input[i] = new Student(no,name,kor,eng);
}
for(int i=0; i<input.length; i++){
input[i].tot = input[i].kor + input[i].eng;
input[i].avg = input[i].tot/2;
if(input[i].avg>=90){
input[i].grade = 'A';
}else if(input[i].avg>=80){
input[i].grade = 'B';
}else if(input[i].avg >=70){
input[i].grade = 'C';
}else if(input[i].avg >=60){
input[i].grade = 'D';
}else{
input[i].grade = 'F';
}
}
for(int row = 0; row<input.length; row++){
input[row].rank = 1;
for(int col =0; col<input.length; col++){
if(input[row].avg<input[col].avg){
input[row].rank++;
}
}
}
System.out.println("====================성적표====================");
} //void Input
public void Display(){
System.out.println("학번 \t이름\t국어\t영어\t총점\t평균\t등급\t등수");
for (int cnt = 0; cnt < input.length; cnt++) {
System.out.println(input[cnt].no + "\t" + input[cnt].name + "\t" + input[cnt].kor + "\t"
+ input[cnt].eng + "\t" + input[cnt].tot + "\t" + input[cnt].avg + "\t" + input[cnt].grade
+ "\t " + input[cnt].rank);

}
}
public void Sort(){
for (int row = 0; row < input.length - 1; row++) {
for (int col = row + 1; col < input.length; col++) {
if (input[row].rank > input[col].rank) {

Student sTemp = input[row];
input[row] = input[col];
input[col] = sTemp;

}

}
}
System.out.println("===============정렬된 성적표=================");
}
public static void main(String[] args) {
Sungjuk_v3 sug = new Sungjuk_v3();
sug.Input();
sug.Display();
sug.Sort();
sug.Display();
}

}


'Java' 카테고리의 다른 글

[과제] Windows Event를 이용한 신호등 예제  (0) 2017.06.26
[과제] 로또 번호  (0) 2017.06.26
[JAVA 정리] 18. 네트워크  (0) 2017.06.24
[JAVA 정리] 17. Windows Programming  (0) 2017.06.24
[JAVA 정리] 16. Thread  (0) 2017.06.24

+ Recent posts