New Want to Write for Computaholics ? if Yes Contact us at "contact@computaholics.in"

Java Program that show the partial implementation of Interface(calculation of Salary of Employee)

Write a Java Program that show the partial implementation of Interface(calculation of Salary of Employee):-

import java.util.*;
interface salary
{
int getsal();
}
abstract class employee
{ String name;
int age;
String sex;
int sal;
employee(String name,int age,String sex,int sal)
{
this.name=name;
this.age=age;
this.sex=sex;
this.sal=sal;
}
abstract void display();
}
class labour extends employee implements salary
{ int wage;
int hrs;
labour(String name,int age,String sex,int sal,int hrs)
{
super(name,age,sex, sal);
this.hrs=hrs;
}
public int getsal()
{
wage=sal*hrs;
return wage;
}
void display()
{
System.out.println("name :"+name);
System.out.println("Age :"+age);
System.out.println("Sex :"+sex);
System.out.println("salary : Rs"+sal);
System.out.println("Hours worked :"+hrs);
System.out.println("Wage of the daily labour :Rs"+getsal());
}
}
class staff extends employee implements salary
{ int hra,da,ta;
staff(String name,int age,String sex,int sal,
int hra,int da,int ta)
{
super(name,age,sex, sal);
this.da=da;
this.ta=ta;
this.hra=hra;
}
public int getsal()
{
int wage=sal+ta+da+hra;
return wage;
}
void display()
{
System.out.println("name :"+name);
System.out.println("Age :"+age);
System.out.println("Sex :"+sex);
System.out.println(" basic salary :Rs"+sal);
System.out.println("Daily allowance : Rs"+da);
System.out.println("Travel allowance : Rs"+ta);
System.out.println("Household allowance : Rs"+hra);
System.out.println("total salary :Rs"+getsal());
}
}
class sal
{
public static void main(String args[])
{ Scanner sc= new Scanner (System.in);
int ch,da,ta,hra,sal,hrs,age;
String name;
String sex;
System.out.println("Enter ur choice for salary calculation");
System.out.println("1-labour");
System.out.println("2-Staff");
ch=sc.nextInt();
switch(ch)
{
case 1 :
System.out.println("Enter the following for a lobour");
System.out.print("Name :");
name=sc.next();
System.out.println("age :");
age=sc.nextInt();
System.out.println("Sex : ");
sex=sc.next();
System.out.println("salary :");
sal=sc.nextInt();
System.out.println("daily working hours :");
hrs=sc.nextInt();
labour l = new labour(name,age,sex,sal,hrs);
l.display();
break;
case 2 :
System.out.println("Enter the following for a Staff");
System.out.println("Name :");
name=sc.next();
System.out.println("age :");
age=sc.nextInt();
System.out.println("Sex : ");
sex=sc.next();
System.out.println("salary : ");
sal=sc.nextInt();
System.out.println("daily allowance :");
da=sc.nextInt();
System.out.println("travel allowance :");
ta=sc.nextInt();
System.out.println("household allowance :");
hra=sc.nextInt();
staff s = new staff(name,age,sex,sal,hra,da,ta);
s.display();
break;
}
}
Copyright © C Program | Java | OpenGL Programming | Hadoop at Computaholics