top of page

שאלה:

בjava: להגדיר מאגר עובדים ומנהלים. חלק מתכונות העובדים והמנהלים משותפות. צריך לנהל את המאגר. לעובדים שם משתמש, למנהלים שם משתמש וסיסמא. לכל מנהל יש כמה עובדים. צריך למיין את העובדים לפי המשכורת ולשלוף את זה עם המשכורת הגבוהה ביותר.

 

 

 

 

תשובה:

Main

public class main {
    
    public static void main(String[] args)
    {
        employee e = new employee();
        manager m = new manager();
        e.CreateEmployees();
        m.CreateManagers(e);
        e.PrintEmployees();
        m.PrintManagers();
        System.out.println("printnig all employee");
        
        m.RemoveEmployee(e, "SADasdASD11");
        m.RemoveEmployee(m, "SADasdASD3");
        m.PrintAllEmployees(e);
        
        
    }

}

Employee

import java.util.ArrayList;

import java.util.Collections;
import java.util.Comparator;

public class Employee 
{
public String firstName;
public String LastName;
public int salary;
public ArrayList<Employee> createEmployee = new ArrayList<Employee>();

public Employee()
{

}


public Employee(String firstName, String LastName,int salary)
{
      this.firstName= firstName;
      this.LastName= LastName;
      this.salary = salary;
}


public void initEmployss()
{

Employee e  = new  Employee ("asdASD","SDsdAS",899781);
Employee e1  = new  Employee ("asdASD1","SDsdAS1",89978);
Employee e2  = new  Employee ("asdASD2","SDsdAS2",8998);
Employee e3  = new Employee ("asdASD3","SDsdAS3",819978);
createEmployee.add(e);
createEmployee.add(e1);
createEmployee.add(e2);
createEmployee.add(e3);

}

   

public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}

public String employeeName(Employee e) 
{
return "Employee: " + e.firstName + " " + e.LastName;
}
public void sort()
{
Collections.sort(createEmployee, new Comparator<Employee>() 
{
public int compare(Employee E1, Employee E2)
{
return Integer.valueOf(E2.salary).compareTo(E1.salary);
}
});

for(int i =0 ; i<= createEmployee.size()-1;i++)
{
Employee e = createEmployee.get(i);
System.out.println(employeeName(e) + "  have salary " + e.salary);
}
}

}

Manager

public class manager extends employee
{
    public String pw;
    
    public manager(String first_name, String last_mane, String email, int salary, String pw) {
        super(first_name, last_mane, email, salary);
        this.pw = pw;
    }
    
    public manager() {
    }
    public ArrayList<manager> ManagerList = new ArrayList<manager>();
    
    public void CreateManagers (employee e)
    {
        manager m  = new manager ("asdASD","SDsdAS","SADasdASD",89978,"ASDasd");
        manager m1  = new manager ("asdASD1","SDsdAS1","SADasdASD1",89978,"ASDasd");
        manager m2  = new manager ("asdASD2","SDsdAS2","SADasdASD22",89978,"ASDasd");
        manager m3  = new manager ("asdASD3","SDsdAS3","SADasdASD3",89978,"ASDasd");
        if(UserNotExist(e, m.email))
            ManagerList.add(m);
        if(UserNotExist(e, m1.email))
            ManagerList.add(m1);
        if(UserNotExist(e, m2.email))
            ManagerList.add(m2);
        if(UserNotExist(e, m3.email))
            ManagerList.add(m3);
    }

    
    public void Addmanager(String first_name, String last_mane, String email, int salary, String pw) 
    {
        setFirst_name(first_name);
        setLast_mane(last_mane);
        setEmail(email);
        setSalary(salary);
        setpw(pw);
    }
    
    public void PrintManagers()
    {
        for(int i=0; i<=ManagerList.size()-1;i++)
        {
            manager ma = ManagerList.get(i);
            System.out.println( i + ". the manager " + ma.first_name + " " +  ma.last_mane  + " " +  ma.email  + " " +  ma.salary + " " + ma.pw);
        }
    }

    
    public void PrintAllEmployees(employee e)
    {
        e.PrintEmployees();
        PrintManagers();
    }
    
    
    public boolean RemoveEmployee(employee e, String email)
    {
        ArrayList<employee> user = e.Employees();
        for(int i=0; i<=user.size()-1;i++)
        {
            employee u = user.get(i);
            if(email ==u.email)
            {
                System.out.println("The employee remonved, " + u.email );
                user.remove(i);
                return true;
            }
        }
        for(int i=0; i<=ManagerList.size()-1;i++)
        {
            manager u = ManagerList.get(i);
            if(email ==u.email)
            {
                System.out.println("The employee remonved, " + u.email );
                ManagerList.remove(i);
                return true;
            }
        }
        return false;
    }
    
    
    
    public boolean UserNotExist(employee e, String email)
    {
        ArrayList<employee> user = e.Employees();
        
        for(int i=0; i<=user.size()-1;i++)
        {
            employee u = user.get(i);
            if(email ==u.email)
            {
                System.out.println("The employee cant add, the email exist! " + u.email );
                return false;
            }
        }
        return true;
    }
    
    public boolean printSalary(employee e)
    {
        ArrayList<employee> user = e.Employees();
        
        for(int i=0; i<=user.size()-1;i++)
        {
            employee u = user.get(i);
            if(email ==u.email)
            {
                System.out.println("The employee cant add, the email exist! " + u.email );
                return false;
            }
        }
        return true;
    }
    
    public int getpw() 
    {
        return salary;
    }
    
    public void setpw(String pw) 
    {
        this.pw = pw;
    }

}

Selenium - izselenium aoutomation tool

054-8059589

  • White Facebook Icon
  • White Twitter Icon
  • White Google+ Icon
  • White YouTube Icon

© 2017 by izselenium

bottom of page