icse-promo

Question

A super class Worker has been defined to store the details of a worker .Define a sub clss Wages to compute the monthly wages for the worker. The details / specifications of both the classes are
given below:
Classname:Worker
Data Members / instance variables:
Name:to store the name of the worker
Basic:to store the basic pay in decimals
Memberfunctions:

Worker(…): Parameterised constructor to assign values to the instance variables

void display():
Classname: Wages
Data Members / instance variables:
hrs:stores the hours worked
rate:stores rate per hour
wage:stores the overall wage of the worker

Member functions:
Wages(…):Parameterised constructor to assign values to the instance variables of both the classes
double overtime():Calculates and returns the overtime amount as (hours*rate)
void display():Calculates the wage using the formula
wage = overtime amount+Basic pay
and displays it along with the other details
Specify the class Worker giving, details of the constructor() and void display().Using the concept of inheritance, specify the class Wages giving details of constructor( ), double overtime() and void display().The main() function need not be written.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					
public class Worker
{
    String Name;
    double Basic;

    public Worker(String n,double b)
    {
        Name=n; 
        Basic=b;
    }
    public void display()
    {
        System.out.println("Name of worker :"+Name);
        System.out.println("Basic Pay of worker :"+Basic);
    }
}

public class Wages extends Worker	
{
    int hrs;
    double rate,wage;

    public Wages(String a,double b,int c,double d)
    {
        super(a,b);
        hrs=c;
        rate=d;
        wage=0.0;
    }
    public double overtime()
    {
        return(rate*hrs);
    }
    public void display()
    {
        double x=overtime();
        wage=x+super.Basic;
        super.display();
        System.out.println("Wage="+wage);
    }
}
 

 

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *