Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. package food_shortage_04;
  2.  
  3. public class Citizen implements Person, Identifiable, Buyer {
  4. private String name;
  5. private int age;
  6. private String id;
  7. private String birthDate;
  8. private int food;
  9.  
  10. public Citizen(String name, int age, String id, String birthDate) {
  11. this.name = name;
  12. this.age = age;
  13. this.id = id;
  14. this.birthDate = birthDate;
  15. this.food = 0;
  16. }
  17.  
  18. @Override
  19. public void buyFood() {
  20. this.food += 10;
  21. }
  22.  
  23. @Override
  24. public int getFood() {
  25. return this.food;
  26. }
  27.  
  28. @Override
  29. public String getId() {
  30. return this.id;
  31. }
  32.  
  33. @Override
  34. public String getName() {
  35. return this.name;
  36. }
  37.  
  38. @Override
  39. public int getAge() {
  40. return this.age;
  41. }
  42. }
  43. ----------------------------------------------------------------------------------------------------------------------------------
  44. package food_shortage_04;
  45.  
  46. public class Rebel implements Person, Buyer {
  47. private String name;
  48. private int age;
  49. private String group;
  50. private int food;
  51.  
  52. public Rebel(String name, int age, String group) {
  53. this.name = name;
  54. this.age = age;
  55. this.group = group;
  56. this.food = 0;
  57. }
  58.  
  59. @Override
  60. public void buyFood() {
  61. this.food += 5;
  62. }
  63.  
  64. @Override
  65. public int getFood() {
  66. return this.food;
  67. }
  68.  
  69. @Override
  70. public String getName() {
  71. return this.name;
  72. }
  73.  
  74. @Override
  75. public int getAge() {
  76. return this.age;
  77. }
  78.  
  79. public String getGroup() {
  80. return group;
  81. }
  82. }
  83. ----------------------------------------------------------------------------------------------------------------------------------
  84. package food_shortage_04;
  85.  
  86. import java.util.*;
  87.  
  88. public class Main {
  89. public static void main(String[] args) {
  90. Scanner scanner = new Scanner(System.in);
  91.  
  92. Set<Person> buyers = new HashSet<>();
  93.  
  94. int n = Integer.parseInt(scanner.nextLine());
  95. while (n-- > 0) {
  96. String[] tokens = scanner.nextLine().split("\\s+");
  97. if (tokens.length == 4) {
  98.  
  99. buyers.add(new Citizen(tokens[0], Integer.parseInt(tokens[1]), tokens[2], tokens[3]));
  100. } else {
  101. buyers.add(new Rebel(tokens[0], Integer.parseInt(tokens[1]), tokens[2]));
  102. }
  103. }
  104.  
  105. int sum = 0;
  106. String line = scanner.nextLine();
  107. while (!line.equals("End")) {
  108.  
  109. for (Person buyer : buyers) {
  110. if (buyer.getName().equals(line)){
  111. buyer.
  112. }
  113. }
  114.  
  115. line = scanner.nextLine();
  116. }
  117.  
  118.  
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement