forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance with superkey
235 lines (176 loc) · 4.87 KB
/
inheritance with superkey
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
class simplegeo
{
private String colour="white";
// private java.util.Date dlcrated;
private boolean filled;
public simplegeo(boolean f){
this.filled=true;
}
/* public simplegeo(String k)
{
this.colour=k;
}*/
public boolean getbol()
{
return filled;
}
public void setbol(boolean s)
{
this.filled=s;
}
public String getString()
{
return colour;
}
public void setstring(String s)
{
this.colour=s;
}
/* public void setdate(java.util.Date d)
{
this.dlcrated=d;
}
public java.util.Date getdate()
{
return dlcrated;
}*/
}
class circle extends simplegeo
{
private double radius;
public circle(boolean f,int r){
super(f);
this.radius=r;
}
public double getrad()
{
return radius;
}
public void setrad(double a)
{
this.radius=a;
}
public double rarea()
{
return (radius*radius)*3.14;
}
public double rperi()
{
return 2*radius;
}
}
class rectangle extends simplegeo
{
private int length;
private int width;
public rectangle(boolean f,int l,int w)
{
super(f);
this.length=l;
this.width=w;
}
public int getlength()
{
return length;
}
public void setlength(int x)
{
this.length=x;
}
public int getwidth()
{
return width;
}
public void setwidth(int y)
{
this.width=y;
}
public int getarea()
{
return (length*width);
}
public int getperirec()
{
return 2*(length+width);
}
}
class square extends simplegeo
{
private int edge;
public square(boolean f,int ed)
{
super(f);
this.edge=ed;
}
public int getedge()
{
return edge;
}
public void setedeg(int t)
{
this.edge=t;
}
public int getsarea()
{
return edge*edge;
}
public int getsperi()
{
return 4*edge;
}
}
class inheritance
{
public static void main(String[] args)
{
//the main object is call name is simplegeo
System.out.println("the main class simplegeo \n");
simplegeo obj1=new simplegeo(false);
//obj1.setstring("white");
System.out.println("the now colour is "+obj1.getString());
//obj1.setdate(31/3/15);
//System.out.println("the new date is right now "+obj1.getdate());
// obj1.setbol(true);
System.out.println("now,check the value of the it's filled or not and at least last we get our result "+obj1.getbol());
System.out.println("\n");
// --------------------------------
//the next object is call name is circle
System.out.println("the second class circle \n");
circle obj2=new circle(true,12);
//obj2.setrad(5.3);
System.out.println("the radius value is currently is "+obj2.getrad());
System.out.println("the area of the circle is "+obj2.rarea());
System.out.println("the prime is that is "+obj2.rperi());
//obj2.setbol(true);
System.out.println("your object is filled or not "+obj2.getbol());
obj2.setstring("blue");
System.out.println("now, your object is filled with the colour "+obj2.getString());
System.out.println("\n");
//-----------------------------------
System.out.println("the third class rectangle \n");
rectangle obj3 = new rectangle(false,12,14);
// obj3.setlength(12);
//obj3.setwidth(14);
System.out.println("the value of the length is "+obj3.getlength());
System.out.println("the value of the width is "+obj3.getwidth());
System.out.println("the area of this rectangle is "+obj3.getarea());
System.out.println("the peri of this rectangle is "+obj3.getperirec());
obj3.setbol(false);
System.out.println("your object is filled or not "+obj3.getbol());
//obj2.setstring("blue");
System.out.println("now, your object is filled with the colour "+obj3.getString());
System.out.println("\n");
//-----------------------------------
System.out.println("the third class rectangle \n");
square obj4 = new square(false,18);
// obj4.setedeg(10);
System.out.println("the value of the edge is "+obj4.getedge());
System.out.println("the area of this rectangle is "+obj4.getsarea());
System.out.println("the peri of this rectangle is "+obj4.getsperi());
//obj4.setbol(true);
System.out.println("your object is filled or not "+obj4.getbol());
obj4.setstring("red");
System.out.println("now, your object is filled with the colour "+obj4.getString());
System.out.println("\n");
}
}