Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. //main
  2. package google;
  3.  
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. Scanner scanner = new Scanner(System.in);
  11.  
  12. Map<String, Person> people = new HashMap<>();
  13.  
  14. String input = scanner.nextLine();
  15.  
  16. while (!input.equals("End")) {
  17. String[] tokens = input.split("\\s+");
  18. String name = tokens[0];
  19. String command = tokens[1];
  20. // people.putIfAbsent(name, new Person());
  21.  
  22.  
  23. if (!people.containsKey(name)){
  24. Person person = new Person();
  25. people.put(name, person);
  26. }
  27.  
  28. switch (command) {
  29. case "company":
  30. String companyName = tokens[2];
  31. String department = tokens[3];
  32. double salary = Double.parseDouble(tokens[4]);
  33. Company company = new Company(companyName, department, salary);
  34. people.get(name).setCompany(company);
  35. break;
  36. case "pokemon":
  37. String pokemonName = tokens[2];
  38. String pokemonType = tokens[3];
  39. Pokemon pokemon = new Pokemon(pokemonName, pokemonType);
  40. people.get(name).setPokemon(pokemon);
  41. break;
  42. case "parents":
  43. String parentName = tokens[2];
  44. String parentBirthday = tokens[3];
  45. Parents parent = new Parents(parentName, parentBirthday);
  46. people.get(name).setParents(parent);
  47. break;
  48. case "children":
  49. String childName = tokens[2];
  50. String childBirthday = tokens[3];
  51. Children child = new Children(childName,childBirthday);
  52. people.get(name).setChildren(child);
  53. break;
  54. case "Car":
  55. String carModel = tokens[2];
  56. int carSpeed = Integer.parseInt(tokens[3]);
  57. Car car = new Car(carModel,carSpeed);
  58. people.get(name).setCar(car);
  59. break;
  60. }
  61.  
  62.  
  63. input = scanner.nextLine();
  64. }
  65.  
  66. people.entrySet().stream().forEach(person -> {
  67. System.out.println(person.getKey());
  68. System.out.println("Company:");
  69. if (isCompany(person.getValue().getCompany())){
  70. System.out.printf("%s %s %.2f%n",
  71. person.getValue().getCompany().getCompanyName(),
  72. person.getValue().getCompany().getDepartment(),
  73. person.getValue().getCompany().getSalary());
  74. }
  75. System.out.println("Car");
  76. if (isCar(person.getValue().getCar()))
  77.  
  78. });
  79. }
  80.  
  81. private static boolean isCar(Car car) {
  82. //is it
  83. }
  84.  
  85. private static boolean isCompany(Company company) {
  86. if (company.getCompanyName().equals("")){
  87. return false;
  88. }
  89. return true;
  90. }
  91. }
  92.  
  93. //Person
  94. package google;
  95.  
  96. import java.util.List;
  97.  
  98. public class Person {
  99. private Company company;
  100. private List<Pokemon> pokemon;
  101. private List<Parents> parents;
  102. private List<Children> children;
  103. private Car car;
  104.  
  105. public Company getCompany() {
  106. return company;
  107. }
  108.  
  109. public List<Pokemon> getPokemon() {
  110. return pokemon;
  111. }
  112.  
  113. public List<Parents> getParents() {
  114. return parents;
  115. }
  116.  
  117. public List<Children> getChildren() {
  118. return children;
  119. }
  120.  
  121. public Car getCar() {
  122. return car;
  123. }
  124.  
  125. public Person() {
  126. }
  127.  
  128. public void setCompany(Company company) {
  129. this.company = company;
  130. }
  131.  
  132. public void setPokemon(Pokemon pokemon) {
  133. this.pokemon.add(pokemon);
  134. }
  135.  
  136. public void setParents(Parents parents) {
  137. this.parents.add(parents);
  138. }
  139.  
  140. public void setChildren(Children children) {
  141. this.children.add(children);
  142. }
  143.  
  144. public void setCar(Car car) {
  145. this.car = car;
  146. }
  147. }
  148. //Company
  149. package google;
  150.  
  151. public class Company {
  152. private String companyName = "";
  153. private String department = "";
  154. private double salary;
  155.  
  156. public String getCompanyName() {
  157. return companyName;
  158. }
  159.  
  160. public String getDepartment() {
  161. return department;
  162. }
  163.  
  164. public double getSalary() {
  165. return salary;
  166. }
  167.  
  168. public Company(String companyName, String department, double salary) {
  169. this.companyName = companyName;
  170. this.department = department;
  171. this.salary = salary;
  172. }
  173. }
  174. //Pokemon
  175. package google;
  176.  
  177. public class Pokemon {
  178. private String name;
  179. private String type;
  180.  
  181. public Pokemon(String name, String type) {
  182. this.name = name;
  183. this.type = type;
  184. }
  185. }
  186. //Parents
  187. package google;
  188.  
  189. public class Parents {
  190. private String ParentName;
  191. private String birthday;
  192.  
  193. public Parents(String parentName, String birthday) {
  194. ParentName = parentName;
  195. this.birthday = birthday;
  196. }
  197. }
  198.  
  199. //Children
  200. package google;
  201.  
  202. public class Children {
  203. private String childName;
  204. private String birthday;
  205.  
  206. public Children(String childName, String birthday) {
  207. this.childName = childName;
  208. this.birthday = birthday;
  209. }
  210. }
  211.  
  212. //Car
  213. package google;
  214.  
  215. public class Car {
  216. public String getModel() {
  217. return model;
  218. }
  219.  
  220. public int getSpeed() {
  221. return speed;
  222. }
  223.  
  224. private String model = "";
  225. private int speed;
  226.  
  227. public Car(String model, int speed) {
  228. this.model = model;
  229. this.speed = speed;
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement