-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
242 lines (224 loc) · 4.33 KB
/
Copy pathRectangle.java
File metadata and controls
242 lines (224 loc) · 4.33 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import java.awt.Color;
import java.awt.Graphics;
/**
* @author Furkan Ozev
* @since 17-01-2019
* Class Rectangle all implement the Shape interface.
*/
public class Rectangle implements Shape
{
private double width;
private double height;
private double posx;
private double posy;
private String color;
/***
* Total area and Total perimeter of Rectangles.
*/
private static double total_area=0;
private static double total_perimeter=0;
/**
* Default constructor
*/
Rectangle()
{
}
/**
* Constructor that take width and height.
* @param width_val width of Rectangle (double)
* @param height_val height of Rectangle (double)
*/
Rectangle(double width_val, double height_val)
{
width = width_val;
height = height_val;
add_total_area();
add_total_perimeter();
posx = 0;
posy = 0;
color = "red";
}
/**
* Constructor that take width, height, posx, posy and color.
* @param width_val width of Rectangle (double)
* @param height_val height of Rectangle (double)
* @param posx_val position x of Rectangle (double)
* @param posy_val position y of Rectangle (double)
* @param color_ color of Rectangle (String)
*/
Rectangle(double width_val, double height_val, double posx_val, double posy_val, String color_)
{
width = width_val;
height = height_val;
posx = posx_val;
posy = posy_val;
color = color_;
add_total_area();
add_total_perimeter();
}
/**
* Set width of Rectangle.
* @param width_val width of Rectangle (double)
*/
public void setwidth(double width_val)
{
width = width_val;
}
/**
* Set height of Rectangle.
* @param height_val height of Rectangle (double)
*/
public void setheight(double height_val)
{
height = height_val;
}
/**
* Set position x of Rectangle.
* @param posx_val posx of Rectangle (double)
*/
public void setposx(double posx_val)
{
posx = posx_val;
}
/**
* Set position y of Rectangle.
* @param posy_val posy of Rectangle (double)
*/
public void setposy(double posy_val)
{
posy = posy_val;
}
/**
* Set position color of Rectangle.
* @param color_val color of Rectangle (String)
*/
public void setcolor(String color_val)
{
color = color_val;
}
/**
* Get width of Rectangle.
* @return double width of Rectangle.
*/
public double getwidth()
{
return width;
}
/**
* Get height of Rectangle.
* @return double height of Rectangle
*/
public double getheight()
{
return height;
}
/**
* Get position x of Rectangle.
* @return double position x of Rectangle
*/
public double getposx()
{
return posx;
}
/**
* Get position y of Rectangle.
* @return double position y of Rectangle
*/
public double getposy()
{
return posy;
}
/**
* Get color of Rectangle.
* @return String color of Rectangle
*/
public String getcolor()
{
return color;
}
/**
* Add shape area to total area.
*/
public void add_total_area()
{
total_area += (width*height);
}
/**
* Add shape perimeter to total perimeter.
*/
public void add_total_perimeter()
{
total_perimeter += (2*(width+height));
}
/**
* Static function.
* @return double total area of Rectangles
*/
public static double get_total_area()
{
return total_area;
}
/**
* Static function.
* @return double total perimeter of Rectangles
*/
public static double get_total_perimeter()
{
return total_perimeter;
}
/*
* @see Shape#area()
*/
public double area()
{
return width*height;
}
/*
* @see Shape#perimeter()
*/
public double perimeter()
{
return (width+height)*2;
}
/*
* @see Shape#increment()
*/
public void increment()
{
posx++;
posy++;
}
/*
* @see Shape#decrement()
*/
public void decrement()
{
if(posx-1>= 0 && posy-1>= 0)
{
posx--;
posy--;
}
}
/*
* @see Shape#compareTo(Shape)
*/
public int compareTo( final Shape o)
{
if(area() > o.area()) return 1;
else if(area() < o.area()) return -1;
else return 0;
}
/*
* @see Shape#Draw(java.awt.Graphics)
*/
public void Draw(Graphics o)
{
PolygonDyn p = new PolygonDyn(this);
if(color == "green") o.setColor(Color.GREEN);
else if(color == "red") o.setColor(Color.RED);
else if(color == "blue") o.setColor(Color.BLUE);
else if(color == "yellow") o.setColor(Color.YELLOW);
else if(color == "pink") o.setColor(Color.PINK);
o.fillPolygon(p.getx(), p.gety(), p.get_size());
}
}