Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package lab11;
  2.  
  3. public class rectangle {
  4.  
  5.  
  6. public static void main(String[] args) {
  7. prostokat b = new prostokat(1,2, 5,5);
  8. b.wymiary();
  9. b = b.obroc(90);
  10. b.wymiary();
  11. b = b.rozciag(2, 6);
  12. b.wymiary();
  13. b = b.przesun(4, 2);
  14. b.wymiary();
  15. }
  16.  
  17. public static class prostokat{
  18. private final int a, b;
  19. private final int x, y;
  20. private prostokat(int a, int b, int x, int y)
  21. {
  22. this.a = a;
  23. this.b = b;
  24. this.x = x;
  25. this.y = y;
  26. }
  27. private prostokat()
  28. {
  29. this.a = 0;
  30. this.b = 0;
  31. this.x = 0;
  32. this.y = 0;
  33. }
  34.  
  35. private prostokat obroc(int stopnie)
  36. {
  37. if(stopnie%90 != 0) return null;
  38. if((stopnie/90)%2 != 0) return new prostokat(b,a, x, y);
  39. else return new prostokat(a,b, x, y);
  40. }
  41. private prostokat rozciag(int a, int b)
  42. {
  43. return new prostokat(this.a + a, this.b + b, x, y);
  44. }
  45. private prostokat przesun(int x, int y)
  46. {
  47. return new prostokat(this.a, this.b, this.x + x, this.y+y);
  48. }
  49. private void wymiary()
  50. {
  51. System.out.println("Wysokosc: "+this.a+" Szerokosc: "+this.b+" Współrzędna: X: "+this.x+" Y: "+this.y);
  52. }
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement