Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package at.ac.campuswien.shape;
  2.  
  3. public class Rectangle extends Shape{
  4. private int x1;
  5. private int y1;
  6. private int x2;
  7. private int y2;
  8.  
  9. private static int count;
  10.  
  11. public Rectangle(int x1, int y1, int x2, int y2){
  12. this.x1 = x1;
  13. this.y1 = y1;
  14. this.x2 = x2;
  15. this.y2 = y2;
  16. count++;
  17. }
  18. public Rectangle(int x1, int y1, int x2, int y2, String color,String name, boolean stroke) {
  19. this.x1 = x1;
  20. this.y1 = y1;
  21. this.x2 = x2;
  22. this.y2 = y2;
  23. super.setColor(color);
  24. super.setName(name);
  25. super.setStroked(stroke);
  26. count++;
  27.  
  28. }
  29.  
  30. public Rectangle(int width, int height, String color,String name, boolean stroke){
  31. this.x1 = 0;
  32. this.y1 = 0;
  33. this.x2 = width;
  34. this.y2 = height;
  35. super.setColor(color);
  36. super.setName(name);
  37. super.setStroked(stroke);
  38. count++;
  39. }
  40. public Rectangle(){
  41. this(0,0,0,0);
  42. }
  43.  
  44. public void Move(int deltax, int deltay){
  45. this.x1 = this.x1 + deltax;
  46. this.x2 = this.x2 + deltax;
  47.  
  48. this.y1 = this.y1 + deltay;
  49. this.y2 = this.y2 + deltay;
  50.  
  51. }
  52.  
  53. public boolean isInside(int x, int y){
  54. boolean ergebnis = false;
  55.  
  56. if(x >= this.x1 && x <= this.x2){
  57. if(y >= this.y1 && y <= this.y2)
  58. ergebnis = true;
  59. }
  60.  
  61. return ergebnis;
  62. }
  63.  
  64. public double getWidth(){
  65. double width = x2-x1;
  66. return width;
  67. }
  68.  
  69. public static int getCount(){
  70. return count;
  71. }
  72.  
  73. public double getHeight(){
  74. return y2-y1;
  75. }
  76.  
  77. public double getArea()
  78. {
  79. return getHeight()*getWidth();
  80. }
  81.  
  82. public double getPerimeter(){
  83. return 2*(getWidth()+getHeight());
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement