Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

| Question 15 8 pts The ABC Company offers its salesperson commission, based on

ID: 3910886 • Letter: #

Question

| Question 15 8 pts The ABC Company offers its salesperson commission, based on two factors: the amount in sales, and the type of products. A and B. The salesperson receives 7% commission on product A if the sales is below S40 000 00, and 10 e sales is $40.000 00 or more. A salesperson receives 5% commission on product B, if the sales is under$20,000.00 and 6.5% if the sales is S2O,000.00 or more. Write a class called Commission The constructor of the class that accepts three parameters they sell. There are two types of 13 marks) . A single character representing the type of product, and The sales amount [1 marks) A mutator method that calculates the commission amount. In writing this mothod use tho swich statement to determine the type of product ? 14 marks] YOU ARE RESPONSIBLE TO SPECIFY ANY REQUIRED VARIABLE(S DO NOT WRITE A TEST CLASS ? Paragraph . ?

Explanation / Answer

class commission{
int id; // SalesPerson id
char product_type;
double sales_amt;
double commission_amt; // a variable declared to calculate the total commission earned.
commission(int id, char product_type, double sales_amt) // Constructor initializing object with given parameters
{
this.id = id;
this.product_type = product_type;
this.sales_amt = sales_amt;
}
  
public boolean accessor(double sales_amt) // accessor method to validate sales amount
{
  
if(sales_amt >= 0)
{
return true;
}
  
else
{
return false;
}
}
  
public double mutator(char product_type , double sales_amt ) // mutator method to calculate the commission
{
boolean p = accessor(sales_amt);
if(p==true)
{
switch(product_type) // switch case used to check all conditions given
{
case 'A':
if(sales_amt >= 40000.00)
{
commission_amt = 0;
commission_amt = 0.1*sales_amt;
}
else if(sales_amt < 40000.00)
{
commission_amt = 0;
commission_amt = 0.07*sales_amt;
}
break;
case 'B':
if(sales_amt < 20000.00)
{
commission_amt = 0;
commission_amt = 0.05 * sales_amt;
}
  
else if(sales_amt >= 20000.00)
{
commission_amt = 0;
commission_amt = 0.065 * sales_amt;
}
break;
  
default:
System.out.println("Product type not specified");
commission_amt = 0;
}
  
return commission_amt;
}
else
return 0;
}
}

Code documentation

The above class is implemented for java programming language.

Mutator method returns double data type for calculated commission so in test class take consideration of its return type while calling mutator method.

below is a test class for checking above implemented class

public class test{
public static void main(String[] args)
{
commission obj1 = new commission(1,'A',20000);
//System.out.println(obj1.product_type);
//System.out.println(obj1.sales_amt);
double x = obj1.mutator(obj1.product_type, obj1.sales_amt);
  
System.out.println(x);
}
}

below is the output for above requirement asked in test class