- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassPolygon.java
More file actions
Latest commit
46 lines (37 loc) · 948 Bytes
/
Copy pathclassPolygon.java
File metadata and controls
46 lines (37 loc) · 948 Bytes
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
importjava.util.*;
publicclassclassPolygon {
protectedintsides;
classPolygon(ints){
sides = s;
}
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
ints = sc.nextInt();
PolygonSquaresq = newPolygonSquare();
PolygonTriangletr = newPolygonTriangle();
classPolygonp = newclassPolygon(s);
sq.draw();
tr.draw();
p.draw();
sc.close();
}
publicvoiddraw(){
if(sides == 4){
System.out.println("Square has 4 sides");
}elseif(sides == 3){
System.out.println("Triangle has 3 sides");
}else{
System.out.println("Polygon of " + sides + " sides");
}
}
}
classPolygonSquareextendsclassPolygon{
PolygonSquare(){
super(4);
}
}
classPolygonTriangleextendsclassPolygon{
PolygonTriangle(){
super(3);
}
}