-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.java
More file actions
96 lines (93 loc) · 3.35 KB
/
UI.java
File metadata and controls
96 lines (93 loc) · 3.35 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
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
import java.math.BigDecimal;
import java.util.Scanner;
import java.io.IOException;
public class UI {
Scanner sc = new Scanner(System.in);
Compute compute = new Compute();
Memory memory = new Memory();
BigDecimal i = BigDecimal.ZERO;
public void print(String number) throws IOException {
boolean continueor = true;
while (continueor) {
System.out.print("計算したい数字を入力してください");
if (memory.getmemory() == 0) {
i = sc.nextBigDecimal();
sc.nextLine();
} else {
i = memory.getResult();
System.out.print("前回の内容を引き継ぎます");
}
System.out.print("どの計算をしたいですか?");
System.out.print("1:引き算 2:足し算 3: 割り算 4:掛け算 5: 二乗");
int or = sc.nextInt();
sc.nextLine();
switch (or) {
case 1:
System.out.print("引きたい数を教えてください(複数入力可)");
sc.nextLine();
String numbers1 = sc.nextLine();
BigDecimal result1 = compute.Subtraction(numbers1, i);
System.out.println(
result1.stripTrailingZeros().toPlainString()
);
memory.setResult(result1);
break;
case 2:
System.out.print("足したい数を教えてください(複数入力可)");
sc.nextLine();
String numbers2 = sc.nextLine();
BigDecimal result2 = compute.Add(numbers2, i);
System.out.println(
result2.stripTrailingZeros().toPlainString()
);
memory.setResult(result2);
break;
case 3:
System.out.print("割りたい数を教えてください(複数入力可)");
sc.nextLine();
String numbers3 = sc.nextLine();
System.out.print("下千桁しか扱いません");
BigDecimal result3 = compute.division(numbers3, i);
System.out.println(
result3.stripTrailingZeros().toPlainString()
);
memory.setResult(result3);
break;
case 4:
System.out.print("掛けたい数を教えてください(複数入力可)");
sc.nextLine();
String numbers4 = sc.nextLine();
BigDecimal result4 = compute.Multiplication(numbers4, i);
System.out.println(
result4.stripTrailingZeros().toPlainString()
);
memory.setResult(result4);
break;
case 5:
System.out.print("何回二乗しますか?");
sc.nextLine();
int number5 = sc.nextInt();
BigDecimal result5 = compute.squared(number5, i);
System.out.println(
result5.stripTrailingZeros().toPlainString()
);
memory.setResult(result5);
break;
}
System.out.print("計算結果を保存し、続けますか? yes or no");
sc.nextLine();
String continueChoice = sc.nextLine();
if (continueChoice.contains("yes")) {
continueor = true;
} else {
System.out.print("終了します");
continueor = false;
break;
}
}
}
public static void main(String[] args) throws IOException {
UI ui = new UI();
ui.print("");
}
}