0% found this document useful (0 votes)
94 views4 pages

2.4java 20BCS2864

The document describes an experiment to create an employee management system program with options to add an employee, display all employees, and exit the program. It provides the code to create an Employee class with ID, name, age, and salary attributes, and a Main class containing a menu loop to handle user input and call methods to add new employees to an arraylist or display all stored employees before exiting. The output screenshots would show the program functioning as intended by the given code.

Uploaded by

madhu jha
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)
94 views4 pages

2.4java 20BCS2864

The document describes an experiment to create an employee management system program with options to add an employee, display all employees, and exit the program. It provides the code to create an Employee class with ID, name, age, and salary attributes, and a Main class containing a menu loop to handle user input and call methods to add new employees to an arraylist or display all stored employees before exiting. The output screenshots would show the program functioning as intended by the given code.

Uploaded by

madhu jha
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 – 2.

4
Student Name :Rohan Kumar UID : 20BCS2864
Section/Group : 20BCS_MM-807(A) Branch : CSE
Date of Performance : 11th October 2022 _ Semester : 5th
Subject Name : Project Based Learning in Java Lab Subject Code : 20CSP – 321

1. Aim:

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.

2. Code for the program to be written:

import java.util.*;
class Employee {
int employeeId; String
employeeName; int
employeeAge; int
employeeSalary;
Employee(int id, String
name, int age, int salary)
{ employeeId = id;
employeeName = name;
employeeAge = age;
employeeSalary = salary;
}
} public class Main { public static
void main(String[] args) {
ArrayList < Employee > data = new ArrayList < > ();
Scanner sc = new Scanner(System.in);
System.out.println("Select one of the following options!!");
Boolean quit = false; while (true) {
System.out.println("1. Add an Employee");
System.out.println("2. Display All");
System.out.println("3. Exit");
System.out.print("Please enter your choice: ");
int option_selected = sc.nextInt(); switch
(option_selected) { case 1: {
System.out.print("Please enter employee id: ");
boolean flag = true; int id = sc.nextInt(); for
(Employee e: data) { if (e.employeeId
== id) { flag = false;
System.out.println("Employee id already exist!");
}
} if (flag)
{
System.out.print("Please enter employee name: ");
sc.nextLine();
String name = sc.nextLine();
System.out.print("Please enter employee age: "); int age
= sc.nextInt();
System.out.print("Please enter employee salary: ");
int salary = sc.nextInt(); data.add(new
Employee(id, name, age, salary)); }
break; } case 2: {
System.out.println("---------------Report---------------");
for (Employee e: data) {
System.out.println(e.employeeId + " " + e.employeeName + " " +
e.employeeAge + " " + e.employeeSalary);
}
System.out.println("-------------End of Report----------");
break; } case 3: { quit = true;
break; } default: {
System.out.println("Invalid number! Please enter valid number.");
}
} if
(quit)
break;
}
}
}

3. Output Screenshots:

You might also like