Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main
- {
- public static void main (String[]args)
- {
- Cat cat1 = new Cat ("Murzik", 8, 12, 44);
- Cat cat2 = new Cat ("Pushok", 5, 17, 33);
- Cat cat3 = new Cat ("Knopka", 3, 8, 11);
- System.out.println (cat1.fight (cat2));
- System.out.println (cat2.fight (cat3));
- System.out.println (cat1.fight (cat3));
- }
- public static class Cat
- {
- protected String name;
- protected int age;
- protected int weight;
- protected int strength;
- public Cat (String name, int age, int weight, int strength)
- {
- this.name = name;
- this.age = age;
- this.weight = weight;
- this.strength = strength;
- }
- public boolean fight (Cat anotherCat)
- {
- int ageAdvantage = this.age > anotherCat.age ? 1 : 0;
- int weightAdvantage = this.weight > anotherCat.weight ? 1 : 0;
- int strengthAdvantage = this.strength > anotherCat.strength ? 1 : 0;
- int score = ageAdvantage + weightAdvantage + strengthAdvantage;
- return score > 2; // return score > 2 ? true : false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement