I'm beating my head against a wall on this, I'm sure it's something simple that I just don't understand yet because I am new to java.
Any help would be appreciated.
I think there is an issue with the Double annualSales and the ArrayList, but I'm not sure.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package commission;
import java.util.ArrayList;
import java.util.Scanner;
/**
* * @author
*
* This program will calculate a sales persons annual sales commission plus fixed
* salary based on a 5% commission staring at 80% of the 500,000 sales target.
* Additionally the program will show the sales person what their commission
* would have been had the achieved greater sales.
*/
public class Commission
{
public static final int salesTarget = 500000; // Setting of Sales Target
public static final float accelerationFactor = 0.075f; // rate accelerator
public static final float minimumSales = 0.80f; // Commision starts at 80%
public static void main(String[] args)
{
ArrayList <String> name = new ArrayList<String>();
ArrayList <Double> annualSales = new ArrayList<Double>();
Scanner input = new Scanner(System.in); // enables keyboard input
System.out.println("Please enter Sales Person name") ;
name.add(input.nextLine());
// prompts user for name of sales person
System.out.print("Please enter annual sales: ") ;//Prompts user for sales
annualSales.add(input.nextDouble());
SalesPerson salesPerson = new SalesPerson // enables salesPerson class
(50000, .05, salesTarget, minimumSales); // set initial values
System.out.println("Total Compensation: " //displays salary + commission
+ (salesPerson.totalCompensation(annualSales, minimumSales)));
System.out.println(); // print blank line
System.out.println("SalePerson\tTotal Sales\tTotal Compensation");//Print column names
System.out.println(); // print blank line
System.out.println((name) + "\t\t" + (annualSales) + "\t" + //print sales and compensation
(salesPerson.totalCompensation(annualSales, minimumSales )));
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/** *
* @author
*/
class SalesPerson
{
//Variables set so they are only visable in the salesPerson class
private double fixedSalary = 50000;
private double commissionRate = .05;
private double salesTarget = .80f;
private float accelerationFactor = .075f;
public SalesPerson // set the salesPerson instance with associated variables
(double fixedSalary, double commissionRate,
double salesTarget, float accelerationFactor)
{
this.fixedSalary = fixedSalary;
this.commissionRate = commissionRate;
this.salesTarget = salesTarget;
this.accelerationFactor = accelerationFactor;
}
public double totalCompensation(double annualSales, double minimumSales)
{
// The following code determines the minimum sales in dollars and
// susequently determines which level of commission incentive will
// be awarded before finally calculating the total annual compensation.
double minSalesCalc = salesTarget * minimumSales;
// The following code compares the two variables and sets the variable
// diff equal to 0 as a starting point for the calculations.
int diff = Double.compare(annualSales,minSalesCalc);
if(diff >= 0)
{ minSalesCalc = fixedSalary;
if(annualSales > salesTarget)
{
minSalesCalc += salesTarget * commissionRate;
minSalesCalc += (annualSales - salesTarget) * accelerationFactor;
} else
{ minSalesCalc += annualSales * commissionRate;
} return minSalesCalc;
} else
{ return fixedSalary;
}
}
}

