Math, asked by cherry5065, 15 hours ago

3) write a class worker and derive classes dailyworker and salariedworker from it. Every worker has a name and a salary rate. Write method compay (int hours) to compute the week pay of every worker. A daily worker is paid on the basis of the number of days he/she works. The salaried worker gets paid the wage for 40 hours a week no matter what the actual hours are. Test this program to calculate the pay of workers. You are expected to use the concept of polymorphism to write this program.

Answers

Answered by 44PurpleOcean
2

Answer:

\red{answer}

Step-by-step explanation:

class worker

{

String name;

int empno;

worker(int no,String n)

{ empno=no; name=n; }

void show()

{

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

System.out.println("Employee number : "+empno);

System.out.println("Employee name : "+name);

}

}

class dailyworker extends worker

{

int rate;

dailyworker(int no,String n,int r)

{

super(no,n);

rate=r;

}

void compay(int h)

{

show();

System.out.println("Salary : "+rate*h);

}

}

class salariedworker extends worker

{

int rate;

salariedworker(int no,String n,int r)

{

super(no,n);

rate=r;

}

int hour=40;

void compay()

{

show();

System.out.println("Salary : "+rate*hour);

}

}

//--------- main -----------

class s04_03

{

public static void main(String args[])

{

dailyworker d=new dailyworker(254,"Arjun",75);

salariedworker s=new salariedworker(666,"Unni",100);

d.compay(45);

s.compay();

}

}

Similar questions