EXPERIMENT 2.
Student Name: Aman Kumar UID: 19BCS1498
Branch: BE-CSE Section/Group: 19CSE-IS-4A
Semester: 6 th
Date of Performance:06/04/2022
Subject Name: PROJECT BASED LEARNING IN JAVA LAB
Subject Code: 22E-CSP-358
AIM: Write a program for Employee Management System.
TASK TO BE DONE:
Create a menu based Java application with the following options.
1. Add an Employee
2. Display All
3. Exit
If option 1 is selected, the application should gather details of the employee like
employee name, employee id, designation and salary and store it in a file.
If option 2 is selected, the application should display all the employee details.
If option 3 is selected the application should exit.
Sample Output:
Main Menu
1. Add an Employee
2. Display All
3. Exit
1
Enter Employee ID: 120
Enter Employee Name: Sudhir
Enter Employee Age: 33
Enter Employee Salary: 90000
Steps for experiment/practical/Code:
package unit2;
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
Learning outcomes (What I have learnt):
1. Understanding the List in java.
2. Understanding various concepts of Array List in java.
3. Understanding concepts of various functions of List and ArrayList.