import java.util.ArrayList;
import java.util.Scanner;
class Employee {
private String name;
private String empid;
private String department;
private String designation;
private String experience;
private double basicPay;
private double DA;
private double gradePay;
private double personalPay;
private double iTax;
private double professionalTax;
private double epf;
/**
* Constructor
*
* @param name
* @param empid
* @param department
* @param designation
* @param experience
* @param basicPay
* @param DA
* @param gradePay
* @param personalPay
* @param iTax
* @param professionalTax
* @param epf
*/
public Employee(String name, String empid, String department, String designation, String experience,
double basicPay, double DA, double gradePay, double personalPay, double iTax, double professionalTax,
double epf) {
this.name = name;
this.empid = empid;
this.department = department;
this.designation = designation;
this.experience = experience;
this.basicPay = basicPay;
this.DA = DA;
this.gradePay = gradePay;
this.personalPay = personalPay;
this.iTax = iTax;
this.professionalTax = professionalTax;
this.epf = epf;
}
@Override
public String toString() {
return "Employee name: " + this.name + "\n" + "Employee ID: " + this.empid + "\n" + "Employee department: "
+ this.department + "\n" + "Employee designation: " + this.designation + "\n" + "Employee experience: "
+ this.experience + "\n" + "Employee basic pay: " + this.basicPay + "\n" + "Employee DA: " + this.DA
+ "\n" + "Employee grade pay: " + this.gradePay + "\n" + "Employee personal pay: " + this.personalPay
+ "\n" + "Employee iTax: " + this.iTax + "\n" + "Employee professional tax: " + this.professionalTax
+ "\n" + "Employee epf: " + this.epf + "\n";
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the empid
*/
public String getEmpid() {
return empid;
}
/**
* @param empid the empid to set
*/
public void setEmpid(String empid) {
this.empid = empid;
}
/**
* @return the department
*/
public String getDepartment() {
return department;
}
/**
* @param department the department to set
*/
public void setDepartment(String department) {
this.department = department;
}
/**
* @return the designation
*/
public String getDesignation() {
return designation;
}
/**
* @param designation the designation to set
*/
public void setDesignation(String designation) {
this.designation = designation;
}
/**
* @return the experience
*/
public String getExperience() {
return experience;
}
/**
* @param experience the experience to set
*/
public void setExperience(String experience) {
this.experience = experience;
}
/**
* @return the basicPay
*/
public double getBasicPay() {
return basicPay;
}
/**
* @param basicPay the basicPay to set
*/
public void setBasicPay(double basicPay) {
this.basicPay = basicPay;
}
/**
* @return the dA
*/
public double getDA() {
return DA;
}
/**
* @param dA the dA to set
*/
public void setDA(double dA) {
DA = dA;
}
/**
* @return the gradePay
*/
public double getGradePay() {
return gradePay;
}
/**
* @param gradePay the gradePay to set
*/
public void setGradePay(double gradePay) {
this.gradePay = gradePay;
}
/**
* @return the personalPay
*/
public double getPersonalPay() {
return personalPay;
}
/**
* @param personalPay the personalPay to set
*/
public void setPersonalPay(double personalPay) {
this.personalPay = personalPay;
}
/**
* @return the iTax
*/
public double getiTax() {
return iTax;
}
/**
* @param iTax the iTax to set
*/
public void setiTax(double iTax) {
this.iTax = iTax;
}
/**
* @return the professionalTax
*/
public double getProfessionalTax() {
return professionalTax;
}
/**
* @param professionalTax the professionalTax to set
*/
public void setProfessionalTax(double professionalTax) {
this.professionalTax = professionalTax;
}
/**
* @return the epf
*/
public double getEpf() {
return epf;
}
/**
* @param epf the epf to set
*/
public void setEpf(double epf) {
this.epf = epf;
}
}
public class EmployeeProject {
private static int getEmployeeById(ArrayList<Employee> employees, String empid) {
for (int i = 0; i < employees.size(); i++) {
if (employees.get(i).getEmpid().compareTo(empid) == 0) {
return i;
}
}
return -1;
}
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int ch = -1;
ArrayList<Employee> employees = new ArrayList<Employee>();
while (ch != 5) {
System.out.println("1. Add");
System.out.println("2. Edit");
System.out.println("3. Delete");
System.out.println("4. Display the employee details");
System.out.println("5. Exit");
System.out.print("Your choice: ");
ch = input.nextInt();
switch (ch) {
case 1: {
input.nextLine();
System.out.print("Enter employee name: ");
String name = input.nextLine();
System.out.print("Enter employee ID: ");
String empid = input.nextLine();
System.out.print("Enter employee department: ");
String department = input.nextLine();
System.out.print("Enter employee designation: ");
String designation = input.nextLine();
System.out.print("Enter employee experience: ");
String experience = input.nextLine();
System.out.print("Enter employee basic pay: ");
double basicPay = input.nextDouble();
System.out.print("Enter employee DA: ");
double DA = input.nextDouble();
System.out.print("Enter employee grade pay: ");
double gradePay = input.nextDouble();
System.out.print("Enter employee personal pay: ");
double personalPay = input.nextDouble();
System.out.print("Enter employee iTax: ");
double iTax = input.nextDouble();
System.out.print("Enter employee professional tax: ");
double professionalTax = input.nextDouble();
System.out.print("Enter employee epf: ");
double epf = input.nextDouble();
Employee newEmployee = new Employee(name, empid, department, designation, experience, basicPay, DA,
gradePay, personalPay, iTax, professionalTax, epf);
employees.add(newEmployee);
System.out.println("\nEmployee has been added.\n");
}
break;
case 2: {
input.nextLine();
System.out.print("Enter employee ID to edit: ");
String empid = input.nextLine();
int index = getEmployeeById(employees, empid);
if (index != -1) {
System.out.print("Enter a new employee name: ");
String name = input.nextLine();
System.out.print("Enter a new employee department: ");
String department = input.nextLine();
System.out.print("Enter a new employee designation: ");
String designation = input.nextLine();
System.out.print("Enter a new employee experience: ");
String experience = input.nextLine();
System.out.print("Enter a new employee basic pay: ");
double basicPay = input.nextDouble();
System.out.print("Enter a new employee DA: ");
double DA = input.nextDouble();
System.out.print("Enter a new employee grade pay: ");
double gradePay = input.nextDouble();
System.out.print("Enter a new employee personal pay: ");
double personalPay = input.nextDouble();
System.out.print("Enter a new employee iTax: ");
double iTax = input.nextDouble();
System.out.print("Enter a new employee professional tax: ");
double professionalTax = input.nextDouble();
System.out.print("Enter a new employee epf: ");
double epf = input.nextDouble();
Employee newEmployee = new Employee(name, empid, department, designation, experience, basicPay, DA,
gradePay, personalPay, iTax, professionalTax, epf);
employees.remove(index);
employees.add(index, newEmployee);
System.out.println("\nEmployee has been updated.\n");
} else {
System.out.println("\nWrong employee ID.\n");
}
}
break;
case 3: {
input.nextLine();
System.out.print("Enter employee ID to delete: ");
String empid = input.nextLine();
int index = getEmployeeById(employees, empid);
if (index != -1) {
employees.remove(index);
System.out.println("\nEmployee has been deleted.\n");
} else {
System.out.println("\nWrong employee ID.\n");
}
}
break;
case 4: {
input.nextLine();
System.out.print("Enter employee ID to display: ");
String empid = input.nextLine();
int index = getEmployeeById(employees, empid);
if (index != -1) {
System.out.println(employees.get(index).toString());
} else {
System.out.println("\nWrong employee ID.\n");
}
}
break;
case 5: {
// exit
}
break;
default: {
System.out.println("Wrong menu item.");
}
break;
}
}
input.close();
}
}
Comments
Leave a comment