0% found this document useful (0 votes)
85 views

Experiment 2.4: Write A Program For Employee Management System

The document describes an experiment to create an employee management system program with Java. The program allows a user to add employees by entering their ID, name, age, and salary. It stores employee details in an ArrayList. The user can then view all stored employee details or exit the program. The code creates an Employee class to store details, uses an ArrayList to store Employee objects, and implements a menu to allow adding employees or displaying all. Running the program outputs sample input/output of adding an employee and the main menu options.

Uploaded by

Lovelesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Experiment 2.4: Write A Program For Employee Management System

The document describes an experiment to create an employee management system program with Java. The program allows a user to add employees by entering their ID, name, age, and salary. It stores employee details in an ArrayList. The user can then view all stored employee details or exit the program. The code creates an Employee class to store details, uses an ArrayList to store Employee objects, and implements a menu to allow adding employees or displaying all. Running the program outputs sample input/output of adding an employee and the main menu options.

Uploaded by

Lovelesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

You might also like