Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab11;
- public class rectangle {
- public static void main(String[] args) {
- prostokat b = new prostokat(1,2, 5,5);
- b.wymiary();
- b = b.obroc(90);
- b.wymiary();
- b = b.rozciag(2, 6);
- b.wymiary();
- b = b.przesun(4, 2);
- b.wymiary();
- }
- public static class prostokat{
- private final int a, b;
- private final int x, y;
- private prostokat(int a, int b, int x, int y)
- {
- this.a = a;
- this.b = b;
- this.x = x;
- this.y = y;
- }
- private prostokat()
- {
- this.a = 0;
- this.b = 0;
- this.x = 0;
- this.y = 0;
- }
- private prostokat obroc(int stopnie)
- {
- if(stopnie%90 != 0) return null;
- if((stopnie/90)%2 != 0) return new prostokat(b,a, x, y);
- else return new prostokat(a,b, x, y);
- }
- private prostokat rozciag(int a, int b)
- {
- return new prostokat(this.a + a, this.b + b, x, y);
- }
- private prostokat przesun(int x, int y)
- {
- return new prostokat(this.a, this.b, this.x + x, this.y+y);
- }
- private void wymiary()
- {
- System.out.println("Wysokosc: "+this.a+" Szerokosc: "+this.b+" Współrzędna: X: "+this.x+" Y: "+this.y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement