-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometry.java
More file actions
91 lines (68 loc) · 1.83 KB
/
Copy pathGeometry.java
File metadata and controls
91 lines (68 loc) · 1.83 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
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
import java.util.Scanner;
public class Geometry {
public static void main(String[] args) {
Square s = new Square();
Rectangle r = new Rectangle();
Circle c = new Circle();
s.acceptInput();
s.compute();
s.disp();
r.acceptInput();
r.compute();
r.disp();
c.acceptInput();
c.compute();
c.disp();
}
}
// rectangle class
class Rectangle {
float length;
float breadth;
float area;
public void acceptInput() {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER THE LENGTH OF RECTANGLE : ");
length = sc.nextFloat();
System.out.println("ENTER THE BREADTH OF RECTANGLE : ");
breadth = sc.nextFloat();
}
public void compute() {
area = length * breadth;
}
public void disp() {
System.out.println("THE AREA OF RECTANGLE IS : " + area);
}
}
// square class
class Square {
float length;
float area;
public void acceptInput() {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER THE LENGTH OF SQUARE : ");
length = sc.nextFloat();
}
public void compute() {
area = length * length;
}
public void disp() {
System.out.println("THE AREA OF SQUARE IS : " + area);
}
}
// circle class
class Circle {
float radius;
float area;
public void acceptInput() {
Scanner sc = new Scanner(System.in);
System.out.println("ENTER THE RADIUS OF CIRCLE : ");
radius = sc.nextFloat();
}
public void compute() {
area = 3.14f * radius * radius;
}
public void disp() {
System.out.println("THE AREA OF CIRCLE IS : " + area);
}
}