ya_zay4eg

level05.lesson09.task02

Nov 24th, 2014
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 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 = null;
  18.     int weight = 4;
  19.     int age = 10;
  20.     String color1=null;
  21.     String address1 = null;
  22.  
  23.     public Cat (String name) {//- Имя
  24.         this.name=name;
  25.     }
  26.  
  27.     public Cat (String name,int weight,int age) {//- Имя, вес, возраст
  28.         this.name=name;
  29.         this.weight=weight;
  30.         this.age=age;
  31.     }
  32.  
  33.     public Cat (String name, int age) {//- Имя, возраст (вес стандартный)
  34.         this.name=name;
  35.         this.age=age;
  36.         int weight=this.weight;
  37.     }
  38.  
  39.     public Cat (int weight, String color1) {//- вес, цвет, (имя, адрес и возраст – неизвестные. Кот - бездомный)
  40.         this.weight = weight;
  41.         this.color1 = color1;
  42.         String name=this.name;
  43.         String address1=this.address1;
  44.         int age=this.age;
  45.     }
  46.  
  47.     public Cat (int weight,String color1, String address1) {
  48.  
  49.         this.weight = weight;
  50.         this.color1=color1;
  51.         this.address1=address1;
  52.     }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment