A class staff is declared with the following details
Class name staff
Data members :
Code_num    int to store staff code number
Sname       To store staff's name
Basic       To store basic salary
Member Functions :
Staff() -  Constructor
void input() -  To accept the values
void printdata()  -  To print values

Another class Overtime is declared as
Class Name Overtime
Data members 
ndays :  To store the number of days worked
ex_hrs : To store the number of hours worked per day
rate : Rate per hour
Member Functions 
Overtime (int n, double r, int h)  Constructor to assign n to ndays , 
r to rate anf h to ex_hrs
Double calculate() : to calculate the total salary(Number of days worked * rate per hour 
* number of hours worked per day + basic salary) and total salary.
void show_salary()   To display number of days worked rate and total salary.
Using the concept of inheritance define the above classes and all the 
functions in them the main function need not to be written.

            




import java.util.*;
class Staff
{
    int code_num;
    String name;
    double Basic;
    Staff(){
        code_num=0;
        name="";
        Basic=0.0;
    }

    void input(){
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the code number,name,basic");
        code_num=sc.nextInt();
        name=sc.nextLine();
        Basic=sc.nextDouble();
    }

    void printdata(){
        System.out.println("Code number of the Employee:"+code_num);
        System.out.println("name of the Employee:"+name);
        System.out.println("Basic Salary of the Employee:"+name);
    }
}

class Overtime extends Staff
{
    int ndays,ex_hrs;
    double rate;
    Overtime(int n,double r,int h)
    {
        super();
        ndays=n;
        rate=r;
        ex_hrs=h;

    }

    double calculate(){
        double tot_sal=0.0;
        tot_sal=ndays*rate*ex_hrs+Basic;
        return tot_sal;
    }

    void show_salary()
    {
        System.out.println("Number of days worked:"+ndays);
        System.out.println("rate per hour:"+rate);
        double sal=calculate();
        System.out.println("total salary:"+sal);

    }
}



     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com