- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAreaCalculator.java
More file actions
Latest commit
84 lines (63 loc) · 1.88 KB
/
Copy pathAreaCalculator.java
File metadata and controls
84 lines (63 loc) · 1.88 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
importjava.util.*;
publicclassAreaCalculator {
publicstaticvoidmain(String[] args) {
Scannerkeyboard = newScanner(System.in);
System.out.println("Shape Area Calculator");
while(true) {
System.out.println();
System.out.println("-=-=-=-=-=-=-=-=-=-");
System.out.println();
System.out.println("1) Triangle");
System.out.println("2) Rectangle");
System.out.println("3) Circle");
System.out.println("4) Quit");
System.out.println();
System.out.print("Which shape: ");
intshape = keyboard.nextInt();
System.out.println();
if (shape == 1) {
System.out.print("Base: ");
intbase = keyboard.nextInt();
System.out.print("Height: ");
intheight = keyboard.nextInt();
area_triangle(base, height);
} elseif (shape == 2) {
System.out.print("Length: ");
intlength = keyboard.nextInt();
System.out.print("Width: ");
intwidth = keyboard.nextInt();
area_rectangle(length, width);
} elseif (shape == 3) {
System.out.print("Radius: ");
intradius = keyboard.nextInt();
area_circle(radius);
} elseif (shape == 4) {
quit();
break;
}
}
keyboard.close();
}
publicstaticdoublearea_triangle(intbase, intheight) {
System.out.println();
intA = (base * height) / 2;
System.out.println("The area is " + A + ".");
returnA;
}
publicstaticintarea_rectangle(intlength, intwidth){
System.out.println();
intA = length * width;
System.out.println("The area is " + A + ".");
returnA;
}
publicstaticdoublearea_circle(intradius) {
System.out.println();
doubleA = Math.PI * radius * radius;
System.out.println("The area is " + A + ".");
returnA;
}
publicstaticStringquit() {
System.out.println("Good Bye");
returnnull;
}
}