-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAreaCalculator.java
More file actions
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
import java.util.*;
public class AreaCalculator {
public static void main(String[] args) {
Scanner keyboard = new Scanner(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: ");
int shape = keyboard.nextInt();
System.out.println();
if (shape == 1) {
System.out.print("Base: ");
int base = keyboard.nextInt();
System.out.print("Height: ");
int height = keyboard.nextInt();
area_triangle(base, height);
} else if (shape == 2) {
System.out.print("Length: ");
int length = keyboard.nextInt();
System.out.print("Width: ");
int width = keyboard.nextInt();
area_rectangle(length, width);
} else if (shape == 3) {
System.out.print("Radius: ");
int radius = keyboard.nextInt();
area_circle(radius);
} else if (shape == 4) {
quit();
break;
}
}
keyboard.close();
}
public static double area_triangle(int base, int height) {
System.out.println();
int A = (base * height) / 2;
System.out.println("The area is " + A + ".");
return A;
}
public static int area_rectangle(int length, int width){
System.out.println();
int A = length * width;
System.out.println("The area is " + A + ".");
return A;
}
public static double area_circle(int radius) {
System.out.println();
double A = Math.PI * radius * radius;
System.out.println("The area is " + A + ".");
return A;
}
public static String quit() {
System.out.println("Good Bye");
return null;
}
}