SHARE
TWEET

1

a guest Feb 27th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Main
  2. {
  3.   public static void main (String[]args)
  4.   {
  5.     Cat cat1 = new Cat ("Murzik", 8, 12, 44);
  6.     Cat cat2 = new Cat ("Pushok", 5, 17, 33);
  7.     Cat cat3 = new Cat ("Knopka", 3, 8, 11);
  8.  
  9.       System.out.println (cat1.fight (cat2));
  10.       System.out.println (cat2.fight (cat3));
  11.       System.out.println (cat1.fight (cat3));
  12.   }
  13.  
  14.   public static class Cat
  15.   {
  16.     protected String name;
  17.     protected int age;
  18.     protected int weight;
  19.     protected int strength;
  20.  
  21.     public Cat (String name, int age, int weight, int strength)
  22.     {
  23.       this.name = name;
  24.       this.age = age;
  25.       this.weight = weight;
  26.       this.strength = strength;
  27.     }
  28.  
  29.     public boolean fight (Cat anotherCat)
  30.     {
  31.       int ageAdvantage = this.age > anotherCat.age ? 1 : 0;
  32.       int weightAdvantage = this.weight > anotherCat.weight ? 1 : 0;
  33.       int strengthAdvantage = this.strength > anotherCat.strength ? 1 : 0;
  34.  
  35.       int score = ageAdvantage + weightAdvantage + strengthAdvantage;
  36.       return score > 2;     // return score > 2 ? true : false;
  37.     }
  38.   }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top