본문으로 바로가기

성적 관리 프로그램

category JAVA 2018. 4. 12. 01:23

 

 

 

JAVA

Vector / Genetic

 

성적관리 프로 그램  

 

미와성:클래스를 따로 나눠 주는 역할을 하지 못했습니다...........

 코드가 좀더 가벼워 보일수있게  여러분들이 클래스를 따로 나눠 주세용~~~!!

 

 

 

 

 

 

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package Test;
 
import java.util.Scanner;
import java.util.*;
 
class Student {
    private String name;
    private int kor, eng, math;
    private int sum;
    private double avg;
    
    public Student() {}
    
    public Student(String name, int kor, int eng, int math) {
        this.name = name;
        this.kor = kor;
        this.eng = eng;
        this.math = math;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public int getKor() {
        return kor;
    }
    public void setKor(int kor) {
        this.kor = kor;
    }
    public int getEng() {
        return eng;
    }
    public void setEng(int eng) {
        this.eng = eng;
    }
    public int getMath() {
        return math;
    }
    public void setMath(int math) {
        this.math = math;
    }
    public int getSum() {
        sum = getKor()+getEng()+getMath();
        return sum;
    }
    public double getAvg() {
        avg = sum / 3.0;
        return avg;
    }
    public String toString() {
        return "이름 : "+this.getName()+" 국어 : "+this.getKor()+" 영어 : "+this.getEng()+" 수학 : "+this.getMath()+" 총점 : "+this.getSum()+" 평균 : "+this.getAvg();
    }
}
 
public class School {
    int num;
    String who;
    Scanner sc = new Scanner(System.in);
    List<Student> score = new Vector<Student>();
    Student stu;
    Iterator<Student> it = score.iterator();
    
    public void input() {
        stu = new Student();
        System.out.print("이름 입력 : ");
        stu.setName(sc.next());
        System.out.print("국어점수 입력 : ");
        stu.setKor(sc.nextInt());
        System.out.print("영어점수 입력 : ");
        stu.setEng(sc.nextInt());
        System.out.print("수학점수 입력 : ");
        stu.setMath(sc.nextInt());
        stu.getSum();
        stu.getAvg();
        
        score.add(stu);
    }
    
    public void disp() {
        for(Student s:score) {
            System.out.println(s);
        }
    }
    
    public void search() {
        System.out.print("검색할 사람의 이름은? : ");
        who = sc.next();
        it = score.iterator();
        while (it.hasNext()) {
            Student stu = it.next();
            if (stu.getName().equals(who)) {
                System.out.println(stu);
            }
        }
    }
    
    public void overwrite() {
        System.out.print("수정할 사람의 이름은? : ");
        who = sc.next();
        it = score.iterator();
        while (it.hasNext()) {
            Student stu = it.next();
            if (stu.getName().equals(who)) {
                System.out.print("수정할 정보는? 1.국어  2.영어  3.수학 : ");
                num = sc.nextInt();
                if(num==1) {
                    System.out.print("국어점수 입력 : ");
                    stu.setKor(sc.nextInt());
                }
                else if(num==2) {
                    System.out.print("영어점수 입력 : ");
                    stu.setEng(sc.nextInt());
                }
                else if(num==3) {
                    System.out.print("수학점수 입력 : ");
                    stu.setMath(sc.nextInt());
                }
                else
                    System.out.println("잘못된 입력입니다.");
            }
        }
    }
    
    public void delete() {
        System.out.print("삭제할 사람의 이름은? : ");
        who = sc.next();
        for(int i=0; i<score.size(); i++) {
            if(score.get(i).getName().equals(who)) {
                score.remove(i);
            }
        }
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        School sch = new School();
        
        int num2=0;
        
        while(num2 != 6) {
            System.out.println("--------------------");
            System.out.println("| 1. 추가                     |");
            System.out.println("| 2. 출력                     |");
            System.out.println("| 3. 검색                     |");
            System.out.println("| 4. 수정                     |");
            System.out.println("| 5. 삭제                     |");
            System.out.println("| 6. 종료                     |");
            System.out.println("--------------------");
            
            System.out.print("무엇을 하시겠습니까? 성규야? : ");
            num2 = sc.nextInt();
            
            switch(num2) {
            case 1:
                sch.input();
                break;
            case 2:
                sch.disp();
                break;
            case 3:
                sch.search();
                break;
            case 4:
                sch.overwrite();
                break;
            case 5:
                sch.delete();
                break;
            case 6:
                System.out.println("종료!!");
                return;
            }
        }
        
    }
 
}
 
cs

'JAVA' 카테고리의 다른 글

[JAVA][절대경로와 상대경로]  (0) 2018.04.16
[JAVA][ 성적관리 프로 그램]  (0) 2018.04.13
AVL트리 vs 편향트리  (0) 2018.03.27
[JAVA][래퍼클래스]  (0) 2018.03.22
[JAVA][Stack / Queue]  (1) 2018.03.21