-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
183 lines (158 loc) · 7.18 KB
/
Main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package cstevens_week3;
/**
* @Course: SDEV 250 ~ Java Programming I
* @Author Name: Chad Stevens
* @Assignment Name: Week 3 Assignment
* @Date: Jun 6, 2021
* @Description: Selections
*/
import static java.lang.Math.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// create an object of the Scanner
Scanner input = new Scanner(System.in);
// print selection menu
System.out.println("Please select an area to determine from"
+ "\nthe following menu choices:\n");
System.out.println("1. Determine the area of a Square");
System.out.println("2. Determine the area of a Circle");
System.out.println("3. Determine the area of a Ellipse");
System.out.println("4. Determine the area of a Pentagon");
System.out.println("5. Exit\n");
System.out.print("Choice: ");
// take input for user choice
int shape = input.nextInt();
//SWITCH CASE
switch (shape) {
// area of a square
case 1:
System.out.print("\nEnter the side of a square: ");
// take input for side of square (aSq)
int aSq = input.nextInt();
// print formula, calculate and print area
System.out.println("The formula for the area of a square is:"
+ " a^2");
System.out.println("The area of a square with side of " + aSq
+ " is: " + pow(aSq, 2) + "\n");
break;
// area of a cricle
case 2:
System.out.print("\nEnter the radius of a circle: ");
// take input for radius of circle (r)
int r = input.nextInt();
// print formula, calculate and print area
System.out.println("The formula for the area of a circle is:"
+ " Pi*r^2");
System.out.println("The area of a circle with radius of " + r
+ " is: " + PI*pow(r, 2) + "\n");
break;
// area of an ellipse
case 3:
System.out.print("\nEnter the radius 1 of an ellipse: ");
// take input for radius 1 of ellipse (aEll)
int aEll = input.nextInt();
System.out.print("Enter the radius 2 of an ellipse: ");
// take input for radius 2 of ellipse (bEll)
int bEll = input.nextInt();
// print formula, calculate and print area
System.out.println("The formula for the area of an ellipse is:"
+ " Pi*a*b");
System.out.println("The area of an ellipse with radii of "
+ aEll + " & " + bEll + " is: " + PI * (aEll * bEll)
+ "\n");
break;
// area of pentagon
case 4:
System.out.print("\nEnter the side of a pentagon: ");
// take input for side of pentagon (aPen)
int aPen = input.nextInt();
// print formula, calculate and print area
System.out.println("The formula for the area of a pentagon is:"
+ " 1/4*sqrt(5*(5+2*sqrt5)*a^2)");
System.out.println("The area of a pentagon with side of " + aPen
+ " is: "
+ (sqrt(5 * (5 + 2 * (sqrt(5)))) * pow(aPen, 2) / 4)
+ "\n");
break;
// print goodbye statement and exit program
case 5:
System.out.println("Exiting program, Goodbye.\n");
System.exit(0);
// print invalid selection statement and exit program w/error code 1
default:
System.out.println("Invalid selection. Exiting program.\n");
System.exit(1);
}
//IF ELSE
// // area of a square
// if (shape == 1) {
// System.out.print("\nEnter the side of a square: ");
//
// // take input for side of square (aSq)
// int aSq = input.nextInt();
//
// // print formula, calculate and print area
// System.out.println("The formula for the area of a square is:"
// + " a^2");
// System.out.println("The area of a square with side of " + aSq
// + " is: " + pow(aSq, 2) + "\n");
//
// // area of a circle
// } else if (shape == 2) {
// System.out.print("\nEnter the radius of a circle: ");
//
// // take input for radius of circle (r)
// int r = input.nextInt();
//
// // print formula, calculate and print area
// System.out.println("The formula for the area of a circle is:"
// + " Pi*r^2");
// System.out.println("The area of a circle with radius of " + r
// + " is: " + PI * pow(r, 2) + "\n");
//
// // area of an ellipse
// } else if (shape == 3) {
// System.out.print("\nEnter the radius 1 of an ellipse: ");
//
// // take input for radius 1 of ellipse (aEll)
// int aEll = input.nextInt();
// System.out.print("Enter the radius 2 of an ellipse: ");
//
// // take input for radius 2 of ellipse (bEll)
// int bEll = input.nextInt();
//
// // print formula, calculate and print area
// System.out.println("The formula for the area of an ellipse is:"
// + " Pi*a*b");
// System.out.println("The area of an ellipse with radii of "
// + aEll + " & " + bEll + " is: " + PI * (aEll * bEll)
// + "\n");
//
// // area of a pentagon
// } else if (shape == 4) {
// System.out.print("\nEnter the side of a pentagon: ");
//
// // take input for side of pentagon (aPen)
// int aPen = input.nextInt();
//
// // print formula, calculate and print area
// System.out.println("The formula for the area of a pentagon is:"
// + " 1/4*sqrt(5*(5+2*sqrt5)*a^2)");
// System.out.println("The area of a pentagon with side of " + aPen
// + " is: "
// + (sqrt(5 * (5 + 2 * (sqrt(5)))) * pow(aPen, 2) / 4)
// + "\n");
//
// // print goodbye statement and exit program
// } else if (shape == 5) {
// System.out.println("Exiting program, Goodbye.\n");
// System.exit(0);
//
// // print invalid selection statement and exit program w/error code 1
// } else {
// System.out.println("Invalid selection. Exiting program.\n");
// System.exit(1);
// }
} //End Main Method
} //End Class Main