Repository navigation
Expand file tree
/
Copy pathtask_6.java
More file actions
216 lines (176 loc) · 5.34 KB
/
Copy pathtask_6.java
File metadata and controls
216 lines (176 loc) · 5.34 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
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
public class task_6 {
}
abstract class Shape {
private String color;
private boolean filled;
Shape() {
System.out.println("\n[+] Shape abstract object was created");
}
Shape(String color, boolean filled) {
this.color = color;
this.filled = filled;
System.out.println("\n[+] Shape object was created");
}
// Color getter
String get_color() {
return this.color;
}
// Color setter
void set_color(String color) {
this.color = color;
System.out.println("Shape color setted as: " + this.color);
}
// Filled getter
boolean is_filled() {
return this.filled;
}
// Filled getter
void set_filled(boolean filled) {
this.filled = filled;
System.out.println("Shape filledness setted as: " + this.filled);
}
// Area getter
double get_area() {
return 0.0;
}
// Perimetr getter
double get_perimeter() {
return 0.0;
}
public String toString() {
return "Shape object: is filled: " + this.filled + ", color: " + this.color;
}
}
class Rectangle extends Shape {
protected double width;
protected double length;
Rectangle() {
super.set_color("blue");
super.set_filled(false);
System.out.println("[+] Rectangle object was created");
}
Rectangle(double width, double length) {
super.set_color("blue");
super.set_filled(false);
this.width = width;
this.length = length;
System.out.println("[+] Rectangle object was created");
}
Rectangle(double width, double length, String color, boolean filled) {
super.set_color("blue");
super.set_filled(false);
this.width = width;
this.length = length;
System.out.println("[+] Rectangle object was created");
}
// Width getter
double get_width() {
return this.width;
}
// Width setter
void set_width(double width) {
if (width > 0) {
this.width = width;
System.out.println("Rectangle width setted as: " + this.width);
} else {
System.out.println("Rectangle width must be > 0");
}
}
// Length getter
double get_length() {
return this.length;
}
// Width setter
void set_length(double length) {
if (length > 0) {
this.length = length;
System.out.println("Rectangle length setted as: " + this.length);
} else {
System.out.println("Rectangle length must be > 0");
}
}
@Override
double get_area() {
return this.length * this.width;
}
@Override
double get_perimeter() {
return 2 * (this.length + this.width);
}
@Override
public String toString() {
System.out.println(super.toString());
return "Shape: rectangle, length: " + this.length + ", width: " + this.width;
}
}
interface Movable {
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
}
class MovablePoint implements Movable {
private int x;
private int y;
private int xSpeed;
private int ySpeed;
MovablePoint(int x, int y, int xSpeed, int ySpeed) {
this.x = x;
this.y = y;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
System.out.println("\n[+] MovablePoint object was created");
}
public String toString() {
return "MovablePoint object - x: " + this.x + ", y: " + this.y + ", xSpeed: " + this.xSpeed + ", ySpeed: "
+ this.ySpeed;
}
public void moveUp() {
this.y += this.ySpeed;
System.out.println("MovablePoint object moved up by " + this.ySpeed);
}
public void moveDown() {
this.y -= this.ySpeed;
System.out.println("MovablePoint object moved down by " + this.ySpeed);
}
public void moveLeft() {
this.x -= this.xSpeed;
System.out.println("MovablePoint object moved left by " + this.xSpeed);
}
public void moveRight() {
this.x += this.xSpeed;
System.out.println("MovablePoint object moved right by " + this.xSpeed);
}
}
class MovableRectangle implements Movable {
private MovablePoint topLeft;
private MovablePoint bottomRight;
MovableRectangle(int x1, int y1, int x2, int y2, int xSpeed, int ySpeed) {
this.topLeft = new MovablePoint(x1, y1, xSpeed, ySpeed);
this.bottomRight = new MovablePoint(x2, y2, xSpeed, ySpeed);
System.out.println("[+] MovableRectangle object was created");
}
public String toString() {
return "MovableRectangle object - topLeft: " + this.topLeft + ", bottomRight: " + this.bottomRight;
}
public void moveUp() {
this.topLeft.moveUp();
this.bottomRight.moveUp();
System.out.println("MovableRectangle object moved up");
}
public void moveDown() {
this.topLeft.moveDown();
this.bottomRight.moveDown();
System.out.println("MovableRectangle object moved down");
}
public void moveLeft() {
this.topLeft.moveLeft();
this.bottomRight.moveLeft();
System.out.println("MovableRectangle object moved left");
}
public void moveRight() {
this.topLeft.moveRight();
this.bottomRight.moveRight();
System.out.println("MovableRectangle object moved right");
}
}