In a software company Software Engineers, Sr. Software Engineers, Module Lead,
Technical Lead, Project Lead, Project Manager, Program Manager, Directors all
are the employees of the company but their work, perks, roles, responsibilities
differs. Create the Employee base class would provide the common behaviors of
all types of employee and also some behaviors properties that all employee must
have for that company. Also include search method to search an employee by
name.
Code:-
import java.util.*;
public class Employee
{
String name;
String role;
String work;
String perks;
String responsibility;
public Employee()
{
//System.out.println("\nDefault Constructor");
}
public void Create(String n, String r, String w, String p, String rs)
{
name=n;
role=r;
work =w;
perks=p;
responsibility=rs;
}
public void display()
{
System.out.println("Name - \t\t"+name);
System.out.println("Role - \t\t"+role);
System.out.println("Work - \t\t"+work);
System.out.println("Responsibility - \t"+responsibility);
System.out.println("Perks or salary - \t"+perks);
}
}
class Emp_Main extends Employee
{
static Employee[] emp;
public static int search(String nn)
{
System.out.println("Search for = "+nn+"\n");
for (int i = 0; i <emp.length; i++)
{
if (emp[i].name.equals(nn))
{
System.out.println(" "+nn+" found ...\n details are following ");
emp[i].display();
return 0;
}
}
System.out.println(" "+nn+" not found ...");
return 1;
}
public static void main(String ta[])
{
System.out.println("\t ----- CODING ADDA -----");
emp= new Employee[8];
emp[0] = new Employee();
emp[1] = new Employee();
emp[2] = new Employee();
emp[3] = new Employee();
emp[4] = new Employee();
emp[5] = new Employee();
emp[6] = new Employee();
emp[7] = new Employee();
emp[0].Create("Mr Raj","Software Engineers","Software Engineers","50,000","Responsible for Software Development");
emp[1].Create("Mr ALEX"," Sr. Software Engineers"," Sr. Software Engineers","60,000","Supervision");
emp[2].Create("Miss Tanu","Module Lead","Module Lead","63,000","Module related responsibility");
emp[3].Create("Miss Manu","Technical Lead","Technical Lead","40,000","Technical Leader related responsibility");
emp[4].Create("Mr Vikram","Project Lead","Module Lead","35,000","Module related responsibility");
emp[5].Create("Mr Talwinder Singh","Directors","Directors","150,000","all responsibility of Directors");
emp[6].Create("Mr Sandeep Khehra ","Program Manager","Program Manager","60,000","all responsibility of Program Manager");
emp[7].Create("Miss Manveen Kaur","Project Manager","Project Manager","65,000","all responsibility of Project Manager");
Scanner sc= new Scanner(System.in); //System.in is a standard input stream.
System.out.print("\n Enter a Name of Employee you want to search: ");
String nn= (String) sc.nextLine(); //reads string.
search(nn);
}
}
Output:-
1.