Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 23 of 23

Thread: Simple Commission Calculator

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple Commission Calculator

    I'm struggling to get the incentive part correct. And I have no idea where to start to display the table. Here are the instructions and the code below.

    · A salesperson will continue to earn a fixed salary of $50,000.00 per year. The current sales target for every salesperson is $120,000.00 per year.
    · The sales incentive will only start when 80% of the sales target is met. The current commission is 7.5% of total sales.
    · If a salesperson exceeds the sales target, the commission will increase based on an acceleration factor. The acceleration factor is 1.25.
    · The application should ask the user to enter annual sales, and it should display the total annual compensation.
    · The application should also display a table of potential total annual compensation that the salesperson could have earned, in $5000 increments above the salesperson’s annual sales, until it reaches 50% above the salesperson’s annual sales.

    Sample Table: Assuming a total annual sales of $100,000, the table would look like this:

    Total Sales Total Compensation
    100,000 <Program Calculated Value>
    105,000 <Program Calculated Value>
    <etc>

    Here's what I have so far.

    package commissioncalculator;
     
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
     
    /**
     * @author Marci
     */
    public class CommissionCalculator {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
           String input; //Input of user
           double salary; //This is the annual sales value
           double rate; //This is the commission rate
           double commission; //This is the amount of commision made
           double pay; //Salesperson's pay
           double sales; //annual sales
           double incentive; //sales incentive
     
           DecimalFormat dollar = new DecimalFormat("#,##0.00");
           DecimalFormat percent = new DecimalFormat("##0.0%");
           input = JOptionPane.showInputDialog("Enter the annual salary.");
           salary = Double.parseDouble(input);
           input = JOptionPane.showInputDialog("Enter current commission rate.");
           rate = Double.parseDouble (input);
           input = JOptionPane.showInputDialog("Enter the current sales target.");
           sales = Double.parseDouble (input);
     
           commission = rate * salary;
           pay = commission + salary;
           JOptionPane.showMessageDialog(null, "Commission rate is " +
            percent.format(rate) + ". The amount of pay is $" + dollar.format(pay));
     
            public incentive() {
              if (sales>=(.80 * sales) && sales<=120,000)
                incentive = (.75 * sales);
              else if (sales>120,000)
                incentive = (1.25 * .75 * sales);
        }
        }
     
           System.exit(0);
    }


  2. #2
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    I've altered it a little bit. I think I'm getting closer.
    package commissioncalculator;
     
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
     
    /**
     * @author Marci
     */
    public class CommissionCalculator {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
           String input; //Input of user
           double salary; //This is the annual sales value
           double rate; //This is the commission rate
           double commission; //This is the amount of commision made
           double pay; //Salesperson's pay
     
           DecimalFormat dollar = new DecimalFormat("#,##0.00");
           DecimalFormat percent = new DecimalFormat("##0.0%");
           input = JOptionPane.showInputDialog("Enter the annual salary.");
           salary = Double.parseDouble(input);
           input = JOptionPane.showInputDialog("Enter current commission rate.");
           rate = Double.parseDouble (input);
     
     
           commission = rate * salary;
           pay = commission + salary;
           JOptionPane.showMessageDialog(null, "Commission rate is " +
            percent.format(rate) + ". The amount of pay is $" + dollar.format(pay));
        }
        public static void incentive(String[] args) {
           String input; //input of user
           double sales; //annual sales
           double incentive; //sales incentive
     
           DecimalFormat dollar = new DecimalFormat("#,##0.00");
           DecimalFormat percent = new DecimalFormat("##0.0%");
           input = JOptionPane.showInputDialog("Enter the current sales target.");
           sales = Double.parseDouble (input);
     
              if (sales>=(.80 * sales) && sales<=120,000)
                incentive = (.75 * sales);
              else if (sales >120,000)
                incentive = (1.25 * .75 * sales);
        }  
    }
     System.exit(0);

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    Can you show what the code does now, explain what is wrong and show what the output should be?

    For a first attempt at displaying the table, just use the println() method. Later you can look into using printf() which will give you some formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    This part of it has the error so far:

    if (sales>=(.80 * sales) && sales<=120,000) Error: ')'expected
    incentive = (.75 * sales);
    else if (sales >120,000) Error: ''Else' without 'If' Error: cannot find symbol symbol: class sales location: class CommissionCalculator <identifier> expected
    incentive = (1.25 * .75 * sales); Error: <identifier> expected

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    Is the , the character for decimal points? In the US we use the .
    That one error can cause the others.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    I see where I made that mistake. I can't get the table to come through correctly.

    package commissioncalculator;
     
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
     
    /**
     * @author Marci
     */
    public class CommissionCalculator {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
           String input; //Input of user
           double salary; //This is the annual sales value
           double rate; //This is the commission rate
           double commission; //This is the amount of commision made
           double pay; //Salesperson's pay
           double sales; //annual sales
           double incentive = 0; //sales incentive
     
           DecimalFormat dollar = new DecimalFormat("#,##0.00");
           DecimalFormat percent = new DecimalFormat("##0.0%");
           input = JOptionPane.showInputDialog("Enter the annual salary.");
           salary = Double.parseDouble(input);
           input = JOptionPane.showInputDialog("Enter current commission rate.");
           rate = Double.parseDouble (input);
           input = JOptionPane.showInputDialog("Enter the current sales target.");
           sales = Double.parseDouble (input);
     
           commission = rate * salary;
           pay = commission + salary;
           JOptionPane.showMessageDialog(null, "Commission rate is " +
            percent.format(rate) + ". The amount of pay is $" + dollar.format(pay));
     
              if (sales>=(.80 * sales) && sales<=120000)
                incentive = (.75 * sales);
              else if (sales >120000)
                incentive = (1.25 * .75 * sales);
     
              JOptionPane.showMessageDialog (null,
                "Total Sales"    +    "Total Compensation"     +
                 dollar.format(sales)  + (dollar.format(sales) + dollar.format(incentive) )  );
     
              System.exit(0);
        }   
     
    }

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    I can't get the table to come through correctly.
    Please post the current output and show what is wrong with it and show how you want it to be.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    The first message comes through, but the second is "Total SalesTotal Compensation 100,000.00100,000.0075,000.00"

    I want it to look like this:

    Total Sales Total Compensation
    100,000 75,000
    105,000 78,750

    The table needs to increase by 5,000 until it reaches 50% above the salary. And the compensation takes into consideration the incentive.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    Add a newline character: ("\n") where you want a line to end and the following part of the String to be on the next line.
    Add some spaces between the numbers: num1 + " " + num2
    so you can see where one ends and the next starts.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    Something like this:

              JOptionPane.showMessageDialog (null,
              ("n")  "Total Sales"    +    "Total Compensation" + ("/n")
              ("n") ( dollar.format(sales)  + (dollar.format(sales) + dollar.format(incentive) )  ) + ("/n")
              ("n") ( (dollar.format(sales) + 5000) + (dollar.format(sales) + dollar.format(incentive) )))("/n");

    It still says ")" expected.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    It still says ")" expected.
    Make sure all the ( have a matching ).

    It looks like you might need some + operators to connect all the parts of the String into one String.

    You don't need the ()s around the "\n"
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    Ok, I think I got that solved, but now it doesn't like the "null"

      JOptionPane.showMessageDialog (null,
              "n" + "Total Sales"    +    "Total Compensation" + "/n" +
              "n" + ( dollar.format(sales)  + (dollar.format(sales) + dollar.format(incentive) )  ) + "/n" +
              "n" + ( (dollar.format(sales) + 5000) + (dollar.format(sales) + dollar.format(incentive) ))) + "/n";

    What other choices do I have?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    now it doesn't like the "null"
    Please post the full text of the error message.

    What other choices do I have?
    Look at the API doc for all the choices.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    'void' type not allowed here
    not a statement

    When I run it, I get: run:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - not a statement
    at commissioncalculator.CommissionCalculator.main(Com missionCalculator.java:43)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 14 seconds)

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    Where is the "void"? The error message did not give a line number.

    What error messages does the compiler give? Can you compile the code without trying to execute it? You won't be able to execute the code with compiler errors.

    Compile the code and copy the compiler's error messages here.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    Here's the screenshot of where the error is. Doc2.pdf
    Attached Files Attached Files

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    If you use the compiler, it will generate error messages that can be copied and pasted.
    Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

    If you can't post the text of the error messages attach images, not a pdf.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    Untitled.jpg
    The compiler option is grayed out. Here is the screenshot in picture format.

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    I don't recognize that message. Is it from the IDE, not from the javac compiler program?

    I don't know why beginners are encouraged to use an IDE before they understand how to write simple programs and how to understand the compiler's error messages.

    If you want help, Copy the source file to another folder and use the javac command to compile the program. It will produce error messages that can be copied to the forum.
    Last edited by Norm; August 27th, 2012 at 05:35 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    I'm not sure.
    Unfortunately, it's a self paced class, so they make us jump right into the IDE.

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    Try to get the compiler's error messages and post them here.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Commission Calculator

    Is this what you're looking for?
    Compiling 4 source files to C:\Users\Marci\Desktop\School\PRG 420\CommissionCalculator\CommissionCalculator\buil d\classes
    C:\Users\Marci\Desktop\School\PRG 420\CommissionCalculator\CommissionCalculator\src\ commissioncalculator\CommissionCalculator.java:46: not a statement
    "n" + ( (dollar.format(sales) + 5000) + (dollar.format(sales) + dollar.format(incentive) ))) + "/n";
    1 error
    C:\Users\Marci\Desktop\School\PRG 420\CommissionCalculator\CommissionCalculator\nbpr oject\build-impl.xml:915: The following error occurred while executing this line:
    C:\Users\Marci\Desktop\School\PRG 420\CommissionCalculator\CommissionCalculator\nbpr oject\build-impl.xml:268: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 2 seconds)

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Commission Calculator

    CommissionCalculator.java:46: not a statement
    This part of the message says that there is something on line 46 that is not part of a statement.
    Is that where there was a missing + in the middle of a String?

    There was a long complicated String built there. Start over writing the code to build the String.
    Start with a short String that fits on one line. Compile it and correct any errors.
    Then add a little more to it, compile it and correct errors.
    Then add a little more, compile it and correct errors.

    Continue until you have the full String that you want.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Simple calculator issue
    By ikocijan in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 20th, 2012, 02:43 AM
  2. [SOLVED] Calculating Commission with a GUI???
    By jbarcus81 in forum AWT / Java Swing
    Replies: 13
    Last Post: February 25th, 2012, 07:35 AM
  3. Need help building a simple calculator
    By zigma in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 14th, 2011, 01:13 AM
  4. Simple Calculator
    By JKDSurfer in forum Loops & Control Statements
    Replies: 3
    Last Post: June 28th, 2011, 01:37 PM
  5. Calculator
    By Andrew Wilson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 08:08 AM