Results 1 to 14 of 14

Thread: math help

  1. #1
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default math help

    I'm writing a java program for a school assignment. I have everything completed except getting the program to calculate the sales commission for each $5000 increment, it takes the first one and just copies it to the following increments.

    What did I do wrong?
    Java Code:
    import java.util.Scanner;
    
    public class Compensation {
        /* The total compensation of the Salesman is calculated by this equation:
        *  Annual Compensation = 60000 + (.025 * Sales)
        */
        private static double salary = 60000;      //Salary is the annual salary of $60k
        private static double commission = 0.025;  //commission is .025 of sales
        private static double target = 1200000;    //Target sales amount to trigger accel factor
        private static double goal = 960000;       //Goal to start the commission bonus
    
        public static void main(String[] args) {
    
            //Scanner to capture keyboard input
            Scanner keyboard = new Scanner(System.in);
    
            //Display the Salary
            System.out.println("The Salesman's annual compensation is found by this formula:");
            System.out.println("Compensation = Salary + (Commission * Sales.)");
            System.out.println("The saleman's annual salary is $60,000.");
    
            //Display the Commission
            System.out.println("The Salesman's commission is 25% of his sales.");
            System.out.println("To find the annual compensation, we need the number of sales for the year.");
            
            //Get the sales ammount
            System.out.println("What is the annual sales amount for this salesman? ");
            double sales = keyboard.nextDouble();
    
            if (sales >= goal)  {
                 commission = commission + 1.25;
            }
    
            double compensation = salary + (commission * sales);
    
            if (sales < goal) {
            System.out.println("I'm sorry, the salesman did not meet the target sales and does not receive commission.");
            System.out.println("The salesman's annual compensation this year will just be the salary of $" +Double.toString(salary));
            } 
            else {
            for (double amount = sales; amount <= sales + 50000; amount+= 5000){
            System.out.println(amount + "  Compensation is $" + (compensation));
            }     
           }
        }
    }
    WHen i run this program it displays the "I'm sorry..." text if the number entered for sales is less than the goal (960,000).
    If the number entered is more than 960000 it displays the increments correctly but doesn't calculate the sales commission for each increment.
    Java Code:
    What is the annual sales amount for this salesman? 
    1000000
    1000000.0  Compensation is $1335000.0
    1005000.0  Compensation is $1335000.0
    1010000.0  Compensation is $1335000.0
    1015000.0  Compensation is $1335000.0
    1020000.0  Compensation is $1335000.0

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    340
    Rep Power
    5

    Default Re: math help

    If we use 1,000,000 as an example Sales amount, what would you expect to have printed out?
    Are you saying that for every $50,000 in sales, the comission amount should increase by 1.25%?

  3. #3
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    Yes, there's an acceleration factor of 1.25 after the salesman makes or exceeds 1.2 million in sales. The factor intervals are up to us, I used 5000, but it makes more sense if we use 100,000 for the intervals.

    So as shown in the second code box i posted for each interval the compensation should be salary + (commission * sales), or 60000 + (.025 * sales) where sales is the number entered.
    so if I or someone enters 1.5 mill as the sales, it should give the 1.5 mill number as shown and then Compensation is $153,750.00 or $60,000 + (.0625 * 1500000) at 1500000 the acceleration factor increases the commission from 2.5% to 6.25% (.0625) using the 100k increments

    Java Code:
    1000000.0  Compensation is $85000.00
    1100000.0  Compensation is $87500.00
    etc.
    Does that make sense?
    Last edited by kormath; 02-01-2013 at 10:05 PM.

  4. #4
    Ulrich is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: math help

    You should consider your "for"-loop. There you display increasing sales but always the same compensation.

  5. #5
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    I thought line 30 and 31 would take care of that.

  6. #6
    Ulrich is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: math help

    Line 30/31 are executed just once - you calculate just one value, In the loop you display it over and over again without alteration.

    Quote Originally Posted by kormath View Post
    I thought line 30 and 31 would take care of that.

  7. #7
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    so i need to add the equation in the loop? And sorry i meant line 34.

    Java Code:
    else {
            for (double amount = sales; amount <= sales + 50000; amount+= 5000){
            double compensation = salary + (commission * sales);
            System.out.println(amount + "  Compensation is $" + (compensation));

  8. #8
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    I was able to add the formula for the compensation to the loop without throwing out errors, but it still won't calculate for each increment of the loop. Any other ideas i can try?

    Java Code:
    if (sales < goal) {
            System.out.println("I'm sorry, the salesman did not meet the target sales and does not receive commission this year.");
            System.out.println("The salesman's annual compensation will only be his fixed salary of $" +Double.toString(salary));
            } 
            else {
            for (double amount = sales; amount <= sales + 500000; amount+= 100000)
            {
                double compensation = salary + (commission * sales);
                System.out.println(amount + "  Compensation is $" + (compensation));
    Could this be done without a loop?

    My goal is to have the program display the sales input by the user and calcualte the compensation for that input, as well as 5 increments above that input.
    Java Code:
    **example**
    Total Sales             Total Compensation
    1,000,000                   85,000
    1,100,000                   87,500
    1,200,000                   90,000
    1,300,000                   108,750
    1,400,000                   130,000
    1,500,000                   153,750

  9. #9
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    Okay so i fixed my error in the code not calculating in the loop. I forgot to replace the sales keyword with the amount keyword I created in the loop. Now that part is working perfectly.

    However, i need to have this printed in a table format. I've made the "table" but when i add the amount and compensation keywords to print in the columns, i get this error.

    Error text -
    System.out.println("%-15s $15s %n", amount, compensation);
    method PrintStream.println(Object) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(String) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(char[]) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(double) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(float) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(long) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(int) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(char) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println(boolean) is not applicable
    (actual and formal argument lists differ in length)
    method PrintStream.println() is not applicable
    (actual and formal argument lists differ in length)

    Here's the "table" code
    Java Code:
            else {
            for (double amount = sales; amount <= sales + 500000; amount+= 100000)
            {
                double compensation = salary + (commission * amount);
      //          System.out.println(amount + "  Compensation is $" + (compensation));
                
                    /*
                     * Formatting for the output of the compensation and sales
                     * Code obtained from Free Java Course (2013)
                     * http://www.homeandlearn.co.uk/java/java_formatted_strings.html
                     */
                     
                     //Code for the column headings
                     String heading1 = "Sales Amount";
                     String heading2 = "Salesman's Comp";
                     String divider = "いいいいいいいいいいいい";
                     
                     //Code for pringing the headings in the correct columns
                     System.out.println("");
                     System.out.printf("%-15s %15s %n", heading1, heading2);
                     System.out.println(divider);
                     
                     //Code to print the sales and comp info under the headings
                     System.out.println("%-15s $15s %n", amount, compensation);
                     System.out.println(divider);
    Where did is screw up this time?

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  11. #11
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    ah I see. Thanks! that fixed it.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: math help

    You're welcome!

  13. #13
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: math help

    another question on this. I'm supposed to use the output from this in another class. That class is an array, and it's supposed to ask for 2 names, then print the sales entered for those 2 names, and show the difference in the sales.

    I've gotten this to work by itself printing out the keyboard input, but cannot figure out how to use the info from the Compensation class posted previously in the array class. I've read you can extend the class, but NetBeans gives me errors when i do this.

    Here's the array class:
    Java Code:
    package compensation;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    import java.util.Scanner;
    /**
     *
     * @author tolsen
     */
    public class array {
        
        public static void main(String[] args)
        {
            //Scanner object for saving keyboard input
            Scanner keyboard = new Scanner(System.in);
            
            //Number of employees
            final int peeps = 2;
            
            //Array to hold the names and sales info
            String[] name = new String[peeps];
            double[] sales = new double[peeps];
            
                for (int i = 0; i < peeps; i++) {
                    System.out.print("\n What is the name of the Salesperson? ");
                    name[i] = keyboard.next();
                    System.out.print("\n What is the annual sales for this Salesperson? ");
                    sales[i] = keyboard.nextDouble();
                }
                
                System.out.println("Name and sales of first Salesperson:");
                System.out.printf("%-15s %5s %n", name[0], sales[0]);
                System.out.println();
                System.out.println("Name and sales of second Salesperson:");
                System.out.printf("%-15s %5s %n", name[1], sales[1]);
                System.out.println();
                    
                    if (sales[0] < sales[1]){
                        System.out.println("The difference in sales is: " + (sales[1] - sales[0]));
                        System.out.println();
                        System.out.println(name[0] + " needs to make up $" + (sales[1] - sales[0]) + " in sales.");
                    }
                    
                    else if (sales[0] > sales[1]) {
                        System.out.println("The difference in sales is: " + (sales[0] - sales[1]));
                        System.out.println();
                        System.out.println(name[1] + " needs to make up $" + (sales[0] - sales[1]) + " in sales.");
                    }
            }        
    }

  14. #14
    Ulrich is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: math help

    First you should use uppercase-names for your classes to meet the common naming conventions.

    To solve your problem you need to add a getter-method to the Compensation-class which returns the compensation by the sales argument. Then you need to instantiate "Compensation" from your Array-Class and call this getter-method.

    Ulrich

Similar Threads

  1. Math help
    By stuffses in forum New To Java
    Replies: 5
    Last Post: 03-09-2012, 01:00 AM
  2. Doing Math
    By nicholas205 in forum New To Java
    Replies: 1
    Last Post: 01-28-2012, 02:18 AM
  3. math and GUI
    By urbanleg in forum AWT / Swing
    Replies: 3
    Last Post: 08-06-2011, 04:05 PM
  4. Math.cos()
    By ravi1 in forum New To Java
    Replies: 5
    Last Post: 03-27-2011, 02:52 PM
  5. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •