-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeArea.java
75 lines (65 loc) · 2.09 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
import java.util.Scanner;
public class ShapeArea {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int choice;
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 = computerTriangleArea(b, h);
System.out.println("The area is " + area);
}
else if ( choice == 2 ) {
System.out.print("\nRadius: ");
int radius = keyboard.nextInt();
area = computerCircleArea(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 " + computerRectangleArea(q, w) );
}
else if ( choice == 4 ) {
System.out.print("\nSide: ");
int s = keyboard.nextInt();
System.out.println("The area is " +computerSquareArea(s) );
}
else if ( choice != 5 ) {
System.out.println("ERROR.");
}
} while ( choice != 5 );
}
public static double computerTriangleArea( int base, int height ) {
double A;
A = 0.5 * base * height;
return A;
}
public static double computerCircleArea( int radius ) {
double A;
A = Math.PI * radius * radius;
return A;
}
public static int computerRectangleArea( int length, int width ) {
return (length * width);
}
public static int computerSquareArea( int side ) {
return (side * side);
}
}