fork download
  1. import java.util.*;
  2.  
  3. class Tribe {
  4. private String name;
  5. private int population;
  6. private boolean fireKnowledge;
  7.  
  8. public Tribe(String name, int population, boolean fireKnowledge) {
  9. this.name = name;
  10. this.population = population;
  11. this.fireKnowledge = fireKnowledge;
  12. }
  13.  
  14. public String getName() {
  15. return name;
  16. }
  17.  
  18. public int getPopulation() {
  19. return population;
  20. }
  21.  
  22. public boolean hasFireKnowledge() {
  23. return fireKnowledge;
  24. }
  25.  
  26. public static void main(String[] args) {
  27. Tribe[] tribes = {
  28. new Tribe("Степное Племя", 100, true),
  29. new Tribe("Лесное Племя", 75, false),
  30. new Tribe("Горное Племя", 50, true),
  31. new Tribe("Пустынное Племя", 120, false),
  32. new Tribe("Морское Племя", 90, true)
  33. };
  34.  
  35. int totalPopulation = 0;
  36. int fireAwareTribes = 0;
  37.  
  38. for (Tribe tribe : tribes) {
  39. totalPopulation += tribe.getPopulation();
  40. if (tribe.hasFireKnowledge()) {
  41. fireAwareTribes++;
  42. }
  43. }
  44.  
  45. System.out.println("Общая численность племён: " + totalPopulation);
  46. System.out.println("Количество племён, знакомых с огнём: " + fireAwareTribes);
  47. }
  48. }
  49.  
Success #stdin #stdout 0.12s 55768KB
stdin
Standard input is empty
stdout
Общая численность племён: 435
Количество племён, знакомых с огнём: 3