-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava076_class.java
More file actions
63 lines (54 loc) · 1.16 KB
/
Copy pathJava076_class.java
File metadata and controls
63 lines (54 loc) · 1.16 KB
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
package java0829_class;
/*
* 출력결과를 참조하여 process()메소드를 구현하시오.
*
* [출력결과]
* 10 + 5 = 15
* 3 * 2 = 6
*/
class Calc {
int first;
int second;
char ope;
public Calc() {
}
public Calc(int first, int second, char ope) {
this.first = first;
this.second = second;
this.ope = ope;
}
public int process() {
// 여기를 구현하세요.////////////////
switch (ope) {
case '+':
return first + second;
case '-':
return first - second;
case '*':
return first * second;
case '/':
return first / second;
case '%':
return first % second;
}
return 0;
}// end process()
public void prn() {
System.out.printf("%2d %c %2d = %d\n", first, ope, second, process());
}// end prn()
}// end Calc
public class Java076_class {
public static void main(String[] args) {
Calc[] nfo = new Calc[2];
// 여기를 구현하세요/////////////
nfo[0] = new Calc(10, 5, '+');
nfo[1] = new Calc(3, 2, '*');
/////////////////////
display(nfo);
}// end main( )
public static void display(Calc[] nfo) {
for (int i = 0; i < nfo.length; i++) {
nfo[i].prn();
}
}// end display()
}// end class