Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level05.lesson07.task02;
- /* Создать класс Cat
- Создать класс Cat (кот) с пятью инициализаторами:
- - вес, цвет, адрес ( чужой домашний кот)
- Задача инициализатора – сделать объект валидным. Например, если вес неизвестен, то нужно указать какой-нибудь средний вес. Кот не может ничего не весить. То же касательно возраста. А вот имени может и не быть (null). То же касается адреса: null.
- */
- public class Cat
- {
- //Напишите тут ваш код
- public String name = null;//- Имя
- public int weight = 4;//вес
- public int age = 4;//возраст
- public String color1 = "grey";//цвет
- public String address1 = null;//адресс
- public void initialize (String name){//-Имя
- this.name = name;
- }
- public void initialize (String name, int weight, int age) {//- Имя, вес, возраст
- this.name=name;
- this.weight=weight;
- this.age=age;
- }
- public void initialize (String name, int age) {//- Имя, возраст (вес стандартный)
- this.name=name;
- this.age=age;
- int weight=this.weight;
- }
- public void initialize (int weight, String color1) {//- вес, цвет, (имя, адрес и возраст неизвестны, это бездомный кот)
- this.weight=weight;
- this.color1=color1;
- String name=this.name;
- String address1=this.address1;
- int age=this.age;
- }
- public void initialize (int weight, String color1, String address1) {//- вес, цвет, адрес ( чужой домашний кот)
- this.weight = weight;
- this.color1 = color1;
- this.address1 = address1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment