-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometry.java
268 lines (140 loc) · 5.08 KB
/
Geometry.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//Captain-Price-TF-141
import java.util.Scanner;
/**
* This program demonstrates static methods
*/
public class Geometry
{
public static void main(String[] args)
{
int choice; // The user's choice
double value = 0; // The method's return value
char letter; // The user's Y or N decision
double radius; // The radius of the circle
double length; // The length of the rectangle
double width; // The width of the rectangle
double height; // The height of the triangle
double base; // The base of the triangle
double side1; // The first side of the triangle
double side2; // The second side of the triangle
double side3; // The third side of the triangle
// Create a scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);
// The do loop allows the menu to be displayed first do
System.out.println("");
do
{
// TASK #1 Call the printMenu method
printMenu();
choice = keyboard.nextInt();
switch (choice)
{
case 1:
System.out.print("Enter the radius of the circle: ");
radius = keyboard.nextDouble();
// TASK #3 Call the circleArea method and store the result in the value variable
value = circleArea(radius);
System.out.println("The area of the circle is " + value);
break;
case 2:
System.out.print("Enter the height of the triangle: ");
height = keyboard.nextDouble();
System.out.print("Enter the base of the triangle: ");
base = keyboard.nextDouble();
// TASK #3 Call the triangleArea method and store the result in the value variable
value = triangleArea(base, height);
System.out.println("The area of the triangle is " + value);
break;
case 3:
System.out.print("Enter the radius of the circle: ");
radius = keyboard.nextDouble();
// TASK #3 Call the circumference method and store the result in the value variable
value = circleCircumference(radius);
System.out.println("The circumference of the circle is " + value);
break;
case 4:
System.out.print("Enter the length of side 1 of the triangle: ");
side1 = keyboard.nextDouble();
System.out.print("Enter the length of side 2 of the triangle: ");
side2 = keyboard.nextDouble();
System.out.print("Enter the length of side 3 of the triangle: ");
side3 = keyboard.nextDouble();
// TASK #3 Call the perimeter method and store the result in the value variable
value = trianglePerimeter(side1, side2, side3);
System.out.println("The perimeter of the triangle is " + value);
break;
case 5:
System.exit(0);
break;
default:
System.out.println("You did not enter a valid choice.");
}
}
while (true);
}
// TASK #1 Create the printMenu method here
public static void printMenu() // Menu Selection
{
System.out.println("This is a Geometry calculator");
System.out.println("Choose what you would like to calculate\n");
System.out.println(" 1. Find the area of circle");
System.out.println(" 2. Find the area of triangle");
System.out.println(" 3. Find the circumference of circle");
System.out.println(" 4. Find the perimeter of triangle");
System.out.println(" 5. Exit");
}
// TASK #2 Create the value-returning methods here
// TASK #4 Write javadoc comments for each method
/**
* @param radius
* @return circleArea of type double
*/
public static double circleArea(double radius)
{
return Math.PI * radius * radius;
}
/**
* @param base,
* height
* @return triangleArea of type double
*/
public static double triangleArea(double base, double height)
{
return 0.5 * base * height;
}
/**
* @param length,
* width
* @return rectangleArea of type double
*/
public static double rectangleArea(double length, double width)
{
return length * width;
}
/**
* @param radius
* @return circleCircumference of type double
*/
public static double circleCircumference(double radius)
{
return 2 * Math.PI * radius;
}
/**
* @param length,
* width
* @return rectanglePerimeter of type double
*/
public static double rectanglePerimeter(double length, double width)
{
return 2 * (length + width);
}
/**
* @param side1,
* side2, side3
* @return trianglePerimeter of type double
*/
public static double trianglePerimeter(double side1, double side2, double side3)
{
return side1 + side2 + side3;
}
}