0% found this document useful (0 votes)
23 views9 pages

Assignment No 2 (Aniket Digge)

Uploaded by

Aniket Digge
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)
23 views9 pages

Assignment No 2 (Aniket Digge)

Uploaded by

Aniket Digge
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/ 9

Assignment No.

2
PQR & Company Ltd two kinds of employee, Permanent and Contractual .The Permanent
Employee has monthly salary and PF which is 15% of salary. Contractual employee has
contract period and contract amount. Every employee has id (for permanent ids are like
P1001,P1002... and for contractual ids are like C1001,C1002... etc.), name, dept-name. Id for
permanent will be in even number that of odd number for contractual employee. The input for
any employee is in comma(,) separate format eg:

a. 106,Eric Miller,Finance,35000.00 -> for Permanent employee.

b. 111,Roger Steven,Sales,5,750000.00 -> Contractual employee.

Any type of employee needs to pay tax which is 10% of annual salary. You need to create

A) class Employee with private member data

String employeeId,

String employeeName,

String department

Create getter/setter methods and constructors.

calculateTax()-> without body

override toString() in String.format("%-10s %-20s %-15s").

The class must implement Comparable interface

B) class PermanentEmployee inherited from Employee with private member data

Double monthlySalary,

Double pf, (15% of monthlySalary)

Double tax,

Create getter/setter methods and constructors.

override calculateTax()

override toString() in String.format("%-15s %-15s"...)

C) class ContractEmployee inherited from Employee with private member data

Integer contractPeriod,

Double contarctAmount,

Double tax,

Create getter/setter methods and constructors.


override calculateTax()

override toString() in String.format("%-15s %-15s"...)

D) class Main with method public static void main(String [] arg)-> In this method

a. Only one Employee reference variable is needed to declare.

b. Type of employee i.e permanent employee or contractual employee will be decided


automatically through id.

c. Finally display employee details .

Ans:-

import java.util.Scanner;

class Employee{

private String employeeId="";

private String employeeName="";

private String department="";

public Employee(){}

public void getter(String employeeId, String employeeName, String department) {

this.employeeId = employeeId;

this.employeeName = employeeName;

this.department = department;

public void setter() {

System.out.println("Employee ID = "+employeeId);

System.out.println("Employee Name = "+employeeName);

System.out.println("Department = "+department);
}

public void calculateTax(){}

@Override

public String toString() {

String.format("%-10s %-20s %-15s", employeeId);

return super.toString();

class PermanentEmployee extends Employee{

private Double monthlySalary;

private Double pf;

private Double tax;

public PermanentEmployee(){}

public void getter(Double monthlySalary){

this.monthlySalary = monthlySalary;

pf = monthlySalary*0.15;

public void calculateTax(){

tax = monthlySalary*0.10;

}
public void setter(){

System.out.println("Monthley Salary = "+monthlySalary);

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

System.out.println("TAX = "+tax);

@Override

public String toString() {

String.format("%-15s %-15s", monthlySalary);

return super.toString();

class ContractEmployee extends Employee{

private int contractPeriod;

private Double contarctAmount;

Double tax;

public ContractEmployee(){}

public void getter(int contractPeriod, Double contarctAmount){

this.contarctAmount = contarctAmount;

this.contractPeriod = contractPeriod;

public void calculateTax(){

tax = contarctAmount*contractPeriod*0.10;
}

public void setter(){

System.out.println("Contract Period = "+contractPeriod);

System.out.println("Contract Amount = "+contarctAmount);

System.out.println("TAX = "+tax);

@Override

public String toString() {

String.format("%-15s %-15s", contarctAmount);

return super.toString();

public class Employee_details {

public static void main(String[] args) {

String strid;

String strname;

String strdept;

Scanner sc = new Scanner(System.in);

System.out.println("Enter employee Id : ");

strid = sc.nextLine();

System.out.println("Enter employee Name : ");

strname = sc.nextLine();

System.out.println("Enter Department : ");

strdept = sc.nextLine();
for (int i = 0; i < strid.length(); i++) {

if(i==4){

int n = strid.charAt(i);

if(n%2==0){

System.out.println();

System.out.println("Perment Employee.");

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

System.out.println();

Employee e = new Employee();

e.getter(strid, strname, strdept);

e.setter();

PermanentEmployee pe = new PermanentEmployee();

System.out.println();

System.out.println("Enter Monthly Salary : ");

Double sal = Double.parseDouble(sc.nextLine());

pe.getter(sal);

pe.calculateTax();

pe.setter();

else{

System.out.println();

System.out.println("Contract Employee.");

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

System.out.println();

Employee e = new Employee();

e.getter(strid, strname, strdept);


e.setter();

ContractEmployee ce = new ContractEmployee();

System.out.println();

System.out.println("Enter COntract Peroid : ");

int pd = Integer.parseInt(sc.nextLine());

System.out.println("Enter COntract Amount : ");

Double amt = Double.parseDouble(sc.nextLine());

ce.getter(pd, amt);

ce.calculateTax();

ce.setter();

Output:-

You might also like