help needed . what should i do to sovle the following question ?? / Hold three twosome fights between cats Create three cats using the class Cat. Hold three pairwise fights between cats. Do not create the class Cat. For the fight, use the method boolean fight(Cat anotherCat). Display the result of each fight. / this is the given code .

public static void main(String[] args) { //add your code here }

public static class Cat {

    public static int count = 0;
    public static int fightCount = 0;

    protected String name;
    protected int age;
    protected int weight;
    protected int strength;

    public Cat(String name, int age, int weight, int strength) {
        count++;

        this.name = name;
        this.age = age;
        this.weight = weight;
        this.strength = strength;
    }

    public boolean fight(Cat anotherCat) {
        fightCount++;

        int agePlus = this.age > anotherCat.age ? 1 : 0;
        int weightPlus = this.weight > anotherCat.weight ? 1 : 0;
        int strengthPlus = this.strength > anotherCat.strength ? 1 : 0;

        int score = agePlus + weightPlus + strengthPlus;
        return score > 2; // return score > 2 ? true : false;
    }
}

asked 02 Apr '15, 10:15

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
4311324
accept rate: 0%


  1. In main method create 3 instance of class Cat and give them name, age, weight and strength.
  2. Use 'fight' method 3 times with these instances (e.g. cat1 fight cat2).
  3. 3 lines on creating 3 objects and 3 lines on printing the result of each of 3 fights.

I could give you the whole solution, but copypaste won't give you anything. Max what else I can do is give you couple tematic articles. 1. Creating Objects 2. Constructors

link

answered 02 Apr '15, 12:06

Andrey's gravatar image

Andrey
1323
accept rate: 35%

this kind of help is best . i will not learn anything untill unless i'll try myself . just guide me like points . thanks

(03 Apr '15, 18:46) Muhammad Has...

will you help me ?? how to create 2nd step of cat fight .

(08 Apr '15, 18:23) Muhammad Has...

Well... :) Actually I already gave you a hint in the second sentence, but if you insist, there it is: cat1.fight(cat2); :D

(08 Apr '15, 18:33) Andrey

yeah done it . thanks :)

(09 Apr '15, 09:40) Muhammad Has...
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:

×30
×24
×11

Asked: 02 Apr '15, 10:15

Seen: 1,639 times

Last updated: 22 Apr '15, 20:14