ya_zay4eg

level05.lesson09.task05

Nov 24th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package com.javarush.test.level05.lesson09.task05;
  2.  
  3. /* Создать класс прямоугольник (Rectangle)
  4. Создать класс прямоугольник (Rectangle).
  5. Его данными будут top, left, width, height (левая координата, верхняя, ширина и высота).
  6. Создать для него как можно больше конструкторов:
  7. Примеры:
  8. -   заданы 4 параметра: left, top, width, height
  9. -   ширина/высота не задана (оба равны 0)
  10. -   высота не задана (равно ширине) создаём квадрат
  11. -   создаём копию другого прямоугольника (он и передаётся в параметрах)
  12. */
  13.  
  14. public class Rectangle
  15. {
  16.     //Напишите тут ваш код
  17.     int left;
  18.     int top;
  19.     int width=0;
  20.     int height=0;
  21.     Rectangle rectangle = new Rectangle();
  22.  
  23.  
  24.     public Rectangle (int left, int top, int width, int height) {
  25.         this.left=left;
  26.         this.top=top;
  27.         this.width=width;
  28.         this.height=height;
  29.     }
  30.  
  31.     public Rectangle (int top, int left) {
  32.         this.top=top;
  33.         this.left=left;
  34.         int width=this.width;
  35.         int height=this.height;
  36.  
  37.     }
  38.  
  39.     public Rectangle (int width) {
  40.         this.width=width;
  41.         this.height=width;
  42.         this.top=width;
  43.         this.left=width;
  44.     }
  45.  
  46.     public Rectangle () {
  47.         new Rectangle();
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment