Skip to content

Instantly share code, notes, and snippets.

@mamiwinsfall93
Created January 18, 2020 17:18
Show Gist options
  • Save mamiwinsfall93/0537e7c5d62faae716188a9d40bfb510 to your computer and use it in GitHub Desktop.
Save mamiwinsfall93/0537e7c5d62faae716188a9d40bfb510 to your computer and use it in GitHub Desktop.
Salesman employee classes with salary information
** Filename: Employee.java
* Author: Ndatta Fall
* Purpose: Salesman employee classes with salary information
*
*/
public class Salesman extends Employee{
private int annualSales;// to store annual sales
private int commission = 0;
public Salesman(String name, int monthlySalary, int annualSales) {
// constructor that allows the name, monthly salary and annualSales to be initialized
super(name, monthlySalary);//using super to get employee's name and montly salary
this.annualSales = annualSales;
}
public int totalCommission() {// method to calcualte the total commision
commission = (int) (.02 * annualSales);
if(commission >= 20000) {//max commision is 20000 so if calculated commsion is greater than 20k then setting num=20k
commission = 20000;
}
return commission;
}
public int AnnualSalary() {//calculates annaual salary and returns it
commission = (int) (.02 * annualSales);
if(commission >= 20000) {
commission = 20000;
}
int totalPay = (getMonthlySalary() * 12) + commission;
return totalPay;
}
public String toString() {// returns employee's information
String employeeInfo = "employee's name: " + getName()
+ "\n" + "Monthly salary : " + getMonthlySalary()
+ "\n" + "Annual salary : " + AnnualSalary();
return employeeInfo;
}
public void setCommission(int num) {
this.commission = commission;
}
public int getCommission() {
return commission;
}
public void setAnnualSales(int annualSales) {
this.annualSales = annualSales;
}
public int getAnnualSales() {
return annualSales;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment