반응형

[ 계산기 레이아웃 ]


[ HTML 코드 ]

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
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Calculator</title>
</head>
<body>
    <table width=500 align=center>
        <th colspan="5">계산기</th>
        <tr>
            <td colspan=5 align=center><input type="text" id="showText"
                style="width: 350pt; height: 20pt"></td>
        </tr>
        
        <tr>
            <td colspan=3 align=center><input type="button" id="clearBtn"
                onclick=clearAll() value="Clear" style="width: 130pt; height: 30pt"></td>
            <td colspan=2 align=left><input type="button" id="equal"
                onclick=getResult() value="=" style="width: 130pt; height: 30pt"></td>
        </tr>
        
        <tr>
            <td align=center><input type=button id=1 value=1
                onclick=selectedBtn(1) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=2 value=2
                onclick=selectedBtn(2) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=3 value=3
                onclick=selectedBtn(3) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=plus value=+
                onclick=selectedOp("+") style="width: 40pt; height: 30pt"></td>
            <td align=left><input type=button id=square value=x^y
                onclick=selectedOp("^") style="width: 40pt; height: 30pt"></td>
        </tr>
        
        <tr>
            <td align=center><input type=button id=4 value=4
                onclick=selectedBtn(4) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=5 value=5
                onclick=selectedBtn(5) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=6 value=6
                onclick=selectedBtn(6) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=minus value="-"
                onclick=selectedOp("-") style="width: 40pt; height: 30pt"></td>
            <td align=left><input type=button id=sin value="sin"
                onclick=mathText("_sin") style="width: 40pt; height: 30pt"></td>
        </tr>
        <tr>
            <td align=center><input type=button id=7 value=7
                onclick=selectedBtn(7) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=8 value=8
                onclick=selectedBtn(8) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=9 value=9
                onclick=selectedBtn(9) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=multi value=*
                onclick=selectedOp("*") style="width: 40pt; height: 30pt"></td>
            <td align=left><input type=button id=cos value=cos
                onclick=mathText("_cos") style="width: 40pt; height: 30pt"></td>
        </tr>
        <tr>
            <td align=center><input type=button id=0 value=0
                onclick=selectedBtn(0) style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id="plusNMinus" value="+/-"
                onclick=changeSign() style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=dot value="."
                onclick=selectedBtn('.') style="width: 40pt; height: 30pt"></td>
            <td align=center><input type=button id=divide value="/"
                onclick=selectedOp("/") style="width: 40pt; height: 30pt"></td>
            <td align=left><input type=button id=tan value="tan"
                onclick=mathText("_tan") style="width: 40pt; height: 30pt"></td>
        </tr>
    </table>
</body>
</html>
cs

코드설명

 [HTML_17Line] clearAll() : 설정된 변수 및 text value 초기화

 [HTML_19Line] getResult() : 입력된 값 계산 후 result 변수에 저장
 [HTML_24Line] selectedBtn(id) : 선택된 number 버튼의 값을 매개변수로 전달.
 [HTML_30Line] selectedOp(op) : 선택된 operation 버튼의 값을 매개변수로 전달.
 [HTML_45Line] mathText(text) : 선택된 버튼의 값을 매개변수로 전달.

[JS 코드 ]

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
<script language="javascript">
    var text1 = "";
    var op = "";
    var text2 = "";
    var result = "";
    var isDotSelected = false;
    
    function selectedBtn(id) {
        if(id==".") {
            isDotSelected = true;
        }
        if (op == "") { //첫번째 피 연산자 구분
            text1 += id;
        } else {
            text2 += id;
        } // end of if ~ else    
        
        document.getElementById('showText').value = document.getElementById('showText').value + id;
        
    } //end of selectedBtn function
    
    function selectedOp(id) {
        op = id;
        document.getElementById('showText').value = text1 + " " + op + " "
    } //end of selectedOp function
    
    function changeSign() {
        if(text1 == "") {
            alert("값이 없습니다.");
            return;
        } 
        
        if(parseFloat(text1) < 0) { // 값이 음수 -> 양수
            if(op == '') { //
                text1 = Math.abs(parseInt(text1));
                document.getElementById('showText').value = text1;
            } else if(parseFloat(text2) < 0) {
                text2 = Math.abs(parseInt(text2));
                document.getElementById('showText').value = text2;
            } 
        } else { //값 양수 -> 음수
            if(op == '') {
                text1 = '-' + text1;
                document.getElementById('showText').value = text1;
            } else {
                text2 = '-'+text2;
                document.getElementById('showText').value = text2;
            }
        }
    }
    
    function mathText(text) {
        if(text1 == "") {
            alert("값이 없습니다.");
        }
        switch(text) {
        case "_sin" :
            result = Math.sin(parseInt(text1));
            document.getElementById('showText').value = text1 + "의 sin 값 : " + result;
            break;
        case "_cos" :
            result = Math.cos(parseInt(text1));
            document.getElementById('showText').value = text1 + "의 cos 값 : " + result;
            break;
        case "_tan" :
            result = Math.tan(parseInt(text1));
            document.getElementById('showText').value = text1 + "의 tan 값 : " + result;
            break;
        }
    }
 
    function clearAll() {
        text1 = "";
        text2 = "";
        op = "";
        result = "";
        document.getElementById('showText').value = "";
    }
    
    function getResult() { //=
        result = text1 + op + text2;
    
        if(isDotSelected) { //실수
            document.getElementById('showText').value = document.getElementById('showText').value + " = " + eval(result).toFixed(3);    
        } else {
            document.getElementById('showText').value = document.getElementById('showText').value + " = " + eval(result);
        }
        
        text1 = eval(result);
        op="";
        text2="";
        result = "";
        
        isDotSelected = false;
        
    } //end of getResult function
    
</script>
cs


<input type=text>에 들어갈 값들을 [text1] [op] [text2] = [result]로 구성하였다.


함수에 공통적으로 들어가 있는 아래의 코드는

document.getElementById('showText').value = document.getElementById('showText').value + ~ ; 

<input type=text>에 값을 입력하기 위한 문장이다.


● isDotSelected 변수는 '.'이 선택되었을 경우 실수로 값을 변경하기 위해 선언한 flag변수이다.


 function selectedBtn(id) { } 에서는 

선택된 버튼을 구분 후 text1 또는 text2에 입력을 해준다.

if (op == "") { //첫번째 피 연산자 구분
            text1 += id;
        } else {
            text2 += id;
        } // end of if ~ else    
        

위의 if문은 들어갈 값이 text1인지 text2인지 확인하기 위한 조건문이다.

만약 op가 공백이 아닐경우 text1은 입력이 된 상태이고 text2의 값을 넣을 것이다.



 function changeSign() { } 에서는 

text1 또는 text2의 값이 양수일 경우 음수로 / 음수일 경우 양수로 변경해주는 함수이다.

function changeSign() {
        if(text1 == "") {
            alert("값이 없습니다.");
            return;
        } 
        
        if(parseFloat(text1) < 0) { // 값이 음수 -> 양수
            if(op == '') { //
                text1 = Math.abs(parseInt(text1));
                document.getElementById('showText').value = text1;
            } else if(parseFloat(text2) < 0) {
                text2 = Math.abs(parseInt(text2));
                document.getElementById('showText').value = text2;
            } 
        } else { //값 양수 -> 음수
            if(op == '') {
                text1 = '-' + text1;
                document.getElementById('showText').value = text1;
            } else {
                text2 = '-'+text2;
                document.getElementById('showText').value = text2;
            }
        }
    }

Line 33 ~ 39 : 값이 음수일 경우 양수로 변경 해주는 조건문이다.

if문 내에 if~else문은 변경할 값이 text1인지 text2인지 확인후 변경 해주는 조건문이다.

Line 41 ~ 49 : 값이 양수일 경우 음수로 변경 해주는 조건문이다.

위의 if문과 마찬가지로 if문 내에 if~else문은 변경할 값이 text1인지 text2인지 확인후 변경 해주는 조건문이다.


● function mathText(text) { } 에서는

매개변수로 넘겨받은 값을 구분 후 sin, cos, tan계산을 해주는 함수이다.

    function mathText(text) {
        if(text1 == "") {
            alert("값이 없습니다.");
        }
        switch(text) {
        case "_sin" :
            result = Math.sin(parseInt(text1));
            document.getElementById('showText').value = text1 + "의 sin 값 : " + result;
            break;
        case "_cos" :
            result = Math.cos(parseInt(text1));
            document.getElementById('showText').value = text1 + "의 cos 값 : " + result;
            break;
        case "_tan" :
            result = Math.tan(parseInt(text1));
            document.getElementById('showText').value = text1 + "의 tan 값 : " + result;
            break;
        }
    }

내장 객체 Math내에 있는 Math.sin  Math.cos  Math.tan를 이용해 각각의 값을 구한다.


● 스크립트 내의 변수들과 HTML의 result를 보여주는 <input type=text>의 값을 초기화 하는 함수이다.

 
    function clearAll() {
        text1 = "";
        text2 = "";
        op = "";
        result = "";
        document.getElementById('showText').value = "";
    }
    


● 지금까지 입력된 값을 계산하는 함수이다.

    function getResult() { //=
        result = text1 + op + text2;
    
        if(isDotSelected) { //실수
            document.getElementById('showText').value = document.getElementById('showText').value + " = " 
+ eval(result).toFixed(3);    
        } else {
            document.getElementById('showText').value = document.getElementById('showText').value + " = " 
+ eval(result);
        }
        
        text1 = eval(result);
        op="";
        text2="";
        result = "";
        
        isDotSelected = false;
        
    } //end of getResult function

text1과 op, text2는 string문자열로 +를 이용해 result 변수에 모두 입력한다.

if조건문을 사용해 실수인지 정수인지 판별하고 조건문 내에서 문자열 result를 eval 내장 함수를 통해 계산한다.

실수 조건문에서 .toFixed(3)함수는 ( )안 숫자 자리수만큼 소수점을 끊어주는 역할을 한다.


★ eval 함수

문자열을 수식으로 바꿔주는 역할을 한다.


<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<script language="javascript">
 
    var text1 = "10";
    var op = "+";
    var text2 = "20";
    
    var result = text1 + op + text2; // 10+20
    
    alert(eval(result)); //3
</script>
</head>
<body>
 
</body>
</html>
cs

문자열 result를 eval 내장 함수를 통해 수식으로 바꾼 후 바뀐 수식으로 계산 후 출력


반응형

'Web > HTML_JS_CSS' 카테고리의 다른 글

[Javascript] Script 파일의 위치와 onload..  (2) 2019.01.08
[Javascript] Javascript 사용 방법  (2) 2019.01.08
[css] 선택자  (2) 2019.01.07
[JS] 회원가입 유효성 검사  (1) 2018.08.17
[HTML] 회원가입 폼 만들기  (0) 2018.08.17
반응형
MainClass는 프로그램 진입점으로 관리자/사용자 여부를 판별합니다.
 
관리자 로그인 실패시 사용자로 간주하여 사용자모드(사번, 비밀번호 입력 후 일치 데이터가 있을 경우 해당 직원 데이터에 대해 출력)로 자동적으로 넘어갑니다. 관리자 모드에서는 정규직 비정규직 최대 인원수를 입력받고 데이터의 입력, 출력, 수정, 삭제, 검색 기능을 사용할 수 있습니다.

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
/*
 * MainClass.java
 * 프로그램 진입점...
 */
package hasA;
 
import java.util.Scanner;
 
public class MainClass {
 
    private Administrator admin;
 
    public MainClass() {
        this.admin = new Administrator("aa""1234");
    }
 
    public static void main(String[] args) {
 
        MainClass mc = new MainClass();
 
        Scanner sc = new Scanner(System.in);
 
        char prev = 'y';
 
        do {
            boolean pass = false;
 
            pass = mc.admin.identiAdmin(); // 관리자인지 아닌지 확인
 
            if (pass) { // 관리자
                mc.admin.whatAreYouGoing();// 정규직 관리로 갈지 비정규직으로 갈지 확인하는 함수        
            } else {
                System.out.println("사용자 모드..");
                System.out.print("검색하고 싶은 사번을 입력하세요(R_ / P_) : ");
                String num = sc.next();
                System.out.print(num + " 직원의 비밀번호를 입력하세요 : ");
                String password = sc.next();
 
                if (num.charAt(0== 'R') { // 정규직
                    if (mc.admin.getRegularManagement() != null)
                        mc.admin.getRegularManagement().userSearch(num, password);
                    else
                        System.out.println("데이터 나타낼 수 없음");
                } else { // 비정규직
                    if (mc.admin.getPartTimeEmployeeManagementSystem() != null)
                        mc.admin.getPartTimeEmployeeManagementSystem().userSearch(num, password);
                    else
                        System.out.println("데이터 나타낼 수 없음");
                }                
            }
            System.out.println("---------- 페이지  ----------");
            System.out.println("이 페이지 수행 기능 ");
            System.out.println("-> 관리자 로그인 페이지");
            System.out.println("이 페이지 머물기(y) / 프로그램 종료(n): ");
            prev = sc.next().charAt(0);
        } while (prev != 'n');
 
        System.out.println();
        System.out.println("프로그램 종료");
 
    }
}
 
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * ManagementSystem.java
 * 해당 인터페이스는 관리클래스를 관리
 */
package hasA;
 
public interface ManagementSystem {
 
    // 입력
    public void input();
    // 수정
    public void modifi();
    // 삭제
    public void delete();
    // 검색
    public void search();
    // 출력
    public void allOutput();
    
}
 
cs


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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
 * RegularManagement.java
 */
 
package hasA;
 
import java.util.Scanner;
 
/*
 * 이곳은 정규직 관리 클래스 입니다.
 * 정규직 직원에 대한 데이터 입력을 담당합니다.
*/
public class RegularManagement implements ManagementSystem {
    private RegularEmployee[] re; // 정규직직원클래스
    private SalaryManagement sm; // 급여관리클래스
    private int numOfRegular; // 정규직 최대 인원수
    private int empCount; // 입력받을 직원 수
    private int empIndex; // 현재 입력받을 수 있는 reference index
 
    public RegularManagement() {
        this(0);
    }
 
    public RegularManagement(int numOfRegular) {
        this.numOfRegular = numOfRegular;
 
        // 사람 수 만큼 정규직 직원 생성
        re = new RegularEmployee[this.numOfRegular];
        sm = null;
 
        empCount = 0;
        empIndex = 0;
    }
 
    // setter,getter
    public RegularEmployee[] getRe() {
        return re;
    }
 
    public void setRe(RegularEmployee[] re) {
        this.re = re;
    }
 
    public SalaryManagement getSm() {
        return sm;
    }
 
    public long getSalary(RegularEmployee re) {
        this.sm = new SalaryManagement(re);
        this.sm.putOnRecord();
        return this.sm.getRealSalary();
    }
 
    public void setNumOfRegular(int numOfRegular) {
        this.numOfRegular = numOfRegular;
    }
 
    public int getNumOfRegular() {
        return numOfRegular;
    }
 
    // 입력
    public void input() {
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == numOfRegular) { // 입력을 다 하였을 경우..
            System.out.println("더 이상 입력할 수 없습니다.");
        } else {
            System.out.print("정규직 직원 몇명 입력하시겠어요? ");
            this.empCount = sc.nextInt(); // 입력받을 직원 수
            System.out.println();
 
            if (empCount + empIndex > numOfRegular) {
                System.out.println("입력할 수 있는 범위를 초과하였습니다..");
                System.out.println("다시 시도해주세요..");
            } else {
                for (int i = 0; i < empCount; i++) {
                    re[empIndex] = new RegularEmployee();
 
                    System.out.println("정규직 " + (empIndex + 1+ "번째 직원 정보 입력");
 
                    // 사번
                    re[empIndex].setEmpNum(empIndex + 1);
 
                    // 이름입력
                    System.out.print((empIndex + 1+ "번째 직원 이름 입력 : ");
                    String name = sc.next();
                    System.out.println();
 
                    // 나이입력
                    System.out.print((empIndex + 1+ "번째 직원 나이 입력 : ");
                    int age = sc.nextInt();
                    System.out.println();
 
                    // 생년월일
                    System.out.print((empIndex + 1+ "번째 직원 생년월일 입력(YYYY-MM-DD) : ");
                    String birth = sc.next();
                    System.out.println();
 
                    // 주소
                    System.out.print((empIndex + 1+ "번째 직원 주소 입력 : ");
                    String address = sc.next();
                    System.out.println();
 
                    // 연락처
                    System.out.print((empIndex + 1+ "번째 직원 연락처 입력 : ");
                    String tel = sc.next();
                    System.out.println();
 
                    // 이메일 입력
                    System.out.print((empIndex + 1+ "번째 직원 이메일 입력 : ");
                    String email = sc.next();
                    System.out.println();
 
                    // 은행명 입력
                    System.out.print((empIndex + 1+ "번째 직원 은행명 입력 : ");
                    String bankName = sc.next();
                    System.out.println();
 
                    // 계좌 입력
                    System.out.print((empIndex + 1+ "번째 직원 계좌 입력 : ");
                    String account = sc.next();
                    System.out.println();
 
                    // 개인정보 입력
                    re[empIndex].setPersonalInfo(name, age, birth, address, tel, email, bankName, account);
 
                    // 직책 입력
                    int pos = 0;
                    do {
                        System.out.println((empIndex + 1+ "번째 직원 해당되는 직책 번호를 선택하세요");
                        System.out.println("1.신입사원  2.사원  3.대리  4.과장  5.팀장  6.차장  7.부장  8.전무  9.이사  10.대표이사");
                        System.out.print("-> ");
                        pos = sc.nextInt();
                    } while ((pos >= 1 && pos <= 10== false); // 직책 선택을 잘못 했을 경우
                    re[empIndex].setPosition(Position.getPosition(pos));
                    System.out.println();
 
                    // 소속팀 입력
                    System.out.print((empIndex + 1+ "번째 직원 소속팀 입력 : ");
                    re[empIndex].setTeam(sc.next());
                    System.out.println();
 
                    // 소속부서 입력
                    System.out.print((empIndex + 1+ "번째 직원 소속부서 입력 : ");
                    re[empIndex].setDept(sc.next());
                    System.out.println();
 
                    // 입사년도 입력
                    System.out.print((empIndex + 1+ "번째 직원 입사년도 입력(YYYY) : ");
                    re[empIndex].setYear(sc.nextInt());
                    System.out.println();
 
                    // 비밀번호 입력
                    System.out.print((empIndex + 1+ "번째 직원 비밀번호 입력 : ");
                    re[empIndex].setPassword(sc.next());
                    System.out.println();
 
                    // 사용자에게 입력받을 필요가 없는 부분 등록..
                    // 급여등록 : 직책으로 급여계산
                    long salary = this.getSalary(re[empIndex]); // 급여관리 클래스에서 실급여 계산하고 salary변수에 입력
                    re[empIndex].setSalary(salary); // 입력된 급여를 해당 직원 급여에 입력
 
                    empIndex++;
                }
            }
        }
    }
 
    // 수정
    public void modifi() { // 이름검색
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.print("검색하고 싶은 직원 이름을 입력하세요 : ");
            String tmpName = sc.next();
 
            boolean exist = true;
 
            for (int i = 0; i < empIndex; i++) {
                if (re[i].getPersonalInfo().getName().equals(tmpName)) {
 
                    System.out.println("수정하고 싶은 데이터를 선택하세요..");
                    System.out.println("1.이름  2.나이  3.생일  4.주소 5.전화번호  6.이메일  7.은행명  8.계좌");
                    System.out.println("9.직책  10.소속팀  11.소속부서 12.근속년도  13.비밀번호");
                    System.out.print("-> ");
                    int num = sc.nextInt(); // 번호 선택
 
                    String sTmp = "";
                    int iTmp = 0;
                    long salary = 0;
 
                    switch (num) {
                    case 1// 이름수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setName(sTmp);
                        break;
                    case 2// 나이 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        iTmp = sc.nextInt();
                        re[i].getPersonalInfo().setAge(iTmp);
                        break;
                    case 3// 생년월일수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setBirth(sTmp);
                        break;
                    case 4// 주소 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setAddress(sTmp);
                        break;
                    case 5// 전화번호 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setTel(sTmp);
                        break;
                    case 6// 이메일 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setEmail(sTmp);
                        break;
                    case 7// 은행명 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setBankName(sTmp);
                        break;
                    case 8// 계좌 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].getPersonalInfo().setAccount(sTmp);
                        break;
                    case 9// 직책수정
                        int pos = 0;
                        do {
                            System.out.println("수정할 데이터를 입력하세요 : ");
                            System.out.println("1.신입사원  2.사원  3.대리  4.과장  5.팀장  6.차장  7.부장  8.전무  9.이사  10.대표이사");
                            System.out.print("-> ");
                            pos = sc.nextInt();
                        } while ((pos >= 1 && pos <= 10== false); // 직책 선택을 잘못 했을 경우
                        re[i].setPosition(Position.getPosition(pos));
                        // 급여등록 -> 직책이 수정되면 insentive가 바뀌므로...
                        salary = this.getSalary(re[i]); // 급여관리 클래스에서 실급여 계산하고 salary변수에 입력
                        re[i].setSalary(salary); // 입력된 급여를 해당 직원 급여에 입력
                        break;
                    case 10// 팀 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].setTeam(sTmp);
                        break;
                    case 11// 부서 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].setDept(sTmp);
                        break;
                    case 12// 근속년도 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        iTmp = sc.nextInt();
                        re[i].setYear(iTmp);
                        // 급여등록 -> 근속년도가 수정되면 basicSalary가 바뀌므로...
                        salary = this.getSalary(re[empIndex]); // 급여관리 클래스에서 실급여 계산하고 salary변수에 입력
                        re[i].setSalary(salary); // 입력된 급여를 해당 직원 급여에 입력
                        break;
                    case 13// 비밀번호 수정
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        re[i].setPassword(sTmp);
                        break;
                    default:
                        System.out.println("잘못 입력하였습니다.");
                    }
                    exist = true;
                    System.out.println();
                    System.out.println("수정완료!!");
                }
                if (!exist)
                    System.out.println("검색하신 " + tmpName + " 직원에 대한 정보가 없습니다.");
 
            }
        }
    }
 
    // 삭제
    public void delete() {
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.print("삭제할 직원의 이름을 입력하세요 : ");
            String tmpName = sc.next();
 
            boolean exist = false;
 
            for (int i = 0; i < empIndex; i++) {
                if (re[i].getPersonalInfo().getName().equals(tmpName)) {
                    re[i] = null;
                    exist = true;
                }
                System.out.println("삭제완료!!");
            }
            if (!exist)
                System.out.println("검색하신 " + tmpName + " 직원에 대한 정보가 없습니다.");
        }
    }
 
    // 검색
    public void search() { // 이름 검색
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.print("검색하고 싶은 직원 이름을 입력하세요 : ");
            String tmpName = sc.next();
 
            boolean exist = false;
 
            for (int i = 0; i < empIndex; i++) {
                if (re[i].getPersonalInfo().getName().equals(tmpName)) {
                    disp(re[i]);
 
                    exist = true;
                }
            }
            if (!exist)
                System.out.println("검색하신 " + tmpName + " 직원에 대한 정보가 없습니다.");
 
            exist = !exist;
        }
    }
 
    // 출력
    public void allOutput() {
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.println("-----------------------------------");
            System.out.println("----------정규직 직원 전체 출력----------");
            System.out.println("-----------------------------------");
 
            for (int i = 0; i < empIndex; i++) {
                if (re[i] != null) {
                    System.out.println((i + 1+ "번째 직원 출력");
                    disp(re[i]);
                }
            }
        }
    }
 
    public void userSearch(String num, String password) { // 사용자에서 사번과 이름을 받아옴
 
        if (empIndex == 0) {
            System.out.println("직원정보가 없습니다.");
        } else {
            for (int i = 0; i < empIndex; i++) {
                if (re[i] != null) {
                    if (re[i].getEmpNum().equals(num) && re[i].getPassword().equals(password))
                        disp(re[i]);
                }
            }
        }
    }
 
    public void disp(RegularEmployee re) {
        System.out.println("----------------------------------------");
        System.out.println("사번 : " + re.getEmpNum()); // 사번
        // 직원 개인정보 출력
        System.out.println("이름 : " + re.getPersonalInfo().getName()); // 이름
        System.out.println("나이 : " + re.getPersonalInfo().getAge()); // 나이
        System.out.println("연락처 : " + re.getPersonalInfo().getBirth()); // 연락처
        System.out.println("주소 : " + re.getPersonalInfo().getAddress()); // 주소
        System.out.println("전화번호 : " + re.getPersonalInfo().getTel()); // 전화번호
        System.out.println("이메일 : " + re.getPersonalInfo().getEmail()); // 이메일
        System.out.println("은행명 : " + re.getPersonalInfo().getBankName()); // 은행명
        System.out.println("계좌번호 : " + re.getPersonalInfo().getAccount()); // 계좌번호
        System.out.println("직책 : " + re.getPosition()); // 직책
        System.out.println("소속팀 : " + re.getTeam()); // 소속팀
        System.out.println("소속부서 : " + re.getDept()); // 소속부서
        System.out.println("급여 : " + re.getSalary()); // 급여
        System.out.println("근속년도 : " + re.getYear()); // 근속년도
        System.out.println("----------------------------------------");
    }
}
 
cs


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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package hasA;
 
import java.util.Scanner;
 
public class PartTimeEmployeeManagementSystem implements ManagementSystem {
 
    private PartTimeEmployee[] partTimeEmployee; // 비정규직 직원 클래스
    private SalaryManagement salaryManagement; // 급여관리 클래스
    private int maxNum; // 비정규직 최대 인원수
    private int empCount; // 입력받을 직원 수
    private int empIndex; // 현재 입력받을 수 있는 reference index
 
    public PartTimeEmployeeManagementSystem() {
        this(0);
    }
 
    public PartTimeEmployeeManagementSystem(int maxNum) {
 
        this.maxNum = maxNum;
        /*
         * PartTimeEmployeeManagementSystem을 생성한 클래스에서 비정규직 수를 최대로 받아 그만큼 생성합니다.
         */
        partTimeEmployee = new PartTimeEmployee[maxNum];
        salaryManagement = null;
 
        empCount = 0;
        empIndex = 0;
    }
 
    // setter,getter
 
    public PartTimeEmployee getPartTimeEmployee(int index) { // 주입된 index를 통해 partTimeEmployee[index]의 값을 return
        return partTimeEmployee[index];
    }
 
    public void setPartTimeEmployee(PartTimeEmployee[] pe) {
        this.partTimeEmployee = pe;
    }
 
    public SalaryManagement getSalaryManagement() {
        return salaryManagement;
    }
 
    public void setSalaryManagement(PartTimeEmployee pe) {
        salaryManagement = new SalaryManagement(pe);
        salaryManagement.putOnRecord();
    }
 
    public void setNumOfRegular(int maxNum) {
        this.maxNum = maxNum;
    }
 
    public int getNumOfRegular() {
        return maxNum;
    }
 
    public PartTimeEmployee getClass(int index) {
        return partTimeEmployee[index];
    }
 
    public long getSalary(PartTimeEmployee pe) {
        this.salaryManagement = new SalaryManagement(pe);
        this.salaryManagement.putOnRecord();
        return this.salaryManagement.getRealSalary();
    }
 
    // 입력
    public void input() {
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == maxNum) { // 입력을 다 하였을 경우..
            System.out.println("더 이상 입력할 수 없습니다.");
        } else {
            System.out.print("비정규직 직원 몇명 입력하시겠어요? ");
            this.empCount = sc.nextInt(); // 입력받을 직원 수
            System.out.println();
 
            if (empCount + empIndex > maxNum) {
                System.out.println("입력할 수 있는 범위를 초과하였습니다..");
                System.out.println("다시 시도해주세요..");
            } else {
                for (int i = 0; i < empCount; i++) {
                    partTimeEmployee[empIndex] = new PartTimeEmployee();
 
                    System.out.println("비정규직 " + (empIndex + 1+ "번째 직원 정보 입력");
 
                    // 사번
                    partTimeEmployee[empIndex].setEmpNum(empIndex + 1);
 
                    // 이름입력
                    System.out.print((empIndex + 1+ "번째 직원 이름 입력 : ");
                    String name = sc.next();
                    System.out.println();
 
                    // 나이입력
                    System.out.print((empIndex + 1+ "번째 직원 나이 입력 : ");
                    int age = sc.nextInt();
                    System.out.println();
 
                    // 생년월일
                    System.out.print((empIndex + 1+ "번째 직원 생년월일 입력(YYYY-MM-DD) : ");
                    String birth = sc.next();
                    System.out.println();
 
                    // 주소
                    System.out.print((empIndex + 1+ "번째 직원 주소 입력 : ");
                    String address = sc.next();
                    System.out.println();
 
                    // 연락처
                    System.out.print((empIndex + 1+ "번째 직원 연락처 입력 : ");
                    String tel = sc.next();
                    System.out.println();
 
                    // 이메일 입력
                    System.out.print((empIndex + 1+ "번째 직원 이메일 입력 : ");
                    String email = sc.next();
                    System.out.println();
 
                    // 은행명 입력
                    System.out.print((empIndex + 1+ "번째 직원 은행명 입력 : ");
                    String bankName = sc.next();
                    System.out.println();
 
                    // 계좌 입력
                    System.out.print((empIndex + 1+ "번째 직원 계좌 입력 : ");
                    String account = sc.next();
                    System.out.println();
 
                    // 개인정보 입력
                    partTimeEmployee[empIndex].setPersonalInfo(name, age, birth, address, tel, email, bankName,
                            account);
 
                    // 소속팀 입력
                    System.out.print((empIndex + 1+ "번째 직원 소속팀 입력 : ");
                    partTimeEmployee[empIndex].setTeam(sc.next());
                    System.out.println();
 
                    // 소속부서 입력
                    System.out.print((empIndex + 1+ "번째 직원 소속부서 입력 : ");
                    partTimeEmployee[empIndex].setDept(sc.next());
                    System.out.println();
 
                    // 입사년도 입력
                    System.out.print((empIndex + 1+ "번째 직원 입사년도 입력(YYYY) : ");
                    partTimeEmployee[empIndex].setYear(sc.nextInt());
                    System.out.println();
 
                    // 계약기간 입력
                    System.out.print((empIndex + 1+ "번째 직원 계약기간 : ");
                    partTimeEmployee[empIndex].setPeriod(sc.nextInt());
                    System.out.println();
 
                    // 비밀번호 입력
                    System.out.print((empIndex + 1+ "번째 직원 비밀번호 입력 : ");
                    partTimeEmployee[empIndex].setPassword(sc.next());
                    System.out.println();
 
                    ///////////
                    // 사용자에게 입력을 받을 필요가 없는 부분
                    partTimeEmployee[empIndex].setEndOfDate(); // 퇴사일자 = 입사년도 + 계약기간
 
                    // 사용자에게 입력받을 필요가 없는 부분 등록..
                    // 급여등록 : 직책으로 급여계산
                    // 급여등록
                    long salary = this.getSalary(partTimeEmployee[empIndex]);
                    partTimeEmployee[empIndex].setSalary(salary);
                    System.out.println();
 
                    empIndex++;
                }
            }
        }
    }
 
    // 수정
    public void modifi() {// 이름검색
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.print("검색하고 싶은 직원 이름을 입력하세요 : ");
            String tmpName = sc.next();
 
            boolean exist = true;
 
            for (int i = 0; i < empIndex; i++) {
                if (partTimeEmployee[i].getPersonalInfo().getName().equals(tmpName)) {
 
                    System.out.println("수정하고 싶은 데이터를 선택하세요..");
                    System.out.println("1.이름  2.나이  3.생일  4.주소 5.전화번호  6.이메일  7.은행명  8.계좌번호");
                    System.out.println("9.소속팀  10.소속부서  11.입사년도  12.계약기간  13.비밀번호");
                    System.out.print("-> ");
                    int num = sc.nextInt(); // 번호 선택
 
                    String sTmp = "";
                    int iTmp = 0;
 
                    switch (num) {
                    case 1// 이름
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setName(sTmp);
                        break;
                    case 2// 나이
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        iTmp = sc.nextInt();
                        partTimeEmployee[i].getPersonalInfo().setAge(iTmp);
                        break;
                    case 3// 생일
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setBirth(sTmp);
                        break;
                    case 4// 주소
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setAddress(sTmp);
                        break;
                    case 5// 전화번호
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setTel(sTmp);
                        break;
                    case 6// 이메일
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setEmail(sTmp);
                    case 7// 은행명
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setBankName(sTmp);
                    case 8// 계좌
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].getPersonalInfo().setAccount(sTmp);
                        break;
                    case 9// 팀
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].setTeam(sTmp);
                        break;
                    case 10// 소속부서
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].setDept(sTmp);
                        break;
                    case 11// 입사년도
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        iTmp = sc.nextInt();
                        partTimeEmployee[i].setYear(iTmp);
                        break;
                    case 12// 계약기간
                        System.out.println("수정할 데이터를 입력하세요 : ");
                        iTmp = sc.nextInt();
                        partTimeEmployee[i].setPeriod(iTmp);
                        break;
                    case 13// 비밀번호
                        System.out.print("수정할 데이터를 입력하세요 : ");
                        sTmp = sc.next();
                        partTimeEmployee[i].setPassword(sTmp);
                        break;
                    default:
                        System.out.println("잘못 입력하였습니다.");
                    }
                    exist = true;
                    System.out.println();
                    System.out.println("수정완료!!");
                }
                if (!exist)
                    System.out.println("검색하신 " + tmpName + " 직원에 대한 정보가 없습니다.");
 
            }
        }
    }
 
    // 삭제
    public void delete() {
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.print("삭제할 직원의 이름을 입력하세요 : ");
            String tmpName = sc.next();
 
            boolean exist = true;
 
            for (int i = 0; i < empIndex; i++) {
                if (partTimeEmployee[i].getPersonalInfo().getName().equals(tmpName)) {
                    partTimeEmployee[i] = null;
                    exist = true;
                }
                if (!exist)
                    System.out.println("검색하신 " + tmpName + " 직원에 대한 정보가 없습니다.");
            }
        }
    }
 
    // 검색
    public void search() {
 
        Scanner sc = new Scanner(System.in);
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            System.out.print("검색하고 싶은 직원 이름을 입력하세요 : ");
            String tmpName = sc.next();
 
            boolean exist = false;
 
            for (int i = 0; i < empIndex; i++) {
                if (partTimeEmployee[i].getPersonalInfo().getName().equals(tmpName)) {
                    this.disp(partTimeEmployee[i]);
 
                    exist = true;
                }
                if (!exist)
                    System.out.println("검색하신 " + tmpName + " 직원에 대한 정보가 없습니다.");
 
                exist = !exist;
 
            }
        }
    }
 
    // 출력
    public void allOutput() {
 
        if (empIndex == 0) {
 
            System.out.println("직원정보가 없습니다.");
        } else {
 
            boolean exist = true;
 
            System.out.println("-----------------------------------");
            System.out.println("----------비정규직 직원 전체 출력----------");
            System.out.println("-----------------------------------");
 
            for (int i = 0; i < empIndex; i++) {
                if (partTimeEmployee[i] != null) {
                    System.out.println((i + 1+ "번째 직원 출력");
                    this.disp(partTimeEmployee[i]);
                    exist = true;
                }
                if (!exist)
                    System.out.println("직원 정보가 없습니다.");
            }
        }
    }
 
    public void userSearch(String num, String password) { // 사용자에서 사번과 이름을 받아옴
 
        if (empIndex == 0) {
            System.out.println("직원정보가 없습니다.");
        } else {
            for (int i = 0; i < empIndex; i++) {
                if (partTimeEmployee[i] != null) {
                    if (partTimeEmployee[i].getEmpNum().equals(num)
                            && partTimeEmployee[i].getPassword().equals(password))
                        this.disp(partTimeEmployee[i]);
                }
            }
        }
    }
 
    public void disp(PartTimeEmployee pe) {
        System.out.println("----------------------------------------");
        System.out.println("사번 : " + pe.getEmpNum()); // 사번
        // 직원 개인정보 출력
        System.out.println("이름 : " + pe.getPersonalInfo().getName()); // 이름
        System.out.println("나이 : " + pe.getPersonalInfo().getAge()); // 나이
        System.out.println("연락처 : " + pe.getPersonalInfo().getBirth()); // 연락처
        System.out.println("주소 : " + pe.getPersonalInfo().getAddress()); // 주소
        System.out.println("전화번호 : " + pe.getPersonalInfo().getTel()); // 전화번호
        System.out.println("이메일 : " + pe.getPersonalInfo().getEmail()); // 이메일
        System.out.println("은행명 : " + pe.getPersonalInfo().getBankName()); // 은행명
        System.out.println("계좌번호 : " + pe.getPersonalInfo().getAccount()); // 계좌번호
        System.out.println("소속팀 : " + pe.getTeam()); // 소속팀
        System.out.println("소속부서 : " + pe.getDept()); // 소속부서
        System.out.println("급여 : " + pe.getSalary()); // 급여
        System.out.println("근속년도 : " + pe.getYear()); // 근속년도
        System.out.println("계약기간 : " + pe.getPeriod() + "년"); // 계약기간
        System.out.println("퇴사일자 : " + pe.getEndOfDate() + "년"); // 퇴사일자
        System.out.println("----------------------------------------");
    }
}
 
cs

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
/**
 * PersonalInfo.java
 */
package hasA;
 
import java.util.Date;
 
public class PersonalInfo {
 
    private String name;// 이름
    private int age;// 나이
    private String birth;// 생년월일
    private String address;// 주소
    private String tel;// 연락처
    private String email;// email
    private String bankName; //은행
    private String account;
 
    public PersonalInfo() {
        this(""0"""""""""""");
    }
 
    public PersonalInfo(String name, int age, String birth, String address, 
            String tel, String email, String bankName, String account) {
        super();
        this.name = name;
        this.age = age;
        this.birth = birth;
        this.address = address;
        this.tel = tel;
        this.email = email;
        this.bankName = bankName;
        this.account = account;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = new String(name);
    }
 
    public int getAge() {
        return age;
    }
 
    public void setAge(int age) {
        this.age = age;
    }
 
    public String getBirth() {
        return birth;
    }
 
    public void setBirth(String birth) {
        this.birth = new String(birth);
    }
 
    public String getAddress() {
        return address;
    }
 
    public void setAddress(String address) {
        this.address = new String(address);
    }
 
    public String getTel() {
        return tel;
    }
 
    public void setTel(String tel) {
        this.tel = tel;
    }
 
    public String getEmail() {
        return email;
    }
 
    public void setEmail(String email) {
        this.email = new String(email);
    }
 
    public String getBankName() {
        return bankName;
    }
 
    public void setBankName(String bankName) {
        this.bankName = bankName;
    }
 
    public String getAccount() {
        return account;
    }
 
    public void setAccount(String account) {
        this.account = account;
    }
    
}
cs


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
/**
 * RegularEmployee.java
 */
package hasA;
 
import java.util.Date;
 
 
 
//정규직 클래스는 필드와 게터 세터만 존재함
//사번,개인정보,직책,소속팀,소속부서,급여,근속년도,비밀번호,생성자
public class RegularEmployee {
 
    // 사번
    private String empNum;
    // 개인정보
    private PersonalInfo pi;
    // 직책
    private String position;
    // 소속팀
    private String team;
    // 소속부서
    private String dept;
    // 급여(월급)
    private long salary;
    // 근속년도
    private int year;
    // 비밀번호
    private String password;
    
 
    public RegularEmployee() {
        this("",""""""00"");        
    }
 
    public RegularEmployee(String empNum,String position, String team, String dept, long salary, int year, String password)
    {
        this.empNum = empNum;
        pi = new PersonalInfo();
        this.position =position;
        this.team=team;
        this.dept=dept;
        this.salary=salary;
        this.year=year;
        this.password = password;
    }
    
    // 사번
    public String getEmpNum() {
        return empNum;
    }
 
    public void setEmpNum(int index) {
        this.empNum = new String("R" + index);
    }
    
    //개인정보 입력
    public void setPersonalInfo(String name, int age, String birth, 
            String address, String tel, String email, String bankName, String account) {
        pi = new PersonalInfo();
        pi.setName(name);
        pi.setAge(age);
        pi.setBirth(birth);
        pi.setAddress(address);
        pi.setTel(tel);
        pi.setEmail(email);
        pi.setBankName(bankName);
        pi.setAccount(account);
    }
    
    public PersonalInfo getPersonalInfo() {
        return pi;
    }
    
 
    // 직책
    public String getPosition() {
        return position;
    }
 
    public void setPosition(String position) {
        this.position = new String(position);
    }
 
    // 소속팀
    public String getTeam() {
        return team;
    }
 
    public void setTeam(String team) {
        this.team = new String(team);
    }
 
    // 소속부서
    public String getDept() {
        return dept;
    }
 
    public void setDept(String dept) {
        this.dept = new String(dept);
    }
 
    // 급여
    public long getSalary() {
        return salary;
    }
 
    public void setSalary(long salary) {
        this.salary = salary;
    }
 
    // 근속년도
    public int getYear() {
        return year;
    }
 
    public void setYear(int year) {
        //올해 몇년도?
        //Date date = new Date();
        int thisYear = 2018;
        
        //근속년도 구하기(올해 - 입사년도)
        this.year = thisYear - year;
    }
 
    // 비밀번호
    public String getPassword() {
        return password;
    }
 
    public void setPassword(String password) {
        this.password = new String(password);
    }
 
}
 
cs


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
/**
 * Position.java
 */
package hasA;
 
public class Position { 
    
    public static String getPosition(int pos) {
    
        switch(pos) {
            case 1
                return "신입사원";
            case 2
                return "사원";
            case 3
                return "대리";
            case 4
                return "과장";
            case 5
                return "팀장";
            case 6
                return "차장";
            case 7
                return "부장";
            case 8
                return "전무";
            case 9
                return "이사";
            case 10
                return "대표이사";
            default :
                return "null";
        }
    }
}
cs

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
/**
 * PartTimeEmployee.java
 */
package hasA;
 
import java.util.Date;
 
public class PartTimeEmployee {
 
    private String empNum;// 사번
    private PersonalInfo personalInfo; // 개인정보
    private String team;// 소속팀
    private String dept;// 소속부서
    private long salary;// 급여
    private int year;// 근속년도
    private int period;// 계약기간
    private int endOfDate;// 퇴사일자
    private String password;// 비밀번호
 
    public PartTimeEmployee() {
        this(0""""000"""");
    }
 
    public PartTimeEmployee(int empIndex, String team, String dept, int salary, int year, int period, String endOfDate, String password) {
        this.empNum = "P" + empIndex;
        personalInfo = new PersonalInfo();
        this.team = team;
        this.dept = dept;
        this.salary = salary;
        this.year = year;
        this.period = period;
        endOfDate = endOfDate;
        this.password = password;
    }
 
    // this.개인정보 set
    public void setPersonalInfo(String name, int age, String birth, 
            String address, String tel, String email, String bankName, String account) {
        personalInfo = new PersonalInfo();
        personalInfo.setName(name);
        personalInfo.setAge(age);
        personalInfo.setBirth(birth);
        personalInfo.setAddress(address);
        personalInfo.setTel(tel);
        personalInfo.setEmail(email);
        personalInfo.setBankName(bankName);
        personalInfo.setAccount(account);
    }
 
    // this.개인정보 return
    public PersonalInfo getPersonalInfo() {
        return personalInfo;
    }
 
    public int getYear() {
        return year;
    }
 
    public void setYear(int year) {
        this.year = year;
    }
 
    public String getEmpNum() {
        return empNum;
    }
 
    public void setEmpNum(int empIndex) {
        this.empNum = "P" + empIndex;
    }
 
    public long getSalary() {
        return salary;
    }
 
    public void setSalary(long salary) {
        this.salary = salary;
    }
 
    public String getPassword() {
        return password;
    }
 
    public void setPassword(String password) {
        this.password = password;
    }
 
    public String getTeam() {
        return team;
    }
 
    public void setTeam(String team) {
        this.team = team;
    }
 
    public String getDept() {
        return dept;
    }
 
    public void setDept(String dept) {
        this.dept = dept;
    }
 
    public int getPeriod() {
        return period;
    }
 
    public void setPeriod(int period) {
        this.period = period;
    }
 
    public int getEndOfDate() {
        return endOfDate;
    }
 
    public void setEndOfDate() {
        this.endOfDate = this.year + this.period;
    }
}
cs

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
/**
 * SalaryManagement.java
 */
package hasA;
 
/*
 * 기본급, 수당, 세금, 실급여는 각자 계산하여 넣기
 */
public class SalaryManagement {
 
    // private String empNum; // 사원(사원번호를 통해 검색)
    private RegularEmployee regular;
    private PartTimeEmployee partTime;
    private char divRP; // 정규직인지 비정규직인지 확인하는 변수
    private long insentive;// 수당
    private long tax; // 세금
    private long basicSalary;// 기본급
    private long realSalary; // 실급여
 
    public SalaryManagement(RegularEmployee regular) { // 정규직
        /*
         * divRP는 급여관리 객체를 만드는 클래스에서 해당 직원 사번의 첫글자 정규직 = R / 비정규직 = P로 판단함
         */
 
        this.regular = regular;
        partTime = null;
        this.divRP = 'R';
        insentive = tax = basicSalary = realSalary = 0// 전부 long
    }
 
    public SalaryManagement(PartTimeEmployee partTime) { // 비정규직
        /*
         * divRP는 급여관리 객체를 만드는 클래스에서 해당 직원 사번의 첫글자 정규직 = R / 비정규직 = P로 판단함
         */
        regular = null;
        this.partTime = partTime;
        this.divRP = 'P';
        insentive = tax = basicSalary = realSalary = 0;
    }
 
    public void setDiviRP() {
        if (regular.getEmpNum().charAt(0== 'R') { // 입력된 사번이 정규직일경우 사번의 첫번째 글자가 R이므로 해당 if문은 정규직을 위한 if문
            this.divRP = 'R';
        } else {// 입력된 사번이 비규직일경우 사번의 첫번째 글자가 P이므로 해당 if문은 비정규직을 위한 if문
            this.divRP = 'P';
        }
    }
 
    public void putOnRecord() { // 해당 직원에 대해 계산할 수 있는 함수 모두 호출
        setBasciSalary();
        if (divRP == 'R')
            setInsentive(); // 비정규직은 수당이 없음
        setTax();
        setRealSalary();
    }
 
    // 기본급 입력
    public void setBasciSalary() { // 근속년도를 받아와 기본급여 측정
        // 근속년도에 따라 기본급여 나누기
        // basicSalary = 근속년도에 따른 기본급여
 
        int man = 10000;
 
        if (divRP == 'P') { // 비정규직이라면..
            this.basicSalary = 100 * man;
        } else {
            // 근속년도에 따라 측정
            if (this.regular.getYear() == 0 && this.regular.getYear() < 1)
                this.basicSalary = 150 * man;
            else if (this.regular.getYear() >= 1 && this.regular.getYear() < 4)
                this.basicSalary = 200 * man;
            else if (this.regular.getYear() >= 4 && this.regular.getYear() < 9)
                this.basicSalary = 300 * man;
            else if (this.regular.getYear() >= 9 && this.regular.getYear() < 15)
                this.basicSalary = 400 * man;
        }
    }
 
    public long getBasciSalary() {
        return basicSalary;
    }
 
    public void setInsentive() { // 직책 받아오기
        /*
         * insentive = 직책에 따른 수당 관리 비정규직 : 0% 신입사원 : 15% 사원 : 30% 대리 : 50% 과장 : 70% 팀장 :
         * 80% 차장 : 90% 부장 : 100% 전무 : 130% 이사 : 150% 회장 : 200%
         * 
         * insentive 계산 방법 : 기본급 * 직책에 따른 퍼센트 계산
         */
 
        // 수당 입력
 
        String pos = this.regular.getPosition();// 직책 받아오기
        switch (pos) {
        case "신입사원":
            this.insentive = (int) (this.basicSalary * 0.15);
            break;
        case "사원":
            this.insentive = (int) (this.basicSalary * 0.3);
            break;
        case "대리":
            this.insentive = (int) (this.basicSalary * 0.5);
            break;
        case "과장":
            this.insentive = (int) (this.basicSalary * 0.7);
            break;
        case "팀장":
            this.insentive = (int) (this.basicSalary * 0.8);
            break;
        case "차장":
            this.insentive = (int) (this.basicSalary * 0.9);
            break;
        case "부장":
            this.insentive = (int) (this.basicSalary * 1);
            break;
        case "전무":
            this.insentive = (int) (this.basicSalary * 1.3);
            break;
        case "이사":
            this.insentive = (int) (this.basicSalary * 1.5);
            break;
        case "대표이사":
            this.insentive = (int) (this.basicSalary * 2);
            break;
        default:
            //System.out.println("잘못된 입력입니다.");
        }
    }
 
    public long getInsentive() {
        return (long)insentive;
    }
 
    public void setTax() {
        // 세금 계산방법 : (기본급 + 수당) *15 %
        // 세금 입력
        this.tax = (long) ((this.basicSalary + this.insentive) * 0.15);
    }
 
    public long getTax() {
        return this.tax;
    }
 
    public long getRealSalary() {
        return this.realSalary;
    }
 
    public void setRealSalary() {
        // 실급여 계산방법 = 기본급 + 수당 - 세금
        // 실급여 입력
        this.realSalary = this.basicSalary + this.insentive - this.tax;
    }
 
}
 
cs


반응형
반응형

Enum개념과 사용법 이를 응용하기 위해 좀 많이 헤맸다.


TestEnum 클래스를 만들고 여기서 StudentEnum을 사용하여 열거형의 이름과 인덱스를 구해보고자 한다.


Enum을 생성하는 방법은  클래스를 만들어서 사용하는 방법,

클래스 내부에 선언해서 사용하는 방법 등..

여러가지가 있지만 나는 Enum클래스를 따로 생성하여 실행 할 것이다.


StudentEnum.java

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
package hasA;
 
public enum StudentEnum {
    //Student Enum이 가질 열거형
    NAME(0"이름"), 
    KOR(1,"국어"), 
    ENG(2"영어"), 
    MATH(3,"수학"), 
    SUM(4"총합"), 
    AVG(5"평균");
    
    private int studentIndex;
    private String studentName;
    
    StudentEnum(int studentIndex, String subjectName) {
        this.studentIndex = studentIndex;
    }
 
    //getStudentIndex의 Getter
    public int getStudentIndex() {
        return studentIndex;
    }
 
    //getStudentName의 Getter
    public String getStudentName() {
        return studentName;
    }
}
 
cs


TestEnum.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package hasA;
 
public class TestEnum {
    
    private StudentEnum se;
    
    public void getValue() {
        
        StudentEnum[] tmpSe = this.se.values();
        
        //각각 해당하는 열거형 이름값 가져오기
        for(int i=0; i<tmpSe.length; i++) {
            System.out.println(tmpSe[i].toString());
        }
    }
    
    public static void main(String[] args) {
        
        TestEnum te = new TestEnum();
 
        te.getValue();
    }
}
 
cs

TestEnum.java에서 getValue()는 StudentEnum의 열거형 값을 가져온다.

tmpSe레퍼런스에 this.se.value()를 통해 StudentEnum의 열거형을 배열 레퍼런스로 바꿔 저장한다.

이후 for문을 돌리면서 값을 출력..


좀 더 공부해야겠다..ㅎ


반응형
반응형

/*

 * 1. 클래스 구성요소

 * 1) field : 객체 사용시 지속적으로 사용되어지는 data

 * 주로 private으로 지정 => 캡슐화목적(데이터 은닉/보호)

 * 1. instance field : 객체를 생성하고 사용할 수 있는 기능

 * 2. static field : 컴파일시에 생성되고 객체생성하지 않아도 사용할 수 있음

 * 3. final field : 상수가 아닌 값을 상수로 지정(읽기전용) -> final static으로 생성

 * 

 * 2) constructor : 객체 생성시에 자동 호출

 * 디폴트기능 : 객체등록

 * 사용자 기능 : 필드 초기화

 *

 * 1. 리턴타입 없음, 함수명이 클래스명과 똑같다

 * 2. 접근 지정자 public 주로  

 * constructor를 private으로 설정할 경우 constructor를 호출할 수 있는 static method를 생성후 외부에서 static    *                             method 호출

 * 3. 명시적으로 만들지 않을 경우 디폴트 생성자가 제공

 * 

 * 3) method : 외부와 내부 연결

 * 외부에서 객체 내부의 필드를 사용하게 해주는 기능

 * 주로 public

 * 1. instance method : 객체레퍼런스변수명.메소드명()

 * 2. static method : 클래스명.메소드명()

 * 3. final method : 오버라이딩 금지

 * 

 * final Object : 상속금지

 * 

 *  2. 접근지정자

 *  private : 외부에서 절대 접근 불가능

 *  default : 같은 패키지 내에서 사용가능

 *  protected : 외부 패키지 중 상속받은 자식까지 접근가능

 *  public : 모두 사용 가능

 */

반응형

'Programming Language > JAVA' 카테고리의 다른 글

[급여관리 프로그램(Has~A 만)  (24) 2018.07.16
[Java]Enum  (0) 2018.07.12
성적처리 프로그램(클래스 사용x)  (0) 2018.07.09
이클립스 단축키 모음  (0) 2018.07.05
<Java> 제네릭  (0) 2018.01.08
반응형

첫번째..


예제보고 그냥 따라쳐보기

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
from tkinter import *
 
        
 
window = Tk()
window.title("Calculator")
 
display = Entry(window, width=33, bg="yellow")
display.grid(row=0, column=0, columnspan=5)
 
buttonText = [
        '7''8''9''/' ,'C',
        '4''5''6''*'' ',
        '1''2''3''-'' ',
        '0''.''=''+''끝' ]
 
 
def click(key) :        
        if key == '=' :
                result = eval(display.get())
                s = str(result)
                display.insert(END, '='+s)
        elif key == '끝' :
                window.destroy()
        else :
                display.insert(END, key)
 
rowIndex = 1
colIndex = 0
 
for button_Text in buttonText :
        def process(t=button_Text) :
                click(t)
        Button(window, text=button_Text, width=5, command=process).grid(row=rowIndex, column=colIndex)
        colIndex += 1
        if colIndex>4 :
                rowIndex += 1
                colIndex = 0
 
 
       
window.mainloop()
 
cs


반응형
반응형
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
import turtle
import random
 
turtle = turtle.Turtle()
turtle.shape("turtle")
turtle.speed(0)
 
= 0
= 0
 
#사각형 그리는 변수
rectX = x-20    #사각형 시작 x좌표값
rectY = y       #사각형 시작 y좌표값
rectWidth = 40  #사각형 가로 넓이
rectHeight = 80 #사각형 세로 길이
 
triSide = rectWidth + 40 #삼각형 한 변 길이
 
def drawRectangle(t, color , x, y, width, height) :
        t.fillcolor(color)
        t.penup()
        t.goto(x, y)
        t.pendown()
        t.begin_fill()
 
        for i in range(2) : 
                t.forward(width)
                t.right(90)
                t.forward(height)
                t.right(90)
        t.end_fill()
 
def drawTriangle(t, color, x, y, side) :
        t.fillcolor(color)
        t.penup()
        t.goto(x, y)
        t.pendown()
        t.begin_fill()
 
        t.forward(side)
        t.left(120)
        t.forward(side)
        t.left(120)
        t.forward(side)
 
        t.end_fill()
        
 
        
 
drawRectangle(turtle, "brown", rectX, rectY, rectWidth, rectHeight)
drawTriangle(turtle, "green", rectX-20, y, triSide)
 
cs


반응형

+ Recent posts