0% found this document useful (0 votes)
95 views7 pages

Anurag Tiwari Mca.10029.24 Assignment 9

Uploaded by

anurag6206299870
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views7 pages

Anurag Tiwari Mca.10029.24 Assignment 9

Uploaded by

anurag6206299870
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ANURAG TIWARI (MCA/10029/24)

ASSIGNMENT-9
1. Define an interface with three methods — earnings(), deductions() and bonus() and define
a Java class ,Manager" which uses this interface without implementing bonus() method. Also
define another Java class ,Substaff" which extends from ,Manager" class and implements
bonus() method. Write the complete program to find out earnings, deduction and bonus of a
sbstaff with basic salary amount entered by the user as per the following guidelines —
earning basic + DA (80% of basic) + HPuA (15% of basic)
deduction PF 12% of basic
bonus 50% of basic

CODE: -
import java.util.Scanner;

interface Salary {
double earnings();
double deductions();
double bonus();
}

class Manager implements Salary {


double basicSalary;

Manager(double basicSalary) {
this.basicSalary = basicSalary;
}
public double earnings() {
double DA = 0.50 * basicSalary;
double HRA = 0.15 * basicSalary;
return basicSalary + DA + HRA;
}

public double deductions() {


return 0.12 * basicSalary;
}

public double bonus() {


throw new UnsupportedOperationException("Bonus method not implemented");
}
}

class Substaff extends Manager {

Substaff(double basicSalary) {
super(basicSalary);
}

@Override
public double bonus() {
return 0.50 * basicSalary;
}
}
public class I1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the basic salary of the substaff: ");


double basicSalary = scanner.nextDouble();

Substaff substaff = new Substaff(basicSalary);

System.out.println("Earnings: " + substaff.earnings());


System.out.println("Deductions (PF): " + substaff.deductions());
System.out.println("Bonus: " + substaff.bonus());
}
}
OUTPUT :-

2. Define two packages as — General and Marketing. In General package define a class
"employee" with data members as empid(protected), ename(private) and a public method as
earnings() which calculate total earnings as
earnings = basic + DA (80% of basic) + HRA (15% of basic)
In Marketing package define a class , "sales" which is extending from , "employee" class and
has a method ta//owance() which calculates Travelling Allowance as 5% of total earning.
Write the programs to find out total earning of a sales person for the given basic salary
amount and print along with the emp id.
GENERAL  EMPLOYEE
->EMPID
->ENAME
->EARNINGS()
MARKETING  SALES
-> TALLOWANCE()
CODE :-

FILE:- General/Employee.java

package General;

public class Employee {


protected int empId;
private String ename;
private double basic;

public Employee(int empId, String ename, double basic) {


this.empId = empId;
this.ename = ename;
this.basic = basic;
}
public double earnings() {
double da = 0.80 * basic;
double hra = 0.15 * basic;
return basic + da + hra;
}

public int getEmpId() {


return empId;
}

public String getEname() {


return ename;
}
}

File :- Marketing/Sales.java

package Marketing;
import General.Employee;

public class Sales extends Employee {

public Sales(int empId, String ename, double basic) {


super(empId, ename, basic);
}

public double tAllowance() {


double totalEarnings = earnings();
return 0.05 * totalEarnings;
}

public void displayTotalEarnings() {


double totalEarnings = earnings();
double totalWithTA = totalEarnings + tAllowance();
System.out.println("Employee ID: " + getEmpId());
System.out.println("Employee Name: " + getEname());
System.out.println("Total Earnings (including TA): " + totalWithTA);
}
}

File :- Main.java

import Marketing.Sales;
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter Employee ID: ");


int empId = scanner.nextInt();

System.out.print("Enter Employee Name: ");


scanner.nextLine();
String ename = scanner.nextLine();

System.out.print("Enter Basic Salary: ");


double basic = scanner.nextDouble();

Sales salesPerson = new Sales(empId, ename, basic);


salesPerson.displayTotalEarnings();

scanner.close();
}
}

OUTPUT :-

You might also like