-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeArea.java
78 lines (68 loc) · 1.98 KB
/
ShapeArea.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
69
70
71
72
73
74
75
76
77
78
import java.util.Scanner;
public class ShapeArea {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int choice, square;
double area = 0;
System.out.print("Shape Area Calculator version 0.1");
System.out.println(" (c) 2015 LJtHW Sample Output, Inc.");
do {
System.out.println("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
System.out.println("1) Triangle");
System.out.println("2) Circle");
System.out.println("3) Rectangle");
System.out.println("4) Square");
System.out.println("5) Quit");
System.out.print("> ");
choice = keyboard.nextInt();
if ( choice == 1) {
System.out.print("\nBase: ");
int b = keyboard.nextInt();
System.out.print("Height:");
int h = keyboard.nextInt();
area = computeTriangleArea(b, h);
System.out.println("The area is " + area);
}
else if (choice == 2) {
System.out.print("\nRadius: ");
int radius = keyboard.nextInt();
area = computeCircleArea(radius);
System.out.println("The area is " + area);
}
else if (choice == 3 ) {
System.out.print("\nLength: " );
int q = keyboard.nextInt();
System.out.print("Width: ");
int w = keyboard.nextInt();
System.out.println("The area is " + computeRectangleArea (q, w) );
}
else if (choice == 4) {
System.out.print("\nSide Length: ");
int side = keyboard.nextInt();
square = computeSquareArea(side);
System.out.println("The area is " + square);
}
else if (choice != 5) {
System.out.println("ERROR.");
}
} while (choice != 5 );
}
public static double computeTriangleArea( int base, int height) {
double A;
A = 0.5 * base * height;
return A;
}
public static double computeCircleArea (int radius) {
double A;
A = Math.PI * radius * radius;
return A;
}
public static int computeRectangleArea( int length, int width ) {
return (length * width);
}
public static int computeSquareArea( int side) {
int A;
A = side * side;
return A;
}
}