Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main
- package google;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Person> people = new HashMap<>();
- String input = scanner.nextLine();
- while (!input.equals("End")) {
- String[] tokens = input.split("\\s+");
- String name = tokens[0];
- String command = tokens[1];
- // people.putIfAbsent(name, new Person());
- if (!people.containsKey(name)){
- Person person = new Person();
- people.put(name, person);
- }
- switch (command) {
- case "company":
- String companyName = tokens[2];
- String department = tokens[3];
- double salary = Double.parseDouble(tokens[4]);
- Company company = new Company(companyName, department, salary);
- people.get(name).setCompany(company);
- break;
- case "pokemon":
- String pokemonName = tokens[2];
- String pokemonType = tokens[3];
- Pokemon pokemon = new Pokemon(pokemonName, pokemonType);
- people.get(name).setPokemon(pokemon);
- break;
- case "parents":
- String parentName = tokens[2];
- String parentBirthday = tokens[3];
- Parents parent = new Parents(parentName, parentBirthday);
- people.get(name).setParents(parent);
- break;
- case "children":
- String childName = tokens[2];
- String childBirthday = tokens[3];
- Children child = new Children(childName,childBirthday);
- people.get(name).setChildren(child);
- break;
- case "Car":
- String carModel = tokens[2];
- int carSpeed = Integer.parseInt(tokens[3]);
- Car car = new Car(carModel,carSpeed);
- people.get(name).setCar(car);
- break;
- }
- input = scanner.nextLine();
- }
- people.entrySet().stream().forEach(person -> {
- System.out.println(person.getKey());
- System.out.println("Company:");
- if (isCompany(person.getValue().getCompany())){
- System.out.printf("%s %s %.2f%n",
- person.getValue().getCompany().getCompanyName(),
- person.getValue().getCompany().getDepartment(),
- person.getValue().getCompany().getSalary());
- }
- System.out.println("Car");
- if (isCar(person.getValue().getCar()))
- });
- }
- private static boolean isCar(Car car) {
- //is it
- }
- private static boolean isCompany(Company company) {
- if (company.getCompanyName().equals("")){
- return false;
- }
- return true;
- }
- }
- //Person
- package google;
- import java.util.List;
- public class Person {
- private Company company;
- private List<Pokemon> pokemon;
- private List<Parents> parents;
- private List<Children> children;
- private Car car;
- public Company getCompany() {
- return company;
- }
- public List<Pokemon> getPokemon() {
- return pokemon;
- }
- public List<Parents> getParents() {
- return parents;
- }
- public List<Children> getChildren() {
- return children;
- }
- public Car getCar() {
- return car;
- }
- public Person() {
- }
- public void setCompany(Company company) {
- this.company = company;
- }
- public void setPokemon(Pokemon pokemon) {
- this.pokemon.add(pokemon);
- }
- public void setParents(Parents parents) {
- this.parents.add(parents);
- }
- public void setChildren(Children children) {
- this.children.add(children);
- }
- public void setCar(Car car) {
- this.car = car;
- }
- }
- //Company
- package google;
- public class Company {
- private String companyName = "";
- private String department = "";
- private double salary;
- public String getCompanyName() {
- return companyName;
- }
- public String getDepartment() {
- return department;
- }
- public double getSalary() {
- return salary;
- }
- public Company(String companyName, String department, double salary) {
- this.companyName = companyName;
- this.department = department;
- this.salary = salary;
- }
- }
- //Pokemon
- package google;
- public class Pokemon {
- private String name;
- private String type;
- public Pokemon(String name, String type) {
- this.name = name;
- this.type = type;
- }
- }
- //Parents
- package google;
- public class Parents {
- private String ParentName;
- private String birthday;
- public Parents(String parentName, String birthday) {
- ParentName = parentName;
- this.birthday = birthday;
- }
- }
- //Children
- package google;
- public class Children {
- private String childName;
- private String birthday;
- public Children(String childName, String birthday) {
- this.childName = childName;
- this.birthday = birthday;
- }
- }
- //Car
- package google;
- public class Car {
- public String getModel() {
- return model;
- }
- public int getSpeed() {
- return speed;
- }
- private String model = "";
- private int speed;
- public Car(String model, int speed) {
- this.model = model;
- this.speed = speed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement