jaVer404

level05.lesson09.task02

Apr 2nd, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package com.javarush.test.level05.lesson09.task02;
  2.  
  3. /* Создать класс Cat
  4. Создать класс Cat (кот) с пятью конструкторами:
  5. - Имя,
  6. - Имя, вес, возраст
  7. - Имя, возраст (вес стандартный)
  8. - вес, цвет, (имя, адрес и возраст – неизвестные. Кот - бездомный)
  9. - вес, цвет, адрес ( чужой домашний кот)
  10. Задача инициализатора – сделать объект валидным.
  11. Например, если вес не известен, то нужно указать какой-нибудь средний вес.
  12. Кот не может ничего не весить. То же касательно возраста.
  13. А вот имени может и не быть (null). То же касается адреса: null.
  14. */
  15.  
  16. public class Cat
  17. {
  18.     //Напишите тут ваш код
  19.     String name, color, adress;
  20.     int weight, age;
  21.  
  22.     Cat (String name) {
  23.         this.name = name;
  24.     }
  25.  
  26.     Cat (String name, int weight, int age) {
  27.         this.name = name;
  28.         this.weight = weight;
  29.         this.age = age;
  30.     }
  31.  
  32.     Cat (String name, int age) {
  33.         this.name = name;
  34.         this.age = age;
  35.         this.weight = 5;
  36.     }
  37.  
  38.     Cat (int weight, String color) {
  39.         this.weight = weight;
  40.         this.color = color;
  41.         this.name = null;
  42.         this.adress = null;
  43.         this.age = 404;
  44.     }
  45.  
  46.     Cat (int weight, String color, String adress) {
  47.         this.weight = weight;
  48.         this.color = color;
  49.         this.adress = adress;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment