-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFiguren.java
154 lines (128 loc) · 3.48 KB
/
Figuren.java
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
abstract class Figure
{
protected float x;
protected float y;
Figure()
{
this.x = 0;
this.y = 0;
}
Figure(float x, float y)
{
this.x = x;
this.y = y;
}
public float getX()
{
return x;
}
public float getY()
{
return y;
}
public void print()
{
System.out.println("X: " + x + " Y: " + y);
}
}
interface MobileObject
{
public void move(float x, float y);
public void increase(float x);
public void decreade(float y);
}
class Rectangle extends Figure implements MobileObject
{
private float width;
private float height;
Rectangle()
{
super();
this.width = 0;
this.height = 0;
}
Rectangle(float x, float y, float width, float height)
{
super(x, y);
this.height = height;
this.width = width;
}
public float getHeight()
{
return height;
}
public float getWidth()
{
return width;
}
@Override
public void print()
{
super.print();
System.out.println("Höhe: " + height + " Breite: " + width);
}
public void move(float x, float y)
{
this.x = x;
this.y = y;
}
public void increase(float inc)
{
width = width * inc;
height = height * inc;
}
public void decreade(float dec)
{
width = width / dec;
height = height / dec;
}
public void relation(Rectangle rectangle)
{
if((x==rectangle.x) && (y==rectangle.y) && (width==rectangle.width) && (height==rectangle.height))
{
System.out.println("same");
}
if((x>=rectangle.x && y>=rectangle.y) && ((((x+width)<=(rectangle.x+rectangle.width)) && ((y+height)< (rectangle.y + rectangle.height))) || (((x+width)<(rectangle.x+rectangle.width)) && ((y+height) <= (rectangle.y + rectangle.height)))))
{
System.out.println("contained");
}
//rechts, oben, unten, links
if((((x + width) - rectangle.x) < 0) || ((y- (rectangle.y + rectangle.height)) > 0) || ((rectangle.y - (y+height))>0) || (((rectangle.x + rectangle.width) - x) < 0))
{
System.out.println("disjoint");
}
//ich weiß noch nicht ob die alligned methoden stimmen, könnt die gerne mal ausprobieren und mir bescheid sagen
//rechts
if((x+width == rectangle.x) && ((y < rectangle.y + rectangle.height) || (y+height > rectangle.y)))
{
System.out.println("alligned");
}
//drüber
if(((y+height==rectangle.y) && ((rectangle.x + rectangle.width > x) || (x+ width > rectangle.x))))
{
System.out.println("alligned");
}
//drunter
if((y == rectangle.y + rectangle.height) && ((x < rectangle.x + rectangle.width) || (x + width > rectangle.x)))
{
System.out.println("alligned");
}
//links
if((rectangle.x + rectangle.width == x) && ((y + height > rectangle.y) || (rectangle.y + rectangle.height > y)))
{
System.out.println("alligned");
}
}
}
public class Figuren
{
public static void main(String[] args)
{
Rectangle rectangle1 = new Rectangle(3, 4, 5, 6);
//rectangle1.increase(3);
rectangle1.print();
Rectangle rectangle2 = new Rectangle(8, 4, 12, 5);
rectangle2.print();
rectangle1.relation(rectangle2);
}
}