Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class Main
  2. {
  3. public static void main(String[] args)
  4. {
  5.  
  6. Rectangle rect = new Rectangle(100, 200);
  7. System.out.println(rect.getWidth());
  8. System.out.println(rect.getHeight());
  9.  
  10.  
  11. rect.setWidth(10);
  12. rect.setHeight(20);
  13. rect.scale(10);
  14. System.out.println(rect.getArea());
  15.  
  16.  
  17. }
  18. }
  19.  
  20. class Rectangle
  21. {
  22. int width;
  23. int height;
  24. int factor;
  25.  
  26.  
  27. Rectangle(int width, int height)
  28. {
  29. this.width = width;
  30. this.height = height;
  31. }
  32.  
  33. void setHeight(int height)
  34. {
  35. this.height = height;
  36. }
  37.  
  38. void setWidth(int width)
  39. {
  40. this.width = width;
  41. }
  42.  
  43. int getWidth()
  44. {
  45. return this.width;
  46. }
  47.  
  48. int getHeight()
  49. {
  50. return this.height;
  51. }
  52.  
  53. void scale(int factor)
  54. {
  55. width = width * factor;
  56. height = height * factor;
  57. }
  58.  
  59. int getArea()
  60. {
  61. return this.width * this.height;
  62. }
  63.  
  64. 100
  65. 200
  66. 20000
  67.  
  68. public class Main
  69. {
  70. public static void main(String[] args)
  71. {
  72.  
  73. Rectangle rect = new Rectangle(100, 200);
  74. System.out.println(rect.getWidth());
  75. System.out.println(rect.getHeight());
  76.  
  77.  
  78. rect.setWidth(10);
  79. rect.setHeight(20);
  80. System.out.println(rect.getArea());
  81.  
  82. rect.scale(10);
  83. System.out.println(rect.getArea());
  84.  
  85.  
  86. }
  87. }
  88.  
  89. rect.scale(10);
  90. System.out.println(rect.getArea());
Add Comment
Please, Sign In to add comment