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

20BCS1793 Java 2.4

Uploaded by

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

20BCS1793 Java 2.4

Uploaded by

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

Experiment No :- 2.

NAME – Lakshay Kumar


UID – 20BCS1793
SECTION – 20BCS703-A
SUBJECT – PROJECT BASED LEARNING IN JAVA LAB

Employee Management System


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.
Code:
import java.util.*;
public class employeeList
{
static ArrayList<String> empName = new ArrayList<>();
static ArrayList<String> eid = new ArrayList<>();
static ArrayList<String> designation = new ArrayList<>();
static ArrayList<Integer> salary = new ArrayList<>();
public static class Employee{

public void addData(String name1, String eid1, String designation1, int salary1){
empName.add(name1);
eid.add(eid1);
designation.add(designation1);
salary.add(salary1);
}

public void display(){


for (int i = 0; i < empName.size(); i++){
System.out.println("Name: " + empName.get(i));
System.out.println("Employee ID : " + eid.get(i));
System.out.println("Designation: " + designation.get(i));
System.out.println("Salary: " + salary.get(i));
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

while(true){
System.out.println("Enter Choices: ");
System.out.println("1. Add Employee");
System.out.println("2. Display");
System.out.println("3. Exit");

int choices = in.nextInt();

Employee emp = new Employee();

switch(choices){
case 1:
System.out.println("Enter your Name: ");
String name = in.next();
System.out.println("Enter your Designation: ");
String designation = in.next();
System.out.println("Enter your Eid: ");
String eid = in.next();
System.out.println("Enter your Salary: ");
int salary = in.nextInt();
emp.addData(name, eid, designation, salary);
continue;
case 2:
emp.display();
continue;
case 3:
return;
}
}
}
}

Output:
Learning outcomes (What I have learnt):
1. Learned about ArrayList.
2. Learned about Switch Statement.
3. Learned about ArrayList Travesal.

You might also like