You are on page 1of 3

StackTester

import entity.*;
import java.util.Stack;

public class StackTester{


public static void main (String [] args){

Stack<Employee> stack = new Stack<>();

stack.push(new Employee(100,"JohnSmith",23,19304.54, new


Department(10,"Marketing")));
stack.push(new Employee(101,"Eric Page",25,34304.54, new
Department(11,"Research and Development")));
stack.push(new Employee(102,"Caroline Santos",28,19304.54, new
Department(12,"Human Resources")));

System.out.println("Stacksize:" + stack.size());
System.out.println("");
System.out.println("Stack peek \n " + stack.peek().getEmployeeInfo());
System.out.println("");
System.out.println("Peforming pop operation ....");
System.out.println("");

while (!stack.empty()){
Employee e = stack.pop();
System.out.println(e.getEmployeeInfo());

System.out.println("---------------------------------------------------------------
-----");
}
if (stack.empty()){
System.out.println("Stack is empty............");
}

}
}

Department

public class Department {


private int id;
private String name;

public Department (int id,String name){

this.setId(id);
this.setName(name);
}

public Department(){

public int getId(){


return id;
}
public void setId( int id){
this.id = id;
}
public String getName(){
return name;
}
public void setName (String name){
this.name = name;
}
}

Employee

public class Employee {


private int id;
private String name;
private int age;
private double salary;
private Department department = new Department();

public Employee (int id, String name, int age,double salary,Department


department){

this.setId(id);
this.setName(name);
this.setAge(age);
this.setSalary(salary);
this.setDepartment(department);
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}

public int getAge(){


return age;

}
public void setAge(int age){
this.age = age;

}
public double getSalary(){
return salary;

}
public void setSalary(double salary){
this.salary = salary;

}
public Department getDepartment(){
return department;

}
public void setDepartment(Department department){
this.department = department;

}
public String getEmployeeInfo(){
return "Employee Id:" + id + "\nName" + name + "\nAge:" + age +
"\nSalary:" + salary + "\nDepartment:" + department.getName();
}
}

You might also like