I am trying to pass variables to a function, have it loop through a for loop and pass the new variable to an existing function. For example my original class looks like this
class Calculations {
//declare the variables in the class
double TotalPay;
double Sales;
double Salary;
double Commission;
double SalesTarget;
double AccelFactor;
double SalesIncentive;
double Increment;
double NewAccelFactor;
double TableSales = Sales * .5;
public Calculations(double Sales, double Salary, double Commission, double SalesTarget, double AccelFactor, double SalesIncentive, double Increment) { //calculations function - can be used when processing multiple inputs as well
this.Salary = Salary;
this.Sales = Sales;
this.Commission = Commission;
this.AccelFactor = AccelFactor;
this.SalesTarget = SalesTarget;
this.SalesIncentive = SalesIncentive;
this.Increment = Increment;
}
public void calculatePay() { //calculate the total pay using the above variables that have been set
if (Sales < SalesIncentive) {
TotalPay = Salary + (Sales * Commission);
}
if (Sales == SalesIncentive || (Sales > SalesIncentive && Sales < SalesTarget * 2)) {
TotalPay = Salary + ((Sales * Commission) * AccelFactor);
}
if (Sales > SalesTarget * 2) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 2));
}
if (Sales > SalesTarget * 3) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 3));
}
if (Sales > SalesTarget * 4) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 4));
}
if (Sales > SalesTarget * 5) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 5));
}
if (Sales > SalesTarget * 6) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 6));
}
if (Sales > SalesTarget * 7) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 7));
}
if (Sales > SalesTarget * 8) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 8));
}
if (Sales > SalesTarget * 9) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 9));
}
if (Sales > SalesTarget * 10) {
TotalPay = Salary + ((Sales * Commission) * (AccelFactor * 10));
}
}
public double getTotalPay() {
return TotalPay; //return total pay to use in the output
}
}
My new function looks like this
class TableOutput { //trying to output the table, but it's not working so well
//declare the variables in the class
double TotalPay;
double Sales;
double Salary;
double Commission;
double SalesTarget;
double AccelFactor;
double SalesIncentive;
double Increment;
double NewAccelFactor;
double TableSales;
double newSales;
double totalSales;
//int j = 0;
public TableOutput(double Sales, double Salary, double Commission, double SalesTarget, double AccelFactor, double SalesIncentive, double Increment) {
//assign instances of the variables
this.Salary = Salary;
this.Sales = Sales;
this.Commission = Commission;
this.AccelFactor = AccelFactor;
this.SalesIncentive = SalesIncentive;
this.Increment = Increment;
this.SalesTarget = SalesTarget;
this.TableSales = Sales * 0.5;
this.totalSales = TableSales + Sales;
this.newSales = newSales;
}
public void createTable() {
Calculations calc2; //create a new calculations instance
if (Sales < totalSales) { //while the sales are less than the TableSales then do this
for (double i = Sales; i < totalSales; i += 20000) { //for the Sales that are less than the TableSales, up the Sales by 20k and keep going until it reaches the limit of Sales *.5
newSales = i;
System.out.println("Total Sales Total Compensation\n");
calc2 = new Calculations(newSales, Salary, Commission, SalesTarget, AccelFactor, SalesIncentive, Increment);
calc2.calculatePay();
for (double j=Sales; j < totalSales; j += 20000) { //keep adding 20k to Sales and send it back to get a running total
System.out.println(newSales + " " + calc2.getTotalPay());
}
}
}
}
What I am trying to do is add 20k to the sales and have it increment by 20k while passing that new sales amount back to the calculatePay function. What am I missing here? Shouldn't this be doing exactly that?
for (double i = newSales; i < TableSales; i =+20000) {
Calculations calc2;
calc2 = new Calculations(newSales, Salary, Commission, SalesTarget, AccelFactor, SalesIncentive, Increment);
calc2.calculatePay();
In my main function I am calling on this class for the output in such a manner:
TableOutput Table1 = new TableOutput(Sales, Salary, Commission, SalesTarget, AccelFactor, SalesIncentive, Increment);
Table1.createTable();
but still no output.
newSales?SalestonewSalesand effectively initialising both to 0. Can you print the value ofSalesandnewSalesbefore the loop and see what values they hold?iand make sure it's incremented, don't you actually want to do anything with it?