Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
165 lines (119 loc) · 3.36 KB

File metadata and controls

165 lines (119 loc) · 3.36 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
abstract class Abstract_TwoDShape {
private double width;
private double height;
private String name;
// A default constructor
public Abstract_TwoDShape() {
width = height = 0.0;
name = "none";
}
// Parameterized constructor.
Abstract_TwoDShape(double w, double h, String n){
width = w;
height = h;
name = n;
}
// Construct object with equal width and height.
Abstract_TwoDShape(double x, String n){
width = height = x;
name = n;
}
// Construct an object from an object.
Abstract_TwoDShape(Abstract_TwoDShape ob){
width = ob.width;
height = ob.height;
name = ob.name;
}
// Accessor methods for width and height.
double getWidth() {
return width;
}
double getHeight() {
return height;
}
void setWidth(double w) {
width = w;
}
void setHeight(double h) {
height = h;
}
String getName() {
return name;
}
void showDim() {
System.out.println("Width and height are " + width + " and " + height);
}
// declare an abstract method
abstract double area();
}
class Triangle_extends_abstract_superclass2 extends Abstract_TwoDShape {
private String styleString;
// A default constructor
public Triangle_extends_abstract_superclass2() {
// TODO Auto-generated constructor stub
super();
styleString = "none";
}
// Constructor for Triangle
Triangle_extends_abstract_superclass2(String s, double w, double h){
super(w, h, "triangle");
styleString = s;
}
// One argument constructor.
Triangle_extends_abstract_superclass2(double x){
super(x, "triangle"); // call superclass constructor
styleString = "filled";
}
// Construct an object from an object.
Triangle_extends_abstract_superclass2(Triangle_extends_abstract_superclass2 ob){
super(ob); // pass object to TwoDShape constructor
styleString = ob.styleString;
}
double area() {
return getWidth() * getHeight() / 2;
}
void showStyle() {
System.out.println("Triangle is " + styleString);
}
}
class Rectangle_extends_abstract_superclass2 extends Abstract_TwoDShape {
// A default constructor
public Rectangle_extends_abstract_superclass2() {
// TODO Auto-generated constructor stub
super();
}
// Constructor for Rectangle
Rectangle_extends_abstract_superclass2(double w, double h){
super(w, h, "rectangle"); // Call superclass constructor
}
// Construct a square
Rectangle_extends_abstract_superclass2(double x) {
super(x, "rectangle"); // call superclass constructor
}
// Construct an object from an object.
Rectangle_extends_abstract_superclass2(Rectangle_extends_abstract_superclass2 ob){
super(ob); // pass object to TwoDShape constructor.
}
boolean isSquare() {
if ( getWidth() == getHeight() )
return true;
return false;
}
double area() {
return getWidth() * getHeight();
}
}
public class Abstract_Class {
public static void main(String[] args) {
Abstract_TwoDShape shapes[] = new Abstract_TwoDShape[4];
shapes[0] = new Triangle_extends_abstract_superclass2("outlined", 8.0, 12.0);
shapes[1] = new Rectangle_extends_abstract_superclass2(10);
shapes[2] = new Rectangle_extends_abstract_superclass2(10, 4);
shapes[3] = new Triangle_extends_abstract_superclass2(7.0);
for (int i = 0; i < shapes.length; i++) {
System.out.println("Object is " + shapes[i].getName());
System.out.println("Area is " + shapes[i].area());
System.out.println();
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.