-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp4.java
More file actions
35 lines (34 loc) · 1.21 KB
/
Copy pathp4.java
File metadata and controls
35 lines (34 loc) · 1.21 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
/*Write a program to design a class AreaCalculation and
then find out the area (using method overloading) of a circle whose
radius is 7cm, area of rectangle whose length is 4.5cm and breadth
is 4cm and also the area of cuboid whose length, breadth & height
are 3cm, 2cm & 4cm respectively.*/
class AreaCalculation {
float area;
float r;
float length;
float breadth;
float height;
void area(float r) {
area = 3.14f * r * r;
System.out.println("Area of circle: " + area + " sq. cm.");
}
void area(float length, float breadth) {
area = length * breadth;
System.out.println("Area of rectangle: " + area + " sq. cm.");
}
void area(float length, float breadth, float height) {
area = 2 * ((length * breadth) + (breadth * height) + (height * length));
System.out.println("Area of cuboid: " + area + " sq. cm.");
}
}
public class p4 {
public static void main(String[] args) {
AreaCalculation circle = new AreaCalculation();
circle.area(7f);
AreaCalculation rectangle = new AreaCalculation();
rectangle.area(4.5f, 4f);
AreaCalculation cuboid = new AreaCalculation();
cuboid.area(3f, 2f, 4f);
}
}