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

Thread: Can't get inputs to add up. Need help fast!!

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    37
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Can't get inputs to add up. Need help fast!!

    I am writing a program for a school assignment. One of the requirements is to forecast the potential sales totals and then add up the salary and commission based on the projected sales totals.

    I was able to get the program to project the sales totals correctly; and I was even able to get it to print out the correct commission totals along side the salary figure; but I can't seem to figure out how to get them to add together!

    I am brand new to Java programming. Please help!!!

    I am attaching the code below. Thanks in advance!!

    package compensation;
    import java.text.DecimalFormat;
    import java.util.Scanner;
     
    /**
     * @author Rick Sebastian
     */
     
    public class Compensation 
    {
        public static void main(String[] args) 
     
        {
            int salary = 60000;  //Defines base salary of $60K
            double sales; //Defines sales object to determine commission
            double compensation; //Defines compensation object that combines salary + commission
            double bonus = 0; //Defines the bonus amount to add to the salary figure
            final int INCREMENT = 5000; //Defines sales increment to calculate potential compensation
            int total = 0; // To hold the total sales in total
            double max_salary = (total * bonus + salary); // Maximum Potential Salary
     
            DecimalFormat formatter = new DecimalFormat("#0.00");
     
            Scanner keyboard = new Scanner(System.in); //Code needed to prompt user to enter info on keyboard
     
            System.out.print("Enter total annual sales figure: $ "); //Prompts user to enter sales figure
            sales = keyboard.nextDouble(); 
     
            if (sales <= 960000) //This represents everything less than the 80% of the $1.2M sales goal where no commission is paid
            {
            bonus = 0;
            }
            if (sales >= 960000) //This represents everything greater than 80% of the $1.2M sales goal that qualifies for a 2.5% commission
            {
            bonus = sales * .025;    
            }
            if (sales > 1200000) //This represents everything greater than 100% of the $1.2M sales goal that qualifies for a 2.5% commission + 1.25% accellerator
            {
            bonus = sales * .0375;
            }
            compensation = salary + bonus; //Formula to calculate total compensation
     
            System.out.println("Your total annual compensation is $" + compensation); //This code displays the total compensation including salary + commission
     
            System.out.println("Potential Total Sales\tMax Potential Salary Total");  // Display the table headings.
            System.out.println("------------------------------------------");
     
            for (total = (int) sales; total <= sales * 1.5; total += INCREMENT) // Loop to calculate the Total Potential Sales and Total Potential Compensation
            {
             System.out.printf("%20d\t\t%,.2f\n", total, total*bonus+salary); // Display the Potential Total Sales and Total Potential Annual Compensation
            } 
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Please post the program's output and add some comments to the output saying what is wrong with it and show what it should look like.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    37
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Quote Originally Posted by Norm View Post
    Please post the program's output and add some comments to the output saying what is wrong with it and show what it should look like.
    Sorry. Here is a screen shot showing the issues. Basically, the program needs to add the 2 figures being displayed in the Total Potential Compensation column instead of displaying them side by side. The first figure is the commission and the second is the $60K salary. Ideally, the column should just show $85,000 for line one and increment all the way down. I hope that makes sense.
    Capture.jpg
    Attached Images Attached Images

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Please copy and paste the window's contents here. The image is too small and its contents can't be copied and pasted in comments.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    show $85,000 for line one and increment all the way down
    The code needs to have a statement inside the loop that increments AND SAVES the value for the next line.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jan 2013
    Posts
    37
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Here's the output from NetBeans. I hope it makes more sense.

    run:
    Enter total annual sales figure: $ 1000000
    Your total annual compensation is $85000.0 <--- This number should be formatted as $85,000.00

    Potential Total Sales Max Potential Salary Total
    ------------------------------------------
    1000000 25,000,060,000.00 <--- This output should total to $85,000 instead of displaying side by side as 25,000 and 60,000.
    1005000 25,125,060,000.00
    1010000 25,250,060,000.00
    1015000 25,375,060,000.00
    1020000 25,500,060,000.00
    1025000 25,625,060,000.00
    1030000 25,750,060,000.00
    1035000 25,875,060,000.00
    1040000 26,000,060,000.00
    1045000 26,125,060,000.00
    1050000 26,250,060,000.00
    1055000 26,375,060,000.00
    1060000 26,500,060,000.00
    1065000 26,625,060,000.00
    1070000 26,750,060,000.00
    1075000 26,875,060,000.00
    1080000 27,000,060,000.00
    1085000 27,125,060,000.00
    1090000 27,250,060,000.00
    1095000 27,375,060,000.00
    1100000 27,500,060,000.00
    1105000 27,625,060,000.00
    1110000 27,750,060,000.00
    1115000 27,875,060,000.00
    1120000 28,000,060,000.00
    1125000 28,125,060,000.00
    1130000 28,250,060,000.00
    1135000 28,375,060,000.00
    1140000 28,500,060,000.00
    1145000 28,625,060,000.00
    1150000 28,750,060,000.00
    1155000 28,875,060,000.00
    1160000 29,000,060,000.00
    1165000 29,125,060,000.00
    1170000 29,250,060,000.00
    1175000 29,375,060,000.00
    1180000 29,500,060,000.00
    1185000 29,625,060,000.00
    1190000 29,750,060,000.00
    1195000 29,875,060,000.00
    1200000 30,000,060,000.00
    1205000 30,125,060,000.00
    1210000 30,250,060,000.00
    1215000 30,375,060,000.00
    1220000 30,500,060,000.00
    1225000 30,625,060,000.00
    1230000 30,750,060,000.00
    1235000 30,875,060,000.00
    1240000 31,000,060,000.00
    1245000 31,125,060,000.00
    1250000 31,250,060,000.00
    1255000 31,375,060,000.00
    1260000 31,500,060,000.00
    1265000 31,625,060,000.00
    1270000 31,750,060,000.00
    1275000 31,875,060,000.00
    1280000 32,000,060,000.00
    1285000 32,125,060,000.00
    1290000 32,250,060,000.00
    1295000 32,375,060,000.00
    1300000 32,500,060,000.00
    1305000 32,625,060,000.00
    1310000 32,750,060,000.00
    1315000 32,875,060,000.00
    1320000 33,000,060,000.00
    1325000 33,125,060,000.00
    1330000 33,250,060,000.00
    1335000 33,375,060,000.00
    1340000 33,500,060,000.00
    1345000 33,625,060,000.00
    1350000 33,750,060,000.00
    1355000 33,875,060,000.00
    1360000 34,000,060,000.00
    1365000 34,125,060,000.00
    1370000 34,250,060,000.00
    1375000 34,375,060,000.00
    1380000 34,500,060,000.00
    1385000 34,625,060,000.00
    1390000 34,750,060,000.00
    1395000 34,875,060,000.00
    1400000 35,000,060,000.00
    1405000 35,125,060,000.00
    1410000 35,250,060,000.00
    1415000 35,375,060,000.00
    1420000 35,500,060,000.00
    1425000 35,625,060,000.00
    1430000 35,750,060,000.00
    1435000 35,875,060,000.00
    1440000 36,000,060,000.00
    1445000 36,125,060,000.00
    1450000 36,250,060,000.00
    1455000 36,375,060,000.00
    1460000 36,500,060,000.00
    1465000 36,625,060,000.00
    1470000 36,750,060,000.00
    1475000 36,875,060,000.00
    1480000 37,000,060,000.00
    1485000 37,125,060,000.00
    1490000 37,250,060,000.00
    1495000 37,375,060,000.00
    1500000 37,500,060,000.00
    BUILD SUCCESSFUL (total time: 4 seconds)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    1000000 25,000,060,000.00
    What is the value of: total*bonus+salary? That is what is being printed.


    Check your equations.
    Last edited by Norm; February 3rd, 2013 at 12:24 PM. Reason: Wrong conclusion
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jan 2013
    Posts
    37
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Quote Originally Posted by Norm View Post
    What is the value of: total*bonus+salary? That is what is being printed.


    Check your equations.
    The value of total*bonus+salary equals the total sales figure (far left column) times the commission multiplier (listed in the "if statements" above, plus the annual salary of $60,000.

    So in the case of a person doing $1,000,000 in sales (the first output) they would receive a $25,000 commission in addition to their $60,000 salary. So the idea is to add those 2 figures together to show that based on $1,000,000 in sales, they made $85,000.00 in total compensation for the year.

    Additionally, the requirement of the assignment is to extend the calculations out to include an additional 50% in sales (by increments of $5,000) and potential commissions. So in my example of $1,000,000.00 in sales, the "for loop" I included extends the potentials sales out to $1,500,000.00 and the program correctly displays the commissions based on those sales.

    But I need the commission and the salary to total in the right hand column, not list side by side. That's the part I can't figure out.

    I thought the statement "System.out.printf("%20d\t\t%,.2f\n", total, total*bonus+salary);" would ADD the total*bonus+salary together. Apparently not.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Have you worked with the numbers on a piece of paper or with a calculator and gotten the values that you want to see printed?
    What is the equation that will generate: 85000.00 given 1000000?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jan 2013
    Posts
    37
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Quote Originally Posted by Norm View Post
    Have you worked with the numbers on a piece of paper or with a calculator and gotten the values that you want to see printed?
    What is the equation that will generate: 85000.00 given 1000000?
    The numbers you see are correct. $25,000 is the correct commission on sales of $1,000.000. The salary of $60,000 is a constant.

    So that's not the problem.

    The problem is, how do I get the code to add the $25,000 commission and the $60,000 salary together on one line instead of displaying them side by side???

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    What is the value of this expression: total*bonus+salary
    Print it out without formatting to see what its value is.
    Its a VERY BIG number.

    What is the equation that will create the 85000.00 value that you want to see given the 1000000?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Jan 2013
    Posts
    37
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    Quote Originally Posted by Norm View Post
    What is the value of this expression: total*bonus+salary
    Print it out without formatting to see what its value is.
    Its a VERY BIG number.

    What is the equation that will create the 85000.00 value that you want to see given the 1000000?
    The value in my brain of (total*bonus+salary) is the equation to give me the $85,000 value for line 1 and every line thereafter.

    I don't know how to create an equation (beyond what you see in the code I've posted) to do what I need it to do. That's where I need your help.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't get inputs to add up. Need help fast!!

    85000 is 60000 + 25000
    The 60000 is a fixed amount for every line.
    How is the 25000 computed? How is it based on 1000000?
    Should the 25000 value change for every row that is printed? If so, there needs to be code inside the loop that computes the new value to add to the 60000.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need Help Fast - Please Help in Java ArrayList
    By anonb in forum Collections and Generics
    Replies: 6
    Last Post: November 5th, 2012, 05:26 PM
  2. need HELP FAST PLEASE HELP ME
    By britben95 in forum Member Introductions
    Replies: 1
    Last Post: November 14th, 2011, 08:05 PM
  3. need help fast
    By coke32 in forum Loops & Control Statements
    Replies: 6
    Last Post: October 31st, 2011, 11:04 PM
  4. need help fast!!
    By nwollis in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 27th, 2010, 05:12 PM
  5. Code stopping, need help fast.
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 11th, 2010, 09:00 AM