자바프로그래밍

3. 자바 성적처리 프로그램

제주도소년 2019. 10. 30. 15:12
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import java.util.Scanner;
 
public class Day1_1 {
 
 public static void main(String[] args)
    {
     @SuppressWarnings("resource")
  Scanner sc = new Scanner(System.in);
     
     double temp; // 평균을 계산하기 위해 임시로 선언한 공간
     
     boolean b = true//프로그램의 반복 여부
     
     String where;
     String [][] str; //2차원 배열의 할당
     String dataTemp;
     
     int i=0,j=0,choiceNumber=0, work=0;
     int NAME = 0//이름
     int KOR = 1//국어
     int ENG = 2//영어
     int MAT = 3//수학
     int SUM = 4//총점
     int AVG = 5//평균
     
     int index = 0//배열의 현 위치
     int dataCnt = 6// 데이터의 개수(이름,국어,영어,수학,총점,평균)
     //int dCount = 0;
     int stuCnt = 0//총 학생의 수
     int ko; //국어점수를 문자열에서 정수로 변환하기 위해 선언
     int en; //영어점수를 문자열에서 정수로 변환하기 위해 선언
     int ma; //수학점수를 문자열에서 정수로 변환하기 위해 선언
     
     // 배열의 크기를 입력받음
     System.out.print("사람 수 ? ");
     int num=sc.nextInt();
     sc.nextLine();
     
     str = new String[num][];
     
     do {
      System.out.println("1.정보 입력 \t2. 데이터 출력\t3.검색(성적)\t4.데이터 수정 \t5.데이터 삭제\t6.종료");
      work = sc.nextInt();
      sc.nextLine();    
      switch(work)
      {
       case 1
         if(num == stuCnt) 
         {
          System.out.println("더 이상 입력 할 수 없습니다");
          break;
         }
         //데이터 입력부분
         str[index] = new String[dataCnt];
         System.out.println(index+1+" 번째 학생의 정보 입력");
         for(i=0; i<dataCnt;i++)
            {
              if(i==SUM || i==AVG) break;
              
              dataTemp = sc.next();
              str[index][i] = dataTemp;
            }
         
         ko = Integer.parseInt(str[index][KOR]);
         en = Integer.parseInt(str[index][ENG]);
         ma = Integer.parseInt(str[index][MAT]);
         str[index][SUM] = Integer.toString(ko+en+ma);
         
         temp = Double.parseDouble(str[index][SUM]);
         temp /= 3;
         str[index][AVG] = Double.toString(temp);
         
            System.out.println(index+1+"번 째 사람 입력 완료");
            index++;
            stuCnt++;
            break;
       case 2:
        if(stuCnt == 0)
        {
         System.out.println("입력한 데이터가 없습니다");
         break
        }
         System.out.print("1.전체출력\t2.검색출력");
         choiceNumber = sc.nextInt();
         sc.nextLine();
         if(choiceNumber == 1
         {
          System.out.print("이름\t국어\t영어\t수학\t총점\t평균\n");
             for(i=0; i<stuCnt;i++)
             {
               for(j=0; j<dataCnt; j++)
               {
                if(str[i][j] == null)
                {
                 break;
                }
                else if(j==dataCnt-1)
                {
                 System.out.print(str[i][j]+"\t");
                 System.out.println();
                }
                else
                {
                 System.out.print(str[i][j]+"\t");
                }
               }
             }
            }
         else if(choiceNumber == 2) {
             ////////////////검색출력//////////////
             // 데이터 중 이름을 검색하여 해당하는 부분만 출력하는 기능
             System.out.print("검색할 사람의 이름을 입력해 주세요 :");
             where = sc.next();      
             for(i=0; i<stuCnt;i++)
             {
               if(where.equals(str[i][NAME]))
               {
                for(j=0; j<dataCnt; j++)
                   {
                 System.out.print(str[i][j]+"\t");
                   }
               }
             }
         }
         else
         {
          System.out.println("잘못 입력하였습니다.");
         }
            System.out.print("\n");
            break;
       case 3:
        if(stuCnt == 0)
        {
         System.out.println("입력한 데이터가 없습니다");
         break
        }
        // 데이터 중 점수를 검색하여 해당하는 부분만 출력하는 기능
           System.out.print("검색 할 총점을 입력해 주세요 :");
           where = sc.nextLine();
           int getSum = Integer.parseInt(where);
           int getValue;
           System.out.print("이름\t국어\t영어\t수학\t총점\t평균\n");
           for(i = 0; i<stuCnt;i++)
           {
             getValue = Integer.parseInt(str[i][SUM]);
             if(getValue >= getSum)
             {
              for(j = 0; j<dataCnt;j++
              {
               System.out.print(str[i][j]+"\t");
              }
              System.out.println("");
             }
           }
           System.out.print("\n");
           break;
          case 4:
           if(stuCnt == 0)
        {
         System.out.println("입력한 데이터가 없습니다");
         break
        }
           //데이터를 수정하는 기능
           System.out.print("수정 할 이름 : ");
           String nameSearch = sc.nextLine();
           for(i=0; i<stuCnt;i++)
           {
             if(nameSearch.equals(str[i][NAME]))
             {
              System.out.print("수정 할 데이터 중 1.국어 2.영어 3.수학\n당신의 선택? :");
              choiceNumber = sc.nextInt();
              sc.nextLine();
              
              if(choiceNumber == KOR)
              {
               String modifyScore;
               System.out.print("현재 국어 점수 :"+str[i][KOR]+"\n");
               System.out.print("몇 점으로 수정 하시겠습니까 ? ");
               modifyScore = sc.next();
               ko = Integer.parseInt(modifyScore);
               en = Integer.parseInt(str[i][ENG]);
               ma = Integer.parseInt(str[i][MAT]);
               
               str[i][KOR] = Integer.toString(ko);
               str[i][SUM] = Integer.toString(ko+en+ma);
               
               temp = Double.parseDouble(str[i][SUM]);
               temp /= 3;
               str[i][AVG] = ""+temp;
               System.out.println("국어 점수 수정 완료");
              }
              else if(choiceNumber == ENG)
              {
               String modifyScore;
               System.out.print("현재 영어 점수 :"+str[i][ENG]+"\n");
               System.out.print("몇 점으로 수정 하시겠습니까 ? ");
               modifyScore = sc.next();
               
               ko = Integer.parseInt(str[i][KOR]);
               en = Integer.parseInt(modifyScore);
               ma = Integer.parseInt(str[i][MAT]);
               
               str[i][ENG] = Integer.toString(en);
               str[i][SUM] = Integer.toString(ko+en+ma);
               
               temp = Double.parseDouble(str[i][SUM]);
               temp /= 3;
               str[i][AVG] = ""+temp;
               System.out.println("영어 점수 수정 완료");
              }
              else if(choiceNumber == MAT)
              {
               String modifyScore;
               System.out.print("현재 수학 점수 :"+str[i][MAT]+"\n");
               System.out.print("몇 점으로 수정 하시겠습니까 ? ");
               modifyScore = sc.next();
               
               ko = Integer.parseInt(str[i][KOR]);
               en = Integer.parseInt(str[i][ENG]);
               ma = Integer.parseInt(modifyScore);
               
               str[i][KOR] = Integer.toString(ko);
               str[i][SUM] = Integer.toString(ko+en+ma);
               
               temp = Double.parseDouble(str[i][SUM]);
               temp /= 3;
               str[i][AVG] = ""+temp;
               System.out.println("수학 점수 수정 완료");
              }
             }
        }
           break;
          case 5:
           if(stuCnt == 0)
        {
         System.out.println("입력한 데이터가 없습니다");
         break
        }
           //데이터 삭제
           System.out.print("삭제할 사람의 이름을 입력해 주세요 :");
           where = sc.nextLine();
           for(i=0; i<stuCnt ;i++)
           {
             if(where.equals(str[i][NAME]))
             {
              for(j=0; j<dataCnt; j++)
                 {
               str[i][j] = null;
                 }
             }
           }
           System.out.println("삭제 완료");
           break;
          case 6:
           b = false;
           System.out.println("프로그램 종료");
           break;
          default:
           System.out.println("잘못 입력하였습니다.");
           break;      
      }
     }while(b);
    }
}
 
cs

'자바프로그래밍' 카테고리의 다른 글

5. 자바 예외처리  (0) 2019.10.30
4. 자바 성적처리(클래스)  (0) 2019.10.30
2. 자바 별찍기  (0) 2019.10.30
1. 자바 사칙연산 계산기  (0) 2019.10.30
[자바프로그래밍] if 문 연습  (0) 2019.05.10