-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5.java
More file actions
39 lines (31 loc) · 1.17 KB
/
Lab5.java
File metadata and controls
39 lines (31 loc) · 1.17 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
class Geometry {
// Area of a circle
double calculateArea(double radius) {
return Math.PI * radius * radius;
}
// Area of a rectangle
double calculateArea(double length, double breadth) {
return length * breadth;
}
// Area of a square
int calculateArea(int side) {
return side * side;
}
// Area of a triangle
double calculateArea(double base, double height, char ch) {
return 0.5 * base * height;
}
}
public class Lab5 {
public static void main(String[] args) {
Geometry g = new Geometry();
// Calculate and print the area of a circle with radius 5
System.out.println("Area of Circle: " + g.calculateArea(5.0));
// Calculate and print the area of a rectangle with length 4 and breadth 6
System.out.println("Area of Rectangle: " + g.calculateArea(4, 6));
// Calculate and print the area of a square with side 3
System.out.println("Area of Square: " + g.calculateArea(3));
// Calculate and print the area of a triangle with base 4 and height 7
System.out.println("Area of Triangle: " + g.calculateArea(4, 7, 't'));
}
}