Reputation: 33
I'm in my intro to Java class and working on loops this week. I think I have the loop built but my variable within my main CommissionNotifications is undefined.
I think I have to create an object and reference the variable stored in my other class...am I on the right track?
The program asks for annual sales and then calculates there commission payment based upon the bracket they fall into. The commission payment is done through a If statement on the class and then the program displays what they could earn if they increased there sales by 5,000 up to 1.5 * of there sales. IE if they earn 100000 in sales the table should display there initial commission and then what they could earn if they increased there sales to 150000(1.5*)
Here is my class:
public class Calculations {
double TotalSales;
double ComRate = 0.025;
double AnnualSal = 80000;
double compensation;
double SalesTarget;
double Acceleration = 1.5;
double chart;
double ComAccFactor;
public double getCommissionNotifications() {
return CommissionNotifications;
}
public void setCommissionNotifications(double commissionNotifications) {
CommissionNotifications = commissionNotifications;
}
public double CommissionNotifications; {
if (TotalSales > 120000){
CommissionNotifications = AnnualSal + (TotalSales * (ComRate + Acceleration));
} else if (TotalSales > SalesTarget * .8) {
CommissionNotifications = AnnualSal + (TotalSales * ComRate);
} else {;
CommissionNotifications = AnnualSal;
}
}
}
Here is my Main
import java.util.*;
import java.text.*;
public class Paycheck {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("Enter Total Commission Sales: ");
double TotalSales = input.nextDouble();
double Base = TotalSales;
double finish = TotalSales * 1.5;
System.out.println("Your Total compensation with your annual sales is: " + getCommissionNotifications);
int i = Base + 5000;
while (i <= finish) {
System.out.println(Base);
TotalSales += 5000;
}
}
}
Upvotes: 0
Views: 196
Reputation: 191738
This code looks a lot like C# with the capitalized variable names. Anyways, your
getCommissionNotifications
method should handle the logic of what to return
based on TotalSales
. It's also not clear why you need a setter method, so I've commented that out.
As for using the below class, you need an instance of the Calculations
class
Calculations calc = new Calculations();
double TotalSales = input.nextDouble();
calc.TotalSales = TotalSales;
// double Base = TotalSales; // Duplicate variable not needed
double finish = TotalSales * 1.5;
System.out.println("Your Total compensation with your annual sales is: " + calc.getCommissionNotifications());
public class Calculations {
double TotalSales;
double ComRate = 0.025;
double AnnualSal = 80000;
double compensation;
double SalesTarget;
double Acceleration = 1.5;
double chart;
double ComAccFactor;
public double getCommissionNotifications() {
if (TotalSales > 120000){
return AnnualSal + (TotalSales * (ComRate + Acceleration));
} else if (TotalSales > SalesTarget * .8) {
return AnnualSal + (TotalSales * ComRate);
} else {
return AnnualSal;
}
}
// Not sure why this is needed... You have a dynamic getter method
//public void setCommissionNotifications(double commissionNotifications) {
// CommissionNotifications = commissionNotifications;
//}
}
Upvotes: 0
Reputation: 6780
getCommisionNotifications
is a member of class Calculations
. To access it you will need to create a new Calculations
object:
Calculations c = new Calculations();
c.getCommisionNotifications();
Upvotes: 1