on
1021 - 성적표 만들기02 Review
1021 - 성적표 만들기02 Review
import java.util.Scanner; public class Ex03GradeBook02 { public static void main(String[] args) { // 상수 // 1. 최대 관리 가능한 학생수 final int STUDENT_SIZE = 5; // 2. 가능한 최저점수 final int SCORE_MIN = 0; // 3. 가능한 최고점수 final int SCORE_MAX = 100; // 4. 관리하는 과목수 final int SUBJECT_SIZE = 3; // 변수 Scanner scanner = new Scanner(System.in); int[] idArray = new int[STUDENT_SIZE]; String[] nameArray = new String[STUDENT_SIZE]; int[] koreanArray = new int[STUDENT_SIZE]; int[] englishArray = new int[STUDENT_SIZE]; int[] mathArray = new int[STUDENT_SIZE]; // 다음 입력을 저장할 int 변수 int nextIdx = 0; while(true) { System.out.println("1.입력 2.출력 3.종료"); System.out.print("> "); int userChoice = scanner.nextInt(); if(userChoice == 1) { // 입력 코드 구현 // 만약 다음 입력할 인덱스가 유효한 인덱스이면 입력을 실행하고 그러지 않으면 경고 메세지를 출력하자. if(nextIdx>=0 && nextIdx "); idArray[nextIdx] = scanner.nextInt(); System.out.println("이름을 입력해 주세요."); System.out.print("> "); scanner.nextLine(); nameArray[nextIdx] = scanner.nextLine(); System.out.println("국어점수를 입력해 주세요."); System.out.print("> "); koreanArray[nextIdx] = scanner.nextInt(); while(koreanArray[nextIdx]SCORE_MAX) { System.out.println("잘못 입력하셨습니다."); System.out.println("국어 점수를 입력해 주세요."); System.out.print("> "); koreanArray[nextIdx] = scanner.nextInt(); } System.out.println("영어점수를 입력해 주세요."); System.out.print("> "); englishArray[nextIdx] = scanner.nextInt(); while(englishArray[nextIdx]SCORE_MAX) { System.out.println("잘못 입력하셨습니다."); System.out.println("영어 점수를 입력해 주세요."); System.out.print("> "); englishArray[nextIdx] = scanner.nextInt(); } System.out.println("수학점수를 입력해 주세요."); System.out.print("> "); mathArray[nextIdx] = scanner.nextInt(); while(mathArray[nextIdx]SCORE_MAX) { System.out.println("잘못 입력하셨습니다."); System.out.println("수학 점수를 입력해 주세요."); System.out.print("> "); mathArray[nextIdx] = scanner.nextInt(); } nextIdx ++ ; } //4.만약 변경된 인덱스 값이 유효하지 않은 인덱스이면 경고 메세지만 출력한다. else { System.out.println("--------------------------------------"); System.out.println("더이상 입력하실 수 없습니다."); System.out.println("--------------------------------------"); } } else if(userChoice == 2) { // 아무것도 입력이 되어있지 않다면 nextIdx가 0보다 크면 출력을 하고 그렇지 않으면 경고 메세지를 출력한다. if(nextIdx>0) { for(int i=0 ; i
", idArray[i], nameArray[i]); System.out.printf("국어:%d점 영어:%d점 수학:%d점
", koreanArray[i], englishArray[i], mathArray[i]); System.out.printf("총점:%d점 평균:%.2f점
",sum, average); System.out.println("--------------------------------------"); } } //3.만약 입력 완료 인덱스가 0인 경우, 경고 메세지만 출력한다. else { System.out.println("--------------------------------------"); System.out.println("아직 입력된 학생이 존재하지 않습니다"); System.out.println("--------------------------------------"); } } else if(userChoice == 3) { System.out.println("사용해 주셔서 감사합니다."); break; } } scanner.close(); } }
공유하기 글 요소 저작자표시
from http://helloenavy.tistory.com/77 by ccl(A) rewrite - 2021-10-21 15:27:16