* Make a class to calculate the Salary of the person (Employee, PL) such that,
* 1)Basics is not decided in the class, but provided by the person.
* 2)It can calculate the HRA and the salary, depending upon the Basic.
* Make two different class, One for Employee and other for PL.
* Print the Salary of each Person with Basic and HRA amounts.
* (Abstract class need to be used.)
*
*
*/
/**
* abstract parent class for salary calculation
*/
abstract class SalaryCalc {
// RATE OF HRA for employee
static final float HRA = 12;
// basic salary
float flBasic;
// calculation method
public abstract void calcSalary();
}
/**
* it extends SalaryCalc for employee salary calculation
*
* @author Ritesh
*
*/
class Employee extends SalaryCalc {
/**
* constructor for salary input
*
* @param flSal
* basic salary
*/
Employee(float flSal) {
flBasic = flSal;
}
/**
* salary calculation
*/
public void calcSalary() {
System.out.println("\tBasic Salary of Employee : " + flBasic);
System.out.println("\tHRA = " + HRA + "%");
System.out.println("\tTotal Salary : "
+ ((flBasic * (HRA / 100)) + flBasic));
}
}
/**
* PL salary calculation
*
* @author Ritesh
*
*/
class PL extends SalaryCalc {
/**
* constructor for salary of PL
*
* @param flSal
* salary input
*/
PL(int flSal) {
flBasic = flSal;
}
/**
* calculates Pl salary and return it
*/
public void calcSalary() {
System.out.println("\tBasic Salary of PL = " + flBasic);
System.out.println("\tHRA = " + HRA + "%");
System.out.println("\tTotal Salary : "
+ ((flBasic * (HRA / 100)) + flBasic));
}
}
/**
* salary calculation with HRA
*
* @author Ritesh
*
*/
public class Exercise4 {
/**
* execution begin from here
*
* @param args
* commanline arguments
*/
public static void main(String[] args) {
System.out.println("Employee Salary Calculation : ");
new Employee(10000).calcSalary();
System.out.println("\nPL Salary Calculation : ");
new PL(30000).calcSalary();
}
}
No comments:
Post a Comment