Hi,
I have an assignment that I need help finding out how to add the commission rate for salespeople. I'm to use arrays and methods.
The commission rates are as follows:
$1000 -- 2999 --> 2%
$3000 -- 4999 --> 3.5%
$5000 -- 9999 --> 4.25%
$10000 and above --> 6%
What would be the best way to add the commission rates for these values? (I'm reading from a file for the sales amounts and names of the people).
I've tried if-statements but you can't use a boolean operator for what I wanted to do. Any help is appreciated. I'll keep working on it to see if I can find another way.
This is what I have so far:
public static void main(String[] args) throws Exception {
File file = new File("~hu/180/homework/hw10data");
Scanner input = new Scanner(file);
/** declare variables and arrays */
String[] names = new String[100];
double[] sales = new double[100];
double[] totalAmountEarned = new double[100];
double commissionRate = 0;
double averageSales = 0;
double bonus = 50;
/** Call methods */
getData(file, names, sales);
getCommissionRate(sales, commissionRate);
totalAmountEarned = getTotalSales(sales, commissionRate, totalAmountEarned);
averageSales = getAverageSales(sales, averageSales);
}
// method to read the data from the file and return it
public static int getData(File file, String[] names, double[] sales) throws Exception {
file = new File("~hu/180/homework/hw10data");
Scanner input = new Scanner(file);
int k = 0;
while (input.hasNext()) {
names[k] = input.next();
sales[k] = input.nextDouble();
++k;
}
return k;
}
// method to set the commission rates for the sales amounts
public static double getCommissionRate(double[] sales, double commissionRate) {
commissionRate = 0.02;
commissionRate = 0.035;
commissionRate = 0.0425;
commissionRate = 0.06;
return commissionRate;
}
// method to calculate the total amount earned
public static double[] getTotalSales(double[] sales, double commissionRate, double[] totalAmountEarned) {
int k = 0;
for (k = 0; k < sales.length; ++k) {
totalAmountEarned[k] = (sales[k] * commissionRate) + sales[k];
++k;
}
return totalAmountEarned;
}
// method to calculate the average sales amount
public static double getAverageSales(double[] sales, double averageSales) {
double sum = 0;
int k = 0;
for (k = 0; k < sales.length; ++k) {
sum += sales[k];
++k;
}
averageSales = sum / k;
return averageSales;
}
}
Regards,
Soul