Experiment 2.4: Write A Program For Employee Management System
Experiment 2.4: Write A Program For Employee Management System
import java.util.ArrayList;
import java.util.Scanner;
class Employee{
int e_id,e_age;
String e_name;
double e_salary;
public Employee(int e_id,String e_name,int e_age,double e_salary) {
this.e_id=e_id;
this.e_name=e_name;
this.e_age=e_age;
this.e_salary=e_salary;
}
}
public class Question2_4 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
ArrayList<Employee> list = new ArrayList<>();
while(true) {
System.out.println("Main Menu\n1.Add an Employee\n2.Display All\n3.Exit");
int k=sc.nextInt();
switch(k) {
case 1:int id,age;
String name;
double salary;
System.out.println("Enter Employee ID:");
id=sc.nextInt();
System.out.println("Enter Employee Name:");
name=sc.next();
System.out.println("Enter Employee Age:");
age=sc.nextInt();
System.out.println("Enter Employee Salary:");
salary=sc.nextDouble();
Employee e = new Employee(id,name,age,salary);
list.add(e);
break;
case 2: System.out.println("------Report-------");
for(Employee a:list) {
System.out.println(a.e_id+a.e_name+a.e_age+a.e_salary);
}
break;
case 3: System.exit(0);
break;
default:System.out.println("Enter correct option:");
break;
}
}
}
}
Result/Output