SmartPack is a packers and movers agency having offices across various cities in
ID: 3529392 • Letter: S
Question
SmartPack is a packers and movers agency having offices across various cities in the country. They have around 5000 employees in their rolls handling various roles in various offices. With increasing number of employees and offices, several functions such as employee data management, payroll etc is becoming very complicated and time consuming. They are planning to automate such functions to efficiently manage these processes Two of the classes that were identified are SmartPack and Employee. Develop these two classes and write programs to perform the following functions: 1. Add an employee 2.Find number of employees having a particular designationExplanation / Answer
Below is the working code.Its working fine in eclipse. The two classes are.
--------------------------------------------------------------------------------
SmartPack.java
--------------------------------
import java.util.ArrayList;
import java.util.Scanner;
public class SmartPack {
ArrayList<Employee> emp=new ArrayList<Employee>();
public void addEmployee()
{
Scanner scan=new Scanner(System.in);
Employee temp=new Employee();
System.out.println("enter the customer details:");
System.out.println("enter name:");
temp.name=scan.nextLine();
System.out.println("enter employee Id:");
temp.empId=Integer.parseInt(scan.nextLine());
System.out.println("enter designation:");
temp.designation=scan.nextLine();
emp.add(temp);
System.out.println("Successfullty added:");
getOption();
}
public void findEmployee()
{
Scanner scan=new Scanner(System.in);
System.out.println("enter the designation:");
String des=scan.nextLine();
int flag=0;
for(int i=0;i<emp.size();i++)
{
if(emp.get(i).designation.equals(des))
{
System.out.println("employee found ");
flag=1;
}
}
if(flag==0)
System.out.println("not found");
getOption();
}
public void getOption(){
Scanner scan=new Scanner(System.in);
System.out.println("Chosse option");
System.out.println("1.Add Employee");
System.out.println("2.Find Employee");
System.out.println("Enter your choice");
int choice=Integer.parseInt(scan.nextLine());
switch(choice)
{
case 1:
addEmployee();
break;
case 2:
findEmployee();
break;
default:
System.out.println("wrong choice");
}
}
public static void main(String[] args)
{
SmartPack s=new SmartPack();
s.getOption();
}
}
---------------------------------
Employee.java
---------------------------
public class Employee {
String name;
int empId;
String designation;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.