-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprac3_1.java
133 lines (126 loc) · 3.18 KB
/
prac3_1.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
abstract class GeometricObject
{
public String Color="Blue";
public boolean filled;
public java.util.Date dateCreated;
public GeometricObject(){
dateCreated=new java.util.Date();
}
public GeometricObject(String color,boolean filled)
{
this.Color=color;
this.filled=filled;
}
public String getcolor(){
return Color;
}
public void setcolor()
{
this.Color = Color;
}
public boolean isfilled()
{
return filled;
}
public java.util.Date getDateCreated()
{
return dateCreated;
}
public abstract double getArea();
public abstract double getprimeter();
}
class Circle extends GeometricObject
{
double radius;
Circle()
{
}
Circle(double radius)
{
this.radius=radius;
}
public double getRadius()
{
return radius;
}
public void setradius(double radius)
{
this.radius=radius;
}
public double getDiameter()
{
return 2*radius;
}
public double getArea()
{
return Math.PI*radius*radius;
}
public double getPerimeter()
{
return 2*radius*Math.PI;
}
@Override
public double getprimeter() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class Rectangle extends GeometricObject
{
double width;
double height;
Rectangle()
{
}
Rectangle(double width,double height)
{
this.width=width;
this.height=height;
}
Rectangle(double width,double height,String color,boolean filled)
{
super(color,filled);
this.width = width;
this.height = height;
}
public double getWidth()
{
return width;
}
public double getheight()
{
return height;
}
public void setWidth(double width){
this.width = width;
}
public void setHeight(double height){
this.height = height;
}
public double getArea()
{
return height*width;
}
public double getperimeter()
{
return 2*(width+height);
}
@Override
public double getprimeter() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
public class prac3_1{
public static void main(String[] args)
{
Rectangle Rec = new Rectangle(28,31);
Circle cir = new Circle(31);
System.out.println("----------Class Circle----------");
System.out.println("Area of Circle: "+cir.getArea());
System.out.println("Area of Perimeter: "+cir.getPerimeter());
System.out.println("Diameter of Circle: "+cir.getDiameter());
System.out.println("-----------------------------------");
System.out.println("----------Class Rentangle----------");
System.out.println("Area of Rentangle: "+Rec.getArea());
System.out.println("Area of Perimeter: "+Rec.getperimeter());
}
}