Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday 20 May 2015

java inheritance example to show SalriedWorker, DailyWorker salary details


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