Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. /* Провести три боя попарно между котами
  2. Создать три кота используя класс Cat.
  3. Провести три боя попарно между котами.
  4. Класс Cat создавать не надо. Для боя использовать метод boolean fight(Cat anotherCat).
  5. Результат каждого боя вывести на экран.
  6. */
  7.  
  8. public class Solution {
  9. public static void main(String[] args) {
  10. //напишите тут ваш код
  11. }
  12.  
  13. public static class Cat {
  14.  
  15. public static int count = 0;
  16. public static int fightCount = 0;
  17.  
  18. protected String name;
  19. protected int age;
  20. protected int weight;
  21. protected int strength;
  22.  
  23. public Cat(String name, int age, int weight, int strength) {
  24. count++;
  25.  
  26. this.name = name;
  27. this.age = age;
  28. this.weight = weight;
  29. this.strength = strength;
  30. }
  31.  
  32. public boolean fight(Cat anotherCat) {
  33. fightCount++;
  34.  
  35. int agePlus = this.age > anotherCat.age ? 1 : 0;
  36. int weightPlus = this.weight > anotherCat.weight ? 1 : 0;
  37. int strengthPlus = this.strength > anotherCat.strength ? 1 : 0;
  38.  
  39. int score = agePlus + weightPlus + strengthPlus;
  40. return score > 2; // return score > 2 ? true : false;
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement