Advertisement
Azazavr

com.javarush.test.level05.lesson09.task02

Mar 25th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 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.   То же касательно возраста. А вот имени может и не быть (null). То же касается адреса: null.
  13. */
  14.  
  15. public class Cat
  16. {
  17.     String name;
  18.     int weight;
  19.     int age = 1;
  20.     //int def_weight = 1;
  21.     String colour;
  22.     String address;
  23.  
  24.     public Cat(String name){
  25.         this.name = name;
  26.     }
  27.  
  28.     public Cat(String name, int weight, int age){
  29.         this.name = name;
  30.         this.weight = weight;
  31.         this.age = age;
  32.     }
  33.  
  34.     public Cat(String name, int age){
  35.         this.name = name;
  36.         this.age = age;
  37.         this.weight = 1;
  38.     }
  39.  
  40.     public Cat(int weight, String colour){
  41.         this.weight = weight;
  42.         this.colour = colour;
  43.         this.name = null;
  44.         this.address = null;
  45.         this.age = 1;
  46.     }
  47.     public Cat(int weight, String colour, String address){
  48.         this.weight = weight;
  49.         this.colour = colour;
  50.         this.address = address;
  51.     }
  52.  
  53.     public static void main(String[] args)
  54.     {
  55.  
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement