package chapter20230809;
import java.util.*;
public class test12 {
static boolean run = true;
static int studentNum = 0;
static int[] scores = null;
static int max = 0;
static int average = 0;
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
while (run) {
System.out.println("-----------------------------------------------------");
System.out.println("1.학생수 | 2.점수입력 | 3.점수리스트 | 4.분석 | 5.종료");
System.out.println("-----------------------------------------------------");
System.out.print("선택> ");
int selectNo = scanner.nextInt();
if (selectNo == 1) {
inputStudentNum(); {
}
} else if (selectNo == 2) {
inputScores();
} else if (selectNo == 3) {
printScores();
} else if (selectNo == 4) {
printAnalysis();
} else if (selectNo == 5) {
setRun();
}
}
System.out.println("프로그램 종료");
}
public static void inputStudentNum() {
System.out.print("학생수> ");
studentNum = scanner.nextInt();
scores = new int [studentNum];
}
public static void inputScores() {
for(int i = 0; i < scores.length; i++) {
System.out.print("각 학생 점수> ");
scores[i] = scanner.nextInt();
}
}
public static void printScores() {
for(int i = 0; i < scores.length; i++) {
System.out.println("학생" +"["+ i +"] "+ scores[i]);
}
}
public static void printAnalysis() {
for(int i = 0; i < scores.length; i++) {
max = scores[i] > max ? scores[i] : max;
average += scores[i];
}
System.out.println("최고 점수는 " + max + " 이며" + " 평균 점수는 " + (double)average/studentNum + " 입니다.");
}
public static void setRun() {
run = false;
}
}