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

2.4 Java Akshat

java codes

Uploaded by

Akshat Sharma
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)
15 views4 pages

2.4 Java Akshat

java codes

Uploaded by

Akshat Sharma
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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 2.4
Student Name: Akshat Sharma UID: 21BCS10347
Branch: CSE Section/Group: 614-B
Semester: 6th Date: 22/03/2024
Subject Name: PBL in Java with Lab Subject Code: 21CSH-319

1. Aim: Create a menu based Java application with the following options.1. Add
an Employee2.Display All3.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. Software Used: VS Code

3. Objective:
To learn about concept of File Handling in java.

To learn about LinkedList, Exception Handling in java.

4. Script and Output:


import java.util.*;

public class empdet {


public static void main(String[] args) {
System.out.println("Akshat _ 21BCS10347");
System.out.println("1. Add an Employee\n2. Display All\n3. Exit");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();

List<Integer> ids = new ArrayList<>();


List<String> names = new ArrayList<>();
List<Integer> ages = new ArrayList<>();
List<Double> salaries = new ArrayList<>();

while (n <= 3) {
if (n > 3) {
System.out.println("Wrong input entered!!");
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

break;

switch (n) {
case 1:
System.out.println("Enter Employee ID: ");
int id = sc.nextInt();
sc.nextLine();
System.out.println("Enter Employee Name: ");
String name = sc.nextLine();
System.out.println("Enter Employee Age: ");
int age = sc.nextInt();
System.out.println("Enter Employee Salary: ");
double salary = sc.nextDouble();

ids.add(id);
names.add(name);
ages.add(age);
salaries.add(salary);

System.out.println("Inserted Successfully");
break;

case 2:
System.out.println("----Report ");
for (int i = 0; i < ids.size(); i++) {
System.out.println(ids.get(i) +
" " + names.get(i) +
" " + ages.get(i) +
" " + salaries.get(i));
}
System.out.println("----End of Reort ");
break;
case 3:
System.out.println("Exiting the System");
break;

default:
System.out.println("Wrong input entered!!");
break;
}
if (n == 3)
break;

System.out.println("1. Add an Employee\n2. Display All\n3. Exit");


n = sc.nextInt();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
sc.nextLine();
}

sc.close();
}
}

OUTPUT:

Learning Outcomes:
 Learnt about various functions
 Learnt about ArrayList
 Learnt about how to add details
 Learnt about how to access the elements.

You might also like