You are on page 1of 10

ASSIGNMENT 3 INHERITANCE

NAME :- Vaishnavi
JUNAID AZIZ PATHAN
Appasaheb Nemane
ROLL NO :- 2041
204

Inheritance Design and develop inheritance for a given case study, identify objects and relationships and
implement inheritance wherever applicable. Employee class has Emp_name, Emp_id, Address, Mail_id,
and Mobile_no as members. Inherit the classes: Programmer, Team Lead, Assistant Project Manager and
Project Manager from employee class. Add Basic Pay (BP) as the member of all the inherited classes with
97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for staff club fund. Generate pay slips
for the employees with their gross and net salary.

import java.util.*;

import java.util.Scanner;

class Employee{

Scanner sc = new Scanner(System.in);

String emp_name, mail_id, address;

int emp_id;

long mob_no;

void input(){

System.out.println("Enter the Employee Name: ");

emp_name = sc.nextLine();

System.out.println("Enter the Employee ID: ");

emp_id = sc.nextInt();

System.out.println("Enter the Employee Email Id: ");

mail_id = sc.next();

System.out.println("Enter the Employee Mobile No: ");

mob_no = sc.nextLong();

System.out.println("Enter the Employee Address: ");

address = sc.next();

void display(){
System.out.println("EMPLOYEE DETAILS");

System.out.println("**************************************************************************");

System.out.println("NAME\tID\tEMAIL-ID\t\tADDRESS\t\tMOBILE");

System.out.println("*********************************************************************
*****");

System.out.println(emp_name+"\t"+emp_id+"\t"+mail_id+"\t\t"+address+"\t\t"+mob_no +"\n");

class Programmer extends Employee{

double basic_pay, da, club_fund, pf,hra;

double gross_salary, net_salary;

void get_programmer(){

System.out.print("Enter the Basic Pay of the Programmer = Rs.");

basic_pay = sc.nextDouble();

void result_programmer(){

da=basic_pay*.97;

hra=basic_pay*.10;

pf=basic_pay*.12;

club_fund=basic_pay*0.001;

gross_salary=basic_pay + hra +da;

net_salary = gross_salary - pf - club_fund;

System.out.println("****************************************************************");

System.out.println(" BASIC PAY : "+basic_pay);

System.out.println(" HRA : "+hra);

System.out.println(" PF : "+pf);

System.out.println("CLUB FUND : "+club_fund);

System.out.println(" GROSS SALARY : "+gross_salary);

System.out.println(" NET SALARY : "+ net_salary);

System.out.println("****************************************************************");

}
class TeamLeader extends Employee{

double basic_pay, da, club_fund, pf,hra;

double gross_salary, net_salary;

void get_TeamLeader(){

System.out.print("Enter the Basic Pay of the Team Leader = Rs.");

basic_pay = sc.nextDouble();

void result_TeamLeader(){

da=basic_pay*.97;

hra=basic_pay*.10;

pf=basic_pay*.12;

club_fund=basic_pay*0.001;

gross_salary=basic_pay + hra +da;

net_salary = gross_salary - pf - club_fund;

System.out.println("****************************************************************");

System.out.println(" BASIC PAY : "+basic_pay);

System.out.println(" HRA : "+hra);

System.out.println(" PF : "+pf);

System.out.println("CLUB FUND : "+club_fund);

System.out.println(" GROSS SALARY : "+gross_salary);

System.out.println(" NET SALARY : "+ net_salary);

System.out.println("****************************************************************");

class Asst_Manager extends Employee{

double basic_pay, da, club_fund, pf,hra;

double gross_salary, net_salary;

void get_Asst_Manager(){

System.out.print("Enter the Basic Pay of the Assistant Project Manager = Rs.");

basic_pay = sc.nextDouble();

}
void result_Asst_Manager(){

da=basic_pay*.97;

hra=basic_pay*.10;

pf=basic_pay*.12;

club_fund=basic_pay*0.001;

gross_salary=basic_pay + hra +da;

net_salary = gross_salary - pf - club_fund;

System.out.println("****************************************************************");

System.out.println(" BASIC PAY : "+basic_pay);

System.out.println(" HRA : "+hra);

System.out.println(" PF : "+pf);

System.out.println("CLUB FUND : "+club_fund);

System.out.println(" GROSS SALARY : "+gross_salary);

System.out.println(" NET SALARY : "+ net_salary);

System.out.println("****************************************************************");

class Manager extends Employee{

double basic_pay, da, club_fund, pf,hra;

double gross_salary, net_salary;

void get_Manager(){

System.out.print("Enter the Basic Pay of the Project Manager = Rs.");

basic_pay = sc.nextDouble();

void result_Manager(){

da=basic_pay*.97;

hra=basic_pay*.10;

pf=basic_pay*.12;

club_fund=basic_pay*0.001;

gross_salary=basic_pay + hra +da;

net_salary = gross_salary - pf - club_fund;


System.out.println("****************************************************************");

System.out.println(" BASIC PAY : "+basic_pay);

System.out.println(" HRA : "+hra);

System.out.println(" PF : "+pf);

System.out.println("CLUB FUND : "+club_fund);

System.out.println(" GROSS SALARY : "+gross_salary);

System.out.println(" NET SALARY : "+ net_salary);

System.out.println("****************************************************************");

public class oop2{

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

int ch;

do{

System.out.println("Enter your post:");

System.out.println("1.PROGRAMMER\n2.TEAM LEADER\n3.ASSISTANT PROJECT


MANAGER\n4.PROJECT MANAGER\n5.EXIT");

ch = sc.nextInt();

switch(ch){

case 1:

Programmer obj1 = new Programmer();

obj1.input();

obj1.display();

obj1.get_programmer();

obj1.result_programmer();

break;

case 2:

TeamLeader obj2 = new TeamLeader();

obj2.input();

obj2.display();

obj2.get_TeamLeader();
obj2.result_TeamLeader();

break;

case 3:

Asst_Manager obj3 = new Asst_Manager();

obj3.input();

obj3.display();

obj3.get_Asst_Manager();

obj3.result_Asst_Manager();

break;

case 4:

Manager obj4 = new Manager();

obj4.input();

obj4.display();

obj4.get_Manager();

obj4.result_Manager();

break;

case 5:

System.out.println("EXIT!");

break;

}while(ch!=5);

OUTPUT:-
C:\Users\Admin>cd Documents

C:\Users\Admin\Documents>cd java

C:\Users\Admin\Documents\java>javac oop2.java

C:\Users\Admin\Documents\java>java oop2
Enter your post:

1.PROGRAMMER

2.TEAM LEADER

3.ASSISTANT PROJECT MANAGER

4.PROJECT MANAGER

5.EXIT

Enter the Employee Name:

Zubair

Enter the Employee ID:

2048

Enter the Employee Email Id:

zub@gmail.com

Enter the Employee Mobile No:

7249247724

Enter the Employee Address:

PUNE

EMPLOYEE DETAILS

**************************************************************************

NAME ID EMAIL-ID ADDRESS MOBILE

**************************************************************************

Zubair 2048 zub@gmail.com PUNE 7249247724

Enter the Basic Pay of the Programmer = Rs.30000

****************************************************************

BASIC PAY : 30000.0

HRA : 3000.0

PF : 3600.0

CLUB FUND : 30.0

GROSS SALARY : 62100.0

NET SALARY : 58470.0

****************************************************************

Enter your post:

1.PROGRAMMER

2.TEAM LEADER

3.ASSISTANT PROJECT MANAGER


4.PROJECT MANAGER

5.EXIT

Enter the Employee Name:

RAJU

Enter the Employee ID:

123

Enter the Employee Email Id:

raj@gmail.com

Enter the Employee Mobile No:

12345678

Enter the Employee Address:

NASHIK

EMPLOYEE DETAILS

**************************************************************************

NAME ID EMAIL-ID ADDRESS MOBILE

**************************************************************************

RAJU 123 raj@gmail.com NASHIK 12345678

Enter the Basic Pay of the Team Leader = Rs.40000

****************************************************************

BASIC PAY : 40000.0

HRA : 4000.0

PF : 4800.0

CLUB FUND : 40.0

GROSS SALARY : 82800.0

NET SALARY : 77960.0

****************************************************************

Enter your post:

1.PROGRAMMER

2.TEAM LEADER

3.ASSISTANT PROJECT MANAGER

4.PROJECT MANAGER

5.EXIT

Enter the Employee Name:


DEEPAK

Enter the Employee ID:

4321

Enter the Employee Email Id:

DEEP@gmail.com

Enter the Employee Mobile No:

12345678

Enter the Employee Address:

HARYANA

EMPLOYEE DETAILS

**************************************************************************

NAME ID EMAIL-ID ADDRESS MOBILE

**************************************************************************

DEEPAK 4321 DEEP@gmail.com HARYANA 12345678

Enter the Basic Pay of the Assistant Project Manager = Rs.50000

****************************************************************

BASIC PAY : 50000.0

HRA : 5000.0

PF : 6000.0

CLUB FUND : 50.0

GROSS SALARY : 103500.0

NET SALARY : 97450.0

****************************************************************

Enter your post:

1.PROGRAMMER

2.TEAM LEADER

3.ASSISTANT PROJECT MANAGER

4.PROJECT MANAGER

5.EXIT

Enter the Employee Name:

SOHAM

Enter the Employee ID:

5678

Enter the Employee Email Id:


soham@gmail.com

Enter the Employee Mobile No:

886504804

Enter the Employee Address:

JHARKHAND

EMPLOYEE DETAILS

**************************************************************************

NAME ID EMAIL-ID ADDRESS MOBILE

**************************************************************************

SOHAM 5678 soham@gmail.com JHARKHAND 886504804

Enter the Basic Pay of the Project Manager = Rs.60000

****************************************************************

BASIC PAY : 60000.0

HRA : 6000.0

PF : 7200.0

CLUB FUND : 60.0

GROSS SALARY : 124200.0

NET SALARY : 116940.0

****************************************************************

Enter your post:

1.PROGRAMMER

2.TEAM LEADER

3.ASSISTANT PROJECT MANAGER

4.PROJECT MANAGER

5.EXIT

EXIT!

You might also like