fork(1) 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.  
  37. System.out.println("Племена, знакомые с огнём:");
  38.  
  39. for (Tribe tribe : tribes) {
  40. totalPopulation += tribe.getPopulation();
  41. if (tribe.hasFireKnowledge()) {
  42. System.out.println(tribe.getName());
  43. }
  44. }
  45.  
  46. System.out.println("Общая численность племён: " + totalPopulation);
  47. }
  48. }
  49.  
Success #stdin #stdout 0.1s 55676KB
stdin
Standard input is empty
stdout
Племена, знакомые с огнём:
Они
Хауш
Ямана
Общая численность племён: 435