Hey guys, thank you for the help with previous posts. Right now I am attempting to call a method getComm and getAnnComp but am slightly confused with the variable I should place before the method call. Here is the method, I highlighted my issue with all caps
Scanner input=new Scanner(System.in); System.out.print("\nTotal Commission and Annual Sales Calculator\nThis " + "program will calculate Total Compensation based" + " upon\nthe percentage met of the $120,000 Annual Sales Target." + "\nThis program will also output a table of possible Total" + " Compensations\nin increments of $5,000 up to 1.5 times your inputted Annual Sales\n\n" + "Please enter your Total Annual Sales: "); //Check for Correct Entry Data try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = in.readLine().trim(); //Check for Null Entry if (line == null || line.length() == 0) { System.out.println("You did not enter a value"); return; } //Declare Annual Sales and Replace Commas/Dollar Signs annualSales = Double.parseDouble(line.replaceAll(",", "").replaceAll("\\$", "")); //Check for numerical value } catch (NumberFormatException exception) { System.out.println("Error: Not a valid sales amount."); return; //Check for IOException } catch (IOException exception) { System.out.println("Error: " + exception.getLocalizedMessage()); return; } //Declare Sales spsales=new Salesperson(annualSales); //Output Total Commission System.out.println("\nYour Total Commission for the year is: $" + spsales.getComm()); //HERE IS MY PROBLEM //Output Total Compensation System.out.println("Your Total Compensation for the year is: $"+ String.format("%.2f", spsales.getAnnComp())+ "+\n"); //HERE IS ALSO MY PROBLEM ...etc assume code closes correctly
the corresponding document is
package salesperson_part1; public class Salesperson { //Variable Definition //Declares and initalizes fixed salary. private final double Fix_Sal = 50000; //Declares and initalizes commission. private final double Comm = 7.5; //Declares and initalizes acceleration factor. private final double Accel_Factor = 1.25; //Declares and initializes sales target. double target = 120000; //Declares and initializes sales incentive threshold. double thresh = .80; String spName; //holds the salesperson's name double annSales; // Holds value for annual sales double commRate; //holds calculated commission rate. double commEarned; //holds calculated commission earned. double totalAnnComp; //Holds calculated total annual commission //Default Constructor //Default Constructor public Salesperson() { spName = "Unknown"; annSales = 0.0; } ////parameterized constructor public Salesperson(String name, double sales) { spName = name; annSales = sales; } Salesperson(double annualSales) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } //The setName method will set the name of salesperson public void setName(String name) { spName = name; } //The getName method will rueturn the name of salesperson public String getName() { return spName; } //The setSales method will set the annual sales public void setSales(double sales) { annSales = sales; } //The getSales method returns the value stored in annualSales public double getSales() { return annSales; } //The getComm method will calculate and return commission earned public double getComm() { //Check if sale are greater than or equal to 80% of target. if (annSales >= (target * thresh)) { if (annSales > target) //Checks if annual sales exceed target. { //Gets commission rate. commRate = (Comm * Accel_Factor)/100; commEarned = commRate * annSales; } else { commRate = Comm/100; commEarned = commRate * annSales; } } else { commRate = 0; commEarned = 0; } return commEarned; } /* * The getAnnComp method will calculate and return the total * annual compensation. */ public double getAnnComp () { totalAnnComp = Fix_Sal + commEarned; return totalAnnComp; } }