Advertisement
jaVer404

level14.lesson08.home05

Jun 23rd, 2015
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package com.javarush.test.level14.lesson08.home05;
  2.  
  3. /* Computer
  4. 1. Создай интерфейс CompItem.
  5. 2. Добавь в него метод String getName().
  6. 3. Создай классы Keyboard, Mouse, Monitor, которые реализуют интерфейс CompItem.
  7. 4. Метод getName() должен возвращать имя класса, например, для класса Keyboard будет "Keyboard".
  8. 5. Создай класс Computer.
  9. 6. В класс Computer добавь приватное поле типа Keyboard.
  10. 7. В класс Computer добавь приватное поле типа Mouse.
  11. 8. В класс Computer добавь приватное поле типа Monitor.
  12. 9. Создай конструктор в классе Computer используя комбинацию клавиш Alt+Insert внутри класса (команда Constructor).
  13. 10 Внутри конструктора инициализируйте все три поля (переменных) класса
  14. 11. Создай геттеры для полей класса Computer (в классе используй комбинацию клавиш Alt+Insert и выбери команду Getter).
  15. 12. Все созданные классы и интерфейс должны быть в отдельных файлах.
  16. 13. Класс Solution менять нельзя.
  17. */
  18.  
  19. public class Solution
  20. {
  21.     public static void main(String[] args)
  22.     {
  23.         Computer computer = new Computer();
  24.         if (isWork(computer.getKeyboard()) &&
  25.                 isWork(computer.getMonitor()) &&
  26.                 isWork(computer.getMouse()))
  27.         {
  28.             System.out.println("Work!");
  29.         }
  30.     }
  31.  
  32.     public static boolean isWork(CompItem item)
  33.     {
  34.         System.out.println(item.getName());
  35.         return item.getName() != null && item.getName().length() > 4;
  36.     }
  37.  
  38. }
  39. /*--------------------------------------------*/
  40. package com.javarush.test.level14.lesson08.home05;
  41.  
  42. /**
  43.  * Created by Т-34 on 23.06.2015.
  44.  */
  45. public class Computer
  46. {
  47.     private Keyboard keyboard;
  48.     private Mouse mouse;
  49.     private Monitor monitor;
  50.  
  51.     public Computer()
  52.     {
  53.         this.keyboard = new Keyboard();
  54.         this.mouse = new Mouse();
  55.         this.monitor = new Monitor();
  56.     }
  57.  
  58.     public Keyboard getKeyboard()
  59.     {
  60.         return keyboard;
  61.     }
  62.  
  63.     public Mouse getMouse()
  64.     {
  65.         return mouse;
  66.     }
  67.  
  68.     public Monitor getMonitor()
  69.     {
  70.         return monitor;
  71.     }
  72. }
  73. /*--------------------------------------------*/
  74. package com.javarush.test.level14.lesson08.home05;
  75.  
  76. /**
  77.  * Created by Т-34 on 23.06.2015.
  78.  */
  79. public interface CompItem
  80. {
  81.     String getName();
  82. }
  83. /*--------------------------------------------*/
  84. package com.javarush.test.level14.lesson08.home05;
  85.  
  86. /**
  87.  * Created by Т-34 on 23.06.2015.
  88.  */
  89. public class Keyboard implements CompItem
  90. {
  91.     public String getName() {
  92.         return getClass().getSimpleName();
  93.     }
  94. }
  95. /*--------------------------------------------*/
  96. package com.javarush.test.level14.lesson08.home05;
  97.  
  98. /**
  99.  * Created by Т-34 on 23.06.2015.
  100.  */
  101. public class Mouse implements CompItem
  102. {
  103.     public String getName() {
  104.         return getClass().getSimpleName();
  105.     }
  106. }
  107. /*--------------------------------------------*/
  108. package com.javarush.test.level14.lesson08.home05;
  109.  
  110. /**
  111.  * Created by Т-34 on 23.06.2015.
  112.  */
  113. public class Monitor implements CompItem
  114. {
  115.     public String getName() {
  116.         return getClass().getSimpleName();
  117.     }
  118. }
  119. /*--------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement