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

I need help with the following. Using the code below, the application needs to c

ID: 3661756 • Letter: I

Question

I need help with the following. Using the code below, the application needs to compare the total annual compensation of at least two salespersons. It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners. The application should ask for the name of each salesperson being compared. The Java application should also meet these technical requirements: The application should have at least one class, in addition to the application's controlling class. The source code must demonstrate the use of Array or ArrayList. There should be proper documentation in the source code.

Here is the current calculator:

/*
*
*/
package commissioncalculator;

/**
*
*
*/
public class CommissionCalculator {

  
public static final double COMM_RATE = 0.07; // Rate for Commission

public static final double FIXED_SALARY = 12000;

public static final double SALES_TARGET = 120000;

public static final double ACL_FACT = 1.25; // The acceleration factor

public static final double MIN_RATE = 0.8; // The 80% Incentive Rate

private final double annualSales;
private double commission;
private double totalCompensation;

public CommissionCalculator(double sales) {
annualSales = sales;
commission = 0;
totalCompensation = 0;
}

public void calcCommission() {
// If/Then statement to calculate commission rates.
if (annualSales <= MIN_RATE * SALES_TARGET) {
commission = 0;// No Commission earned :(
} else if (annualSales > SALES_TARGET) {
commission = annualSales * (COMM_RATE) * ACL_FACT;//Commission Rate plus accelerator.
} else {
commission = COMM_RATE * annualSales;// Normal Commission rate.
}

totalCompensation = commission + FIXED_SALARY;
}

public double getTotalCompensation() {
return totalCompensation;
}
}





Explanation / Answer

Please consider this solution. Here i am using an arraylist in SalesPerson class


import java.util.ArrayList; //Needed for ArrayList
import java.util.Scanner; //Needed for Scanner class
import java.text.DecimalFormat; //Needed for Decimal formatting

public class SalespersonComparison
{
   public static void main(String[] args)
   {       
       final double Fix_Sal = 50000; //Declares and initiates fixed salary
       double sales; // hold annual sales

       //Create new ArrayList
       ArrayList<Salesperson> cArray = new ArrayList<>();

        // Create a Scanner object to read input.
       Scanner keyboard = new Scanner(System.in);

       //Lets user know how to end loop
       System.out.println("Press 'Enter' to continue or type 'done'"
               + " when finished.");

       //blank line
       System.out.println();

       //Loop for setting name and annual sales of salesperson
       do
       {
           //Create an Salesperson object
           Salesperson sPerson = new Salesperson();

           //Set salesperson's name
           System.out.println("Enter salesperson name");
           String name = keyboard.nextLine();
           sPerson.setName(name);

           //End while loop
           if (name.equalsIgnoreCase("Done"))
               break;                   

           //Set annual sales for salesperson
           System.out.println("Enter annual sales for salesperson");
           sales = keyboard.nextDouble();
           sPerson.setSales(sales);        

           //To add Salesperson object to ArrayList
           cArray.add(sPerson);

           //Consume line
           keyboard.nextLine();   
       }
       while (true);

       //Display ArrayList

       DecimalFormat arrayL = new DecimalFormat("#,##0.00");
       for (int index = 0; index < cArray.size(); index++)
       {
           Salesperson sPerson = (Salesperson)cArray.get(index);
           System.out.println();
           System.out.print("Salesperson " + (index + 1) +
                            " Name: " + sPerson.getName() +
                            " Sales: " + (arrayL.format(sPerson.getSales())) +
                            " Commission Earned: " +
                            (arrayL.format(sPerson.getComm())) +
                            " Total Annual Compensation: "
                            + (arrayL.format(sPerson.getTotalCompensation())) + " ");

       }
   }
  
public class Salesperson
{
   public static final double COMM_RATE = 0.07; // Rate for Commission

    public static final double FIXED_SALARY = 12000;

    public static final double SALES_TARGET = 120000;

    public static final double ACL_FACT = 1.25; // The acceleration factor

    public static final double MIN_RATE = 0.8; // The 80% Incentive Rate

    private double annualSales;
    private double commission;
    private double totalCompensation;

    String spName;    //holds the salesperson's name

    //Default Constructor
    public Salesperson()
    {
        spName = "Unknown";
        annualSales = 0.0;
    }

    ////parameterized constructor
    public Salesperson(String name, double sales)
    {
        spName = name;
        annualSales = sales;
    }

    //The setName method will set the name of salesperson
    public void setName(String name)
    {
        this.spName=name;
    }

    //The getName method will return the name of salesperson
    public String getName()
    {
        return spName;
    }

    //The setSales method will set the annual sales
    public void setSales(double sales)
    {
       annualSales = sales;
    }

    //The getSales method returns the value stored in annualSales
    public double getSales()
    {
        return annualSales;
    }

    //The getComm method will calculate and return commission earned
    public double getComm()
    {
       if (annualSales <= MIN_RATE * SALES_TARGET) {
             commission = 0;// No Commission earned :(
         } else if (annualSales > SALES_TARGET) {
             commission = annualSales * (COMM_RATE) * ACL_FACT;//Commission Rate plus accelerator.
         } else {
             commission = COMM_RATE * annualSales;// Normal Commission rate.
         }

         return commission;
     
  
  
    }


    public double getTotalCompensation ()
    {  
    totalCompensation = commission + FIXED_SALARY;
    return totalCompensation;
    }
}
}