Created
May 28, 2021 12:11
-
-
Save kshitijvarshne1/1c4c80e61ae056e247f5289d69e8387d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 28-May-21 | |
* Time: 5:15 PM | |
* File: Employee.java | |
*/ | |
package May.may28_21; | |
public class Employee { | |
private final short id; | |
private final String name; | |
private double salary; | |
private byte noOfLeaves; | |
public Employee(short id, String name, double salary, byte noOfLeaves) { | |
this.id = id; | |
this.name = name; | |
this.salary = salary; | |
this.noOfLeaves = noOfLeaves; | |
} | |
public short getId() { | |
return id; | |
} | |
public String getName() { | |
return name; | |
} | |
public double getSalary() { | |
return salary; | |
} | |
public void setSalary(double salary) { | |
this.salary = salary; | |
} | |
public byte getNoOfLeaves() { | |
return noOfLeaves; | |
} | |
public void setNoOfLeaves(byte noOfLeaves) { | |
this.noOfLeaves = noOfLeaves; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 28-May-21 | |
* Time: 5:21 PM | |
* File: EmployeeLeaveCalculator.java | |
*/ | |
package May.may28_21; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class EmployeeLeaveCalculator { | |
public List<Short> getDefaultEmployeeIDList(List<Employee> employeeList) { | |
List<Short> result = new ArrayList<>(); | |
for (Employee e : employeeList) { | |
if (e.getNoOfLeaves() > 25) { | |
result.add(e.getId()); | |
e.setSalary(e.getSalary() * .01 + e.getSalary()); | |
} | |
} | |
return result; | |
} | |
public ArrayList<String> getNumberOfLeaves(List<Employee> employeeList) { | |
ArrayList<String> result = new ArrayList<>(); | |
for (Employee e : employeeList) { | |
result.add(e.getName() + "-" + e.getNoOfLeaves()); | |
} | |
return result; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 28-May-21 | |
* Time: 5:24 PM | |
* File: Main.java | |
*/ | |
package May.may28_21; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Main { | |
public static void main(String[] args) { | |
List<Employee> employeeList = new ArrayList<>(); | |
employeeList.add(new Employee((short) 1, "John", 600.0, (byte) 33)); | |
employeeList.add(new Employee((short) 2, "sam", 60.0, (byte) 1)); | |
employeeList.add(new Employee((short) 3, "tan", 900.0, (byte) 93)); | |
employeeList.add(new Employee((short) 4, "panm", 660.0, (byte) 9)); | |
employeeList.add(new Employee((short) 5, "kiki", 1000.0, (byte) 3)); | |
EmployeeLeaveCalculator e = new EmployeeLeaveCalculator(); | |
System.out.println(e.getDefaultEmployeeIDList(employeeList).toString()); | |
System.out.println(e.getNumberOfLeaves(employeeList).toString()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment