-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArea.java
More file actions
63 lines (55 loc) · 1.68 KB
/
Area.java
File metadata and controls
63 lines (55 loc) · 1.68 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
/*
* Area.java
* Name: Leah Benitez
* Desc: This program implements area functions/method
* Date: 3/12/19
*/
import java.util.Scanner;
public class Area {
static Scanner scnr = new Scanner(System.in);
/*
* RectArea: int
* Parameters: width, length
* Calculates rectangle area
*/
public static int RectArea(int width, int length) {
return width * length;
}
/*
* CircleArea: double
* Parameter: radius
* Calculates circle area
*/
public static double CircleArea(double radius) {
return (Math.PI * Math.pow(radius, 2));
}
/*
* RectArea: double
* Parameters: base, height
* Calculates triangle area
*/
public static double TriArea(double base, double height) {
return (base * height) / 2;
}
public static void main(String[] args) {
System.out.println("Let's calculate the area of a rectangle");
System.out.println("Enter width:");
int width = scnr.nextInt();
System.out.println("Enter length:");
int length = scnr.nextInt();
int areaRect = RectArea(width, length);
System.out.println("The area is " + areaRect + "\n");
System.out.println("Let's calculate the area of a circle");
System.out.println("Enter radius:");
double radius = scnr.nextInt();
double areaCirc = CircleArea(radius);
System.out.println("The area is " + areaCirc + "\n");
System.out.println("Let's calculate the area of a triangle");
System.out.println("Enter base:");
double base = scnr.nextDouble();
System.out.println("Enter height:");
double height = scnr.nextDouble();
double areaTri = TriArea(base, height);
System.out.println("The area is " + areaTri + "\n");
}
}