Skip to content

Instantly share code, notes, and snippets.

@rupalbarman
Last active May 29, 2017 05:12
Show Gist options
  • Select an option

  • Save rupalbarman/253e95466eb545b42eaac236242068a5 to your computer and use it in GitHub Desktop.

Select an option

Save rupalbarman/253e95466eb545b42eaac236242068a5 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
class Employee {
private String name;
private int empID;
private int yearsOfService;
private int salary;
private ArrayList<Certificate> certificates;
public Employee(String name, int empID, int yearsOfService, int salary) {
this.name= name;
this.empID= empID;
this.yearsOfService= yearsOfService;
this.salary= salary;
certificates= new ArrayList<Certificate>();
}
public String getName() {
return this.name;
}
public int getEmpID() {
return this.empID;
}
public int getYearsOfService() {
return this.yearsOfService;
}
public int getSalary() {
return this.salary;
}
public void setSalary(int salary) {
this.salary= salary;
}
public void setYearsOfService(int yearsOfService) {
this.yearsOfService= yearsOfService;
}
public void addCertification(int cid, String name, String desc) {
this.certificates.add(new Certificate(cid, name, desc));
}
public ArrayList<Certificate> getCertifications() {
return this.certificates;
}
}
class Certificate {
private int cID;
private String cName;
private String cDesc;
Certificate(int cid, String name, String desc) {
this.cID= cid;
this.cName= name;
this.cDesc= desc;
}
public int getID() {
return this.cID;
}
public String getName() {
return this.cName;
}
public String getDesc() {
return this.cDesc;
}
}
class Company {
private ArrayList<Employee> emp;
Company(){
this.emp= new ArrayList<Employee>();
}
public void incrementSalaryOfEmployees() {
for(int i=0; i<this.emp.size(); i++) {
int years= emp.get(i).getYearsOfService();
int salary= emp.get(i).getSalary();
if (years>=1 && years<=4) {
emp.get(i).setSalary((int)(1.10*salary));
} else if (years<=10) {
emp.get(i).setSalary((int)(1.20*salary));
} else {
emp.get(i).setSalary((int)(1.10*salary));
}
}
}
public void addNewEmployee(Employee e) {
this.emp.add(e);
}
public ArrayList<Employee> getEmployees() {
return this.emp;
}
public void listAllEmployees() {
for(Employee e: this.emp) {
System.out.println(e.getName());
System.out.println(e.getEmpID());
System.out.println(e.getSalary());
System.out.println(e.getYearsOfService());
ArrayList<Certificate> certs= e.getCertifications();
if(certs.size()>0) {
int idx=1;
System.out.println("\nCertificates\n\n");
for(Certificate c: certs) {
System.out.println(idx+ "\tID "+ c.getID()+ "\n\tName: "+ c.getName()+ "\n\tDescription: "+ c.getDesc());
idx++;
}
} else {
System.out.println("No certificates");
}
System.out.println();
}
}
}
public class EmployeeDetails {
public static void main(String []args) {
Company com= new Company();
Employee e1= new Employee("Barns", 1234, 3, 70000);
Employee e2= new Employee("Jack", 2345, 10, 29000);
e1.addCertification(1001, "Oracle Ceritified Java dev", "This certificate certifies the same");
com.addNewEmployee(e1);
com.addNewEmployee(e2);
com.incrementSalaryOfEmployees();
com.listAllEmployees();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment