-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHui.java
More file actions
61 lines (30 loc) · 1.24 KB
/
Copy pathHui.java
File metadata and controls
61 lines (30 loc) · 1.24 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
import java.util.Scanner;
public class Hui {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Calculate an area of a rectangle or circle (r/c)?\nx to exit");
String choice = sc.nextLine();
if (choice.equals("r")) {
System.out.println("Width?");
double width = Double.parseDouble(sc.nextLine());
System.out.println("Length?");
double length = Double.parseDouble(sc.nextLine());
double res = Calculation.calcArea(width, length);
System.out.println(res);
System.out.printf("Formatted: %.2f \n", res);
}
else if (choice.equals("c")) {
System.out.println("Radius?");
double r = Double.parseDouble(sc.nextLine());
double res = Calculation.calcArea(r);
System.out.println(res);
System.out.printf("Formatted output: %.2f \n", res);
}
else if (choice.equals("x"))
break;
else
System.out.println("Unknown choice. Please try again.");
}
}
}