import java.io.*;
import java.util.Scanner;
class Worker{
String name;
double salaryrate;
public void setdata(String s,double a){
name=s;
salaryrate=a;
}
public double ComPany(int hours){
return salaryrate*hours;
}
}
class DailyWorker extends Worker{
public void getsalary(int days){
int k=days*12;
System.out.println("salary of the DailyWorker is"+ComPany(k));
}
}
class SalariedWorker extends Worker{
public void getsalary(int hours)
{ int m=hours;
System.out.println("salary of the SalriedWorker is"+ComPany(m));
}
}
class WorkerMain{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
String n;
double salaryrate;
int days,hours,ch;
System.out.println("Enter 1 for Daily Worker \n 2 for Salried Employee");
ch=in.nextInt();
switch(ch){
case 1:DailyWorker d=new DailyWorker();
System.out.println("enter the Name");
n=in.nextLine();
System.out.println("\nenter the salary rate");
salaryrate=in.nextDouble();
d.setdata(n,salaryrate);
System.out.println("\nenter the no. of days of work");
days=in.nextInt();
d.getsalary(days);
break;
case 2:
SalariedWorker s=new SalariedWorker();
System.out.println("enter the Name");
n=in.nextLine();
System.out.println("\nenter the salary rate");
salaryrate=in.nextDouble();
s.setdata(n,salaryrate);
s.getsalary(40);
break;
}
}
}
No comments:
Post a Comment