JAVA-Create an Inheritance Hierarchy-SalesPerson,Salary,Commision & Earnings Classes

Q. An inheritance hierarchy is given as follows: SalesPerson >Commission> Salary> Earnings 
Write a JAVA program to perform the following:
a. Create the classes and interface for each entity shown above
b. Instance variables for SalesPerson – name, totalsales and a method show() to display them 
c. Instance variable for Salary – basic [assign value 1000] and method – calcSal() [abstract] 
d. Instance variable for Commision – commpercent and method – calcCom() to calculate the commission rate depending upon totalsales as given below: 
   i. $0 - $200: 0% of totalsales 
   ii. $201 - $500: 10% of totalsales 
   iii. > $500: 20% of totalsales 
e. Instance variable for Earnings – gross and method – 
   i. calcSal() [abstract method of interface Commision] to calculate the gross earnings for a SalesPerson 
   ii. show() to display the gross earning that will override the show() method of SalesPerson 



class salesperson
{
String name;
double total_sale;
salesperson(String n,double t)
{
name=n;
total_sale=t;
}
void show()
{
System.out.println("Name: "+name+"\t"+"Amount_of_Sales: "+total_sale);
}
}
interface salary
{
final static int basic=1000;
public abstract void calsal();
}
class commission extends salesperson
{
commission(String n,double t)
{
super(n,t);
}
double b=total_sale;
double calcom()
{
if(b>0 && b<201)
{
b=b*0;
}
else if(b>200 && b<501)
{
b=0.1*b;
}
else
{
b=0.2*b;
}
return b;
}
}
class earnings extends commission implements salary
{
earnings(String n,double t)
{
super(n,t);
}
double gross;
public void calsal()
{
double c=calcom();
gross=basic+c;
}
void show()
{
super.show();
System.out.println("The Overall Salary is: "+gross);
}
}
class salesperson_test
{
public static void main(String args[])
{
earnings e=new earnings("Sukhendu",400.0);
e.calsal();
e.show();
}
}

//if you have any problem, comment below

Comments