# Sales Commission Calculator in Java

(Sales Commission Calculator) A large company pays its salespeople on a commission basis. The salespeople receive \$200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells \$5,000 worth of merchandise in a week receives \$200 plus 9% of \$5000, or a total of \$650. You’ve been supplied with a list of the items sold by each salesperson. The values of these items are as follows:

### Code Sales Commission Calculator in Java

SalesCommissionCalculator.java

``````/*
*       Filename:  SalesCommissionCalculator.java
*
*    Description:  Exercise 4.19 - Sales Commission Calculator
*
*  @Author:  Bilal Tahir Khan Meo
*  Website: https://www.codeblah.com
*
* =====================================================================================
*/

public class SalesCommissionCalculator{
private static final double BASE_PAY = 200.0;
private static final double COMMISSION_PERCENT = 0.09;

private double total;

public void enterItem(int x){
switch(x){
case 1:
total += 239.99;
break;
case 2:
total += 129.75;
break;
case 3:
total += 99.95;
break;
case 4:
total += 350.89;
break;
default:
break;
}
}
public double getSalesTotal(){
}
public double calculateCommission(){
return BASE_PAY + total * COMMISSION_PERCENT;
}
}``````

SalesCommissionCalculatorTest.java

``````/*
*       Filename:  SalesCommissionCalculatorTest.java
*
*    Description:  4.19 - Calculate gross weekly sales commission of \$200 + 9%
*                  of total sales.
*
*  @Author:  Bilal Tahir Khan Meo
*  Website: https://www.codeblah.com
*
* =====================================================================================
*/
import java.util.Scanner;

public class SalesCommissionCalculatorTest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
SalesCommissionCalculator salesCal = new SalesCommissionCalculator();

int item = 0;

while(item != 9){
System.out.print("Enter the number(1-4) of the item sold (9 to exit): ");
item = sc.nextInt();

salesCal.enterItem(item);
}

if(salesCal.getSalesTotal() > 0){
System.out.print("\nWEEKLY COMMISSION\n");
System.out.printf("Weekly sales total: %.2f\n", salesCal.getSalesTotal());
System.out.printf("Weekly earnings: %.2f\n", salesCal.calculateCommission());

}
}
}``````