Advertisement
Azazavr

com.javarush.test.level05.lesson09.task05

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