-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculate.java
68 lines (67 loc) · 1.4 KB
/
Calculate.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
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
import java.util.Scanner;
class Add{
private int a;
private int b;
public void SetValue(int a, int b) {
this.a = a;
this.b = b;
}
public int calculate() {return a + b;}
}
class Sub{
private int a;
private int b;
public void SetValue(int a, int b) {
this.a = a;
this.b = b;
}
public int calculate() {return a - b;}
}
class Mul{
private int a;
private int b;
public void SetValue(int a, int b) {
this.a = a;
this.b = b;
}
public int calculate() {return a * b;}
}
class Div{
private int a;
private int b;
public void SetValue(int a, int b) {
this.a = a;
this.b = b;
}
public int calculate() {return a / b;}
}
public class Calculate {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.print("두 정수와 연산자를 입력하시오>>");
int a = sc.nextInt();
int b = sc.nextInt();
String c = sc.next();
if(c.equals("+")) {
Add add = new Add();
add.SetValue(a, b);
System.out.println(add.calculate());
}
if(c.equals("-")) {
Sub sub = new Sub();
sub.SetValue(a, b);
System.out.println(sub.calculate());
}
if(c.equals("*")) {
Mul mul = new Mul();
mul.SetValue(a, b);
System.out.println(mul.calculate());
}
if(c.equals("/")) {
Div div = new Div();
div.SetValue(a, b);
System.out.println(div.calculate());
}
sc.close();
}
}