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;
	
	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";
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getEmpid() {
		return empid;
	}
	
	public void setEmpid(String empid) {
		this.empid = empid;
	}
	
	public String getDepartment() {
		return department;
	}
	
	public void setDepartment(String department) {
		this.department = department;
	}
	
	public String getDesignation() {
		return designation;
	}
	
	public void setDesignation(String designation) {
		this.designation = designation;
	}
	
	public String getExperience() {
		return experience;
	}
	
	public void setExperience(String experience) {
		this.experience = experience;
	}
	
	public double getBasicPay() {
		return basicPay;
	}
	
	public void setBasicPay(double basicPay) {
		this.basicPay = basicPay;
	}
	
	public double getDA() {
		return DA;
	}
	
	public void setDA(double dA) {
		DA = dA;
	}
	
	public double getGradePay() {
		return gradePay;
	}
	
	public void setGradePay(double gradePay) {
		this.gradePay = gradePay;
	}
	
	public double getPersonalPay() {
		return personalPay;
	}
	
	public void setPersonalPay(double personalPay) {
		this.personalPay = personalPay;
	}
	
	public double getiTax() {
		return iTax;
	}
	
	public void setiTax(double iTax) {
		this.iTax = iTax;
	}
	
	public double getProfessionalTax() {
		return professionalTax;
	}
	
	public void setProfessionalTax(double professionalTax) {
		this.professionalTax = professionalTax;
	}
	
	public double getEpf() {
		return epf;
	}
	
	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;
	}
	
	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: {
				
			}
				break;
			default: {
				System.out.println("Wrong menu item.");
			}
				break;
			}
		}
		input.close();
	}
}
Comments