-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynShapes.java
More file actions
82 lines (69 loc) · 1.79 KB
/
DynShapes.java
File metadata and controls
82 lines (69 loc) · 1.79 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
class TwoDShape{
private double width;
private double height;
private String name;
TwoDShape(){
width = height = 0.0;
name = "none";
}
TwoDShape(double w, double h, String n){
width = w;
height = h;
name = n;
}
TwoDShape(double x, String n){
width = x;
height = x;
name = n;
}
TwoDShape(TwoDShape ob){
width = ob.width;
height = ob.height;
name = ob.name;
}
double getWidth(){return width;}
double getHeight(){return height;}
void setWidth(double w){width = w};
void setHeight(double h){height = h};
void showDim(){
System.out.println(width + height);
}
double area(){
System.out.println("O");
return 0.0;
}
}
class Triangle extends TwoDShape{
private String style;
Triangle(String s, double w, double h){
super(w, h, "triangle");
style = s;
}
Triangle(double x ){
super(x, "triangle");
style = "filled";
}
double area(){
return getWidth() * getHeight() /2;
}
void showStyle(){
System.out.println(style);
}
}
class DynShapes{
public static void main(String[] args){
TwoDShape[] shapes = new TwoDShape[5];
shapes[0] = new Triangle("outlined", 8, 12);
// Triangle t1 = new Triangle();
// Triangle t2 = new Triangle();
// t1.width = 4;
// t1.style = "filled";
// t1.height = 4;
// t2.width = 8;
// t2.style = "outlined";
// t2.height = 8;
// System.out.println(t1.area());
// t2.showDim();
System.out.println(shapes[0].area());
}
}