ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 7. oop2 - (7) StudentDemo (학생 정보 관리 프로그램)
    java/코드 리뷰 2020. 3. 24. 16:10
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    package oop2;
     
    public class Student {
        String name;
        int ban;
        int no;
        int kor;
        int eng;
        int math;
        
        int getTotalScore() {
            return kor + eng + math;
        }
        
        int getAverage() {
            int totalScore = getTotalScore();
            return totalScore/3;
        }
        
        void displayStudentInfo() {
            System.out.println("ㅡㅡㅡㅡㅡ 학생 정보ㅡㅡㅡㅡㅡ");
            System.out.println("학생이름 : " + name);
            System.out.println("반 : " + ban);
            System.out.println("번호 : " + no);
            System.out.println("국어점수 : " + kor);
            System.out.println("영어점수 : " + eng);
            System.out.println("수학점수 : " + math);
            System.out.println("총점: " + getTotalScore());
            System.out.println("평균 : " + getAverage());
            System.out.println("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ");
            
        }
        
        void displayStudentsInfoRow() {
            System.out.print(name + "\t");
            System.out.print(ban + "\t");
            System.out.print(no + "\t");
            System.out.print(kor + "\t");
            System.out.print(eng + "\t");
            System.out.print(math + "\t");
            System.out.print(getTotalScore() + "\t");
            System.out.println(getAverage());
            
        }
        
    }
     

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    package oop2;
     
    import java.util.Scanner;
     
    public class StudentDemo {
        public static void main(String[] args) {
            
            Scanner sc = new Scanner(System.in);
            Student[] students = new Student[100];
            int savePosition = 0;
     
            while (true) {
                System.out.println();
                System.out.println("[학생 정보 관리 프로그램]");
                System.out.println("======================================");
                System.out.println("1.조회    2.검색    3.입력    0.종료");
                System.out.println("======================================");
                
                System.out.print("메뉴를 선택하세요 : ");
                int menuNo = sc.nextInt();
     
                if (menuNo == 1) {
                    System.out.println("[학생정보 조회]");
                    System.out.println("이름    반    번호    국어    영어    수학    총점    평균");
                    System.out.println("============================================================");
                    
                    for (int i=0; i<savePosition; i++) {
                        Student student = students[i];
                        student.displayStudentsInfoRow();
                    }
                    
                    System.out.println("============================================================");
                    
                } else if (menuNo == 2) {
                    System.out.println("[학생정보 검색]");
                    System.out.print("검색할 이름을 입력하세요 : ");
                    String searchName = sc.next();
                    
                    boolean isFound = false;
                    for (int i=0; i<savePosition; i++) {
                        Student student = students[i];
                        if(searchName.equals(student.name)) {
                            student.displayStudentInfo();
                            isFound = true;
                        }
                    }
                    
                    if (!isFound) {
                        System.out.println("입력한 이름과 일치하는 정보를 찾을 수 없습니다.");
                    }
                                
                } else if (menuNo == 3) {
                    System.out.println("[학생정보 입력]");
                    System.out.print("이름을 입력하세요 : ");
                    String name = sc.next();
                    System.out.print("반을 입력하세요 : ");
                    int ban = sc.nextInt();
                    System.out.print("번호를 입력하세요 : ");
                    int no = sc.nextInt();
                    System.out.print("국어점수를 입력하세요 : ");
                    int kor = sc.nextInt();
                    System.out.print("영어점수를 입력하세요 : ");
                    int eng = sc.nextInt();
                    System.out.print("수학점수를 입력하세요 : ");
                    int math = sc.nextInt();
                    
                    Student student = new Student();
                    
                    student.name = name;
                    student.ban = ban;
                    student.no = no;
                    student.kor = kor;
                    student.eng = eng;
                    student.math = math;
                    
                    students[savePosition] = student;
                    savePosition++;
                    
                } else if (menuNo == 0) {
                    System.out.println();
                    System.out.println("[프로그램 종료]");
                    break;
                }
                
                sc.close();
            }
        }
    }
     

     

Designed by Tistory.