Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
4.3 kB
3
Indexable
Never
package main.java;

import java.util.ArrayList;
        import java.util.Arrays;
        import java.util.List;
        import java.util.Objects;
import java.util.stream.Collectors;

// Service
class CompanyService {
    public static Company resolveTestCompany() {
        return new Company(Arrays.asList(
                new Employee("c832eba3-ab20-4dc7-97aa-fab14f1b67e0",
                        Arrays.asList(
                                new Computer("a59af614-b21a-4150-9657-85713c45c", "Dell", "XPS15"),
        new Computer("82bb1446-c6ac-4294-ac5a-3df1c9efbc9b", "Apple", "MBP 15")
)),
        new Employee("18b609f1-230a-428b-aeb5-6238ad773f58",
                Arrays.asList(
                        new Computer("78255d52-8f94-43fa-807b-0a9ed8def5ca", "Dell", "XPS13"),
        new Computer("88926802-e6ba-40de-81aa-14a14c59fdd3", "Dell", "XPS17")
        )),
        new Employee("60962108-0cd0-4d2d-8b8d-9d2e5ba40504",
                Arrays.asList(
                        new Computer("57016c4c-e3b2-4bc8-9852-e3cad4972233", "Lenovo", "K570"),
        new Computer("6e9f2a81-39d1-4840-bb51-3d68ef6da350", "Apple", "MBP 13")
)),
        new Employee("a39699ce-1631-4f1b-b997-683fd1ed6e6e ",
                Arrays.asList(
                        new Computer("5d6617bb-f3b6-4283-bb48-9dfa6dd916a9", "Asus", "Zenbook 15"),
        new Computer("f0dbf0b9-d08c-42ec-8e92-e2826720a29d", "Apple", "MBP 15"),
        new Computer("534639b0-edf9-4afc-af91-24bf9adc51fd", "Apple", "MBP 13")
        )),
        new Employee("11ca4ac2-7d88-4aa0-855b-c273260e8e0b",
                Arrays.asList(
                        new Computer("b8c9a868-c67c-49fa-a7e2-334d6f1e1be3", "Apple", "MBP 15"),
        new Computer("f83ca9b6-e632-4192-a69f-1ee19e149f19", "Apple", "MBP 13")
)),
        new Employee("4719e9ff-8c68-40bf-af61-d4e143793570",
                Arrays.asList(
                        new Computer("f55957b5-ba2b-4651-a5cb-b2c626c3b0c5", "Asus", "Zenbook 13"),
        new Computer("55b09a30-dae0-42ea-bb1c-0d9b2fd202de", "Apple", "MBP 15")
)),
        new Employee("d651c7d1-0e7e-44fe-966f-d577fca49404",
                Arrays.asList(
                        new Computer("581e41e2-88e3-4847-b2b1-0844c39172d8", "Apple", "MBP 13"),
        new Computer("5e7da22a-e52f-4e97-a1bf-0fa66edf2285", "Lenovo", "K570")
))
));
    }
}
class Test {
    public static void main(String[] args) {

        // Warm up exercise
        //create a class named Developer that extends the Employee 
        //and when the speak method is called, 
        //the System out should be "I'm a Developer"

        Employee emp1 = new Employee();
        emp1.speak();

        Employee emp2 = new Developer();
        emp2.speak();
        
    }

}
/**
 *  Data model
 */
class Company {
    private List<Employee> employees;
    public Company(List<Employee> employees) {
        this.employees = employees;
    }
    public List<Employee> getEmployees() {
        return employees;
    }
}

class Employee {
    private String id;
    private List<Computer> computers;
    public Employee(String id, List<Computer> computers) {
        this.id = id;
        this.computers = computers;
    }

    public Employee() {
        this.id = "";
        this.computers = new ArrayList<>();
    }

    public List<Computer> getComputers() {
        return computers;
    }
    public String getId() {
        return id;
    }
    public void speak() {
        System.out.println("I'm a Employee");
    }
}

class Computer {
    private String id;
    private String brand;
    private String model;
    public Computer(String id, String brand, String model) {
        this.id = id;
        this.brand = brand;
        this.model = model;
    }
    public String getId() {
        return id;
    }
    public String getBrand() {
        return brand;
    }
    public String getModel() {
        return model;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Computer)) {
            return false;
        }
        Computer computer = (Computer) o;
        return Objects.equals(brand, computer.brand) &&
                Objects.equals(model, computer.model);
    }
    @Override
    public int hashCode() {
        return Objects.hash(brand, model);
    }
}