-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathShapes.java
75 lines (57 loc) · 1.48 KB
/
Shapes.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
package OOPS.Examples;
import java.util.*;
public class Shapes {
public int setArea(int Height, int Base) {
int Area = Height * Base/2;
return Area;
}
public int setArea(int Side) {
int Area = Side*Side;
return Area;
}
public double setArea(double Pie, int Radius) {
double Area = Pie*Radius*Radius;
return Area;
}
}
class Triangle extends Shapes{
int Height;
int Base;
void getInputs() {
System.out.print("Enter height of the triangle:");
Scanner s = new Scanner(System.in);
Height = s.nextInt();
System.out.print("Enter base of the triangle:");
Base = s.nextInt();
System.out.println("The Area of Triangle is: "+setArea(Height,Base));
}
}
class Square extends Shapes{
int Side;
void getInputs(){
System.out.print("\n\nEnter side of the square:");
Scanner sc = new Scanner(System.in);
Side = sc.nextInt();
System.out.println("The Area of Square is: "+setArea(Side));
}
}
class Circle extends Shapes{
int Radius;
double Pie = Math.PI;
void getInputs() {
System.out.print("\n\nEnter radius of the circle:");
Scanner sc1 = new Scanner(System.in);
Radius = sc1.nextInt();
System.out.println("The Area of Circle is: "+String.format("%.2f",setArea(Pie,Radius)));
}
}
class Tester{
public static void main(String args[]) {
Triangle triangle = new Triangle();
Square square = new Square();
Circle circle = new Circle();
triangle.getInputs();
square.getInputs();
circle.getInputs();
}
}