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 3 of 3

Thread: run problems undesired output

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default run problems undesired output

    Hello I am need of some assistance. I have an assignment I am working on that is supposed to do the following. • The company has recently changed its total annual compensation policy to improve sales.

    • A salesperson will continue to earn a fixed salary of $50,000. The current sales target for every salesperson is $80,000.

    • The sales incentive will only start when 80% of the sales target is met. The current commission is 12% of total sales.

    • If a salesperson exceeds the sales target, the commission will increase based on an acceleration factor. The acceleration factor is 1.3.

    • 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.


    Here is my code thus far.
     
     
    public static void main(String[] args) {
    String input; //Input of user
    double salary; //This is the annual sales value
    double commissionrate; //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("");
    DecimalFormat percent = new DecimalFormat("");
    input = JOptionPane.showInputDialog("Enter the annual salary.");
    salary = Double.parseDouble(input);
    input = JOptionPane.showInputDialog("Enter current commission rate.");
    commissionrate = Double.parseDouble (input);
    input = JOptionPane.showInputDialog("Enter the current sales target.");
    sales = Double.parseDouble (input);
     
    commission = commissionrate * salary;
    pay = commission + salary;
    JOptionPane.showMessageDialog(null, "Commission rate is " +
    commissionrate + ". The amount of pay is " + dollar.format(pay));
     
    if (sales>= (.80* sales) && sales<= 150000)
    incentive = (.80* sales);
    else if (sales >150000)
    incentive = (1.3 * .75 * sales);
     
    JOptionPane.showMessageDialog (null,
    "Total Sales" + "Total Compensation" +
    dollar.format(sales) + (dollar.format(sales) + dollar.format(incentive) ) );
     
    System.exit(0);
    }
    }
    the problem is when I run the program my input methods work as they should but the results are not correct.Here is the results I get after I run
    commission rate 12,the amount of pay is 650,000
    The total annual compensation is 120,000,120,00096000
    The amount of pay in incorrect as well as the Total annual compensation. Not for sure why the calculations is happening the way it is. Help me understand and what I need to change to make it function properly.


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: run problems undesired output

    nothing on the debug

    --- Update ---

    Seems it is placing 120000,120000,96000 as well as the amount of pay incorrectly. The amount of pay should be 50000 *.12 +50000= 56000 should be the correct amount of pay. I am not for sure how to incorporate the acceleration factor of 1.3 into the if statements.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,276
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: run problems undesired output

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Incorrect output and other problems
    By lanmonster in forum What's Wrong With My Code?
    Replies: 12
    Last Post: January 14th, 2013, 10:38 AM
  2. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  3. how could I output to a text area the output of a method
    By mia_tech in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 12th, 2012, 08:49 PM
  4. Problems with input/output and getters/setters
    By robbiep551 in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: January 5th, 2012, 11:44 PM
  5. Having problems with output to console....help!
    By toppcon in forum What's Wrong With My Code?
    Replies: 21
    Last Post: July 13th, 2011, 07:38 PM