Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
10 kB
4
Indexable
Never
/*
Name Surname = Hakkı Kokur
NO = 150120033
*/

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;

import javax.swing.plaf.SliderUI;
import java.util.Calendar;

public class Test {
    
    public static void main(String[] args) throws FileNotFoundException{

        File file = new File("input.txt");
        Scanner scan = new Scanner(file);
        
        ArrayList<Object> objects = new ArrayList<>();

        while(scan.hasNextLine()){
            String s = scan.nextLine();
            ArrayList<String> sList;
            
            sList = new ArrayList<>(Arrays.asList(s.split(" ")));
            
            if(s.startsWith("Department")){
                int id = java.lang.Integer.valueOf(sList.get(1));
                String name = sList.get(2);
                Department d = new Department(id, name);
                objects.add(d);
            }
            else if(s.startsWith("Project")){
                String name = sList.get(1);
                String[] numbers = sList.get(2).split("/");
                int year = Integer.valueOf(numbers[2]);
                int month = Integer.valueOf(numbers[1]) -1;
                int day = Integer.valueOf(numbers[0]);
                Calendar c = Calendar.getInstance();
                c.set(year, month, day);
                boolean state = Boolean.valueOf(sList.get(3));
                Project p = new Project(name, c, state);
                objects.add(p);
            }
            else if(s.startsWith("Person")){
                String name = sList.get(1);
                String lastName = sList.get(2);
                int id = Integer.valueOf(sList.get(3));
                String gender = sList.get(4);
                String[] numbers = sList.get(5).split("/");
                int year = Integer.valueOf(numbers[2]);
                int month = Integer.valueOf(numbers[1]) -1;
                int day = Integer.valueOf(numbers[0]);
                Calendar c = Calendar.getInstance();
                c.set(year, month, day);
                String marialStatus = sList.get(6);
                String hasDriverLicence = sList.get(7);
                Person pe = new Person(id, name, lastName, gender, c, marialStatus, hasDriverLicence);
                objects.add(pe);
            }
            else if(s.startsWith("Employee")){
                double salary = Double.valueOf(sList.get(2));
                String[] numbers = sList.get(3).split("/");
                int year = Integer.valueOf(numbers[2]);
                int month = Integer.valueOf(numbers[1]) -1;
                int day = Integer.valueOf(numbers[0]);
                Calendar c = Calendar.getInstance();
                c.set(year, month, day);
                for(Object obj: objects){
                    if(obj instanceof Person){
                        if(((Person)obj).getId() == Integer.valueOf(sList.get(1))){
                            for(Object obj2: objects){
                                if(obj2 instanceof Department){
                                    if( ((Department)obj2).getDepartmentName() == sList.get(4)){
                                        Employee e = new Employee(obj, salary, c, obj2);
                                        objects.add(e);
                                        objects.remove(obj);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if(s.startsWith("Manager")){
                double bonus = Double.valueOf(sList.get(2));
                for(Object obj:objects){
                    if(obj instanceof Employee){
                        if ( ((Employee)obj).getId() == Integer.valueOf(sList.get(1))){
                            Manager m = new Manager(obj, bonus);
                            objects.add(m);
                            objects.remove(obj);
                        }
                    }
                }
            }
            else if(s.startsWith("RegularEmployee")){
                double pScore = Double.valueOf(sList.get(2));
                for(Object obj:objects){
                    if(obj instanceof Employee){
                        if ( ((Employee)obj).getId() == Integer.valueOf(sList.get(1))){
                            RegularEmployee re = new RegularEmployee(obj, pScore);
                            objects.add(re);
                            objects.remove(obj);
                        }
                    }
                }
            }
            else if(s.startsWith("Developer")){
                for(Object obj:objects){
                    if(obj instanceof RegularEmployee){
                        if ( ((RegularEmployee)obj).getId() == Integer.valueOf(sList.get(1))){
                            sList.remove(0);
                            sList.remove(0);
                            ArrayList<Project> pr = new ArrayList<>();
                            for(int i = 0; i < sList.size(); i++){
                                for(Object obj2:objects){
                                    if(obj2 instanceof Project){
                                        if (((Project)obj).getProjectName() == sList.get(i)){
                                            pr.add(((Project)obj));
                                        }
                                    }
                                }
                            }
                            Developer dev = new Developer((RegularEmployee)obj, pr);
                            objects.add(dev);
                            objects.remove(obj);
                        }
                    }
                }
            }
            /*
            else if(s.startsWith("Customer")){
                for(Object obj:objects){
                    if(obj instanceof Person){
                        if (((Person)obj).getId() == Integer.valueOf(sList.get(1))){
                            sList.remove(0);
                            sList.remove(0);
                            ArrayList<Product> prr = new ArrayList<>();
                            for(int i = 0; i < sList.size(); i++){
                                for(Object obj2:objects){
                                    if(obj2 instanceof Product){
                                        if (((Product)obj2).getProductName() == sList.get(i)){
                                            prr.add((Product)obj2);
                                        }
                                    }
                                }
                            }
                            Customer cu = new Customer(((Person)obj), prr);
                            objects.add(cu);
                            objects.remove(obj);
                        }
                    }
                }
            }
            */
            
            else if(s.startsWith("Product")){
                String name = sList.get(1);
                String[] numbers = sList.get(2).split("/");
                int year = Integer.valueOf(numbers[2]);
                int month = Integer.valueOf(numbers[1]) -1;
                int day = Integer.valueOf(numbers[0]);
                Calendar c = Calendar.getInstance();
                c.set(year, month, day);
                double price = Double.valueOf(sList.get(3));
                Product pro = new Product(name, c, price);
                objects.add(pro);
            }
            else if(s.startsWith("SalesEmployee")){
                for(Object obj:objects){
                    if(obj instanceof RegularEmployee){
                        if ( ((RegularEmployee)obj).getId() == Integer.valueOf(sList.get(1))){
                            sList.remove(0);
                            sList.remove(0);
                            ArrayList<Product> prr = new ArrayList<>();
                            for(int i = 0; i < sList.size(); i++){
                                for(Object obj2:objects){
                                    if(obj2 instanceof Product){
                                        if (((Product)obj2).getProductName() == sList.get(i)){
                                            prr.add(((Product)obj2));
                                        }
                                    }
                                }
                            }
                            SalesEmployee sm = new SalesEmployee( (RegularEmployee)obj, prr);
                            objects.add(sm);
                            objects.remove(obj);
                        }
                    }
                }
            }
            else{
                /*
                System.out.println("Error");
                System.out.println(s);
                */
            }
        }

        for(Object obj:objects){
            if(obj instanceof Manager){
                ((Manager)obj).distributeBonusBudget();
                ((Manager)obj).raiseSalary(0.2);
            }
            else if(obj instanceof RegularEmployee){
                ((RegularEmployee)obj).raiseSalary(0.3);
            }
            else if(obj instanceof Developer){
                ((Developer)obj).raiseSalary(0.23);
            }
            else if(obj instanceof SalesEmployee){
                ((SalesEmployee)obj).raiseSalary(0.18);
                /* en fazla satış yapan kişiye bonus
                SalesEmployee first;
                double maxSales;
                double sales;
                for(Product obj2: ((SalesEmployee)obj).getSales()){
                    sales +=obj2.getPrice();
                }
                */
            }
        }


        for(Object obj: objects){
            if(obj instanceof Employee){
                
            }
        }

        System.out.println("**********************CUSTOMERS************************");
        for(Object obj: objects){
            if(obj instanceof Customer){
            }
        }

        System.out.println("**********************PEOPLE************************");
        for(Object obj:objects){
            if(obj instanceof Person){
                System.out.println(((Person)obj).toString());
            }
        }



    }
}