package com.javarush.test.level05.lesson07.task02;

/ Create a class Cat Create a class Cat with five initializers: - Name - Name, weight, age - Name, age (standard weight) - Weight, color, (name, address and age are unknown, it’s an alley cat) - Weight, color, address (it’s someone’s house cat) Initializer’s task is to make an object valid. For example, if the weight is unknown, you need to specify some average weight. A cat can’t have any weight at all, likewise age. But it can have no name (null). The same applies to the address - can be null. /

public class Cat { private String color; private String address; private String name; private double weight; private int age;

public void initializer(String name){

    this.name = name;
    this.weight=4;
    this.age = 7;
    this.color=null;
    this.address=null;

}
public void initializer(String name, double weight, int age){

    this.name = name;
    this.weight = weight;
    this.age = age;
    this.color=null;
    this.address=null;
}
public void initializer(String name, int age){

    this.name = name;
    this.age = age;
    this.weight = 7.5;
    this.color=null;
    this.address=null;
}
public  void initializer(double weight, String color){

    this.weight = weight;
    this.color = color;
    this.age = 9;
    this.address=null;
    this.name = null;
}
public void initializer(double weight, String color, String address){

    this.weight = weight;
    this.color = color;
    this.address = address;
    this.age = 5;
    this.name = null;
}

asked 29 Sep '15, 07:32

nisar's gravatar image

nisar
111
accept rate: 0%

help me plz

(29 Sep '15, 14:27) nisar

I also need help

link

answered 10 Jul, 05:55

blacklight's gravatar image

blacklight
11
accept rate: 0%

Passed

public class Cat
{
    private String name = null;
    private int weight = 2;
    private int age = 3;
    private String color = "black";
    private String address = null;

public static void main(String [] args)
{

}
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;
    this.weight = weight;
}
public void initialize(int weight, String color)
{
    this.weight = weight;
    this.color = color;
    this.name = name;
    this.address = address;
    this.age = age;
}
public void initialize(int weight, String color, String address)
{
    this.weight = weight;
    this.color = color;
    this.address = address;
}

}

link

answered 10 Jul, 06:18

blacklight's gravatar image

blacklight
11
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1

Asked: 29 Sep '15, 07:32

Seen: 608 times

Last updated: 10 Jul, 06:18

Related questions