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: need help creating a Commission Calculator

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help creating a Commission Calculator

    I need to create a simple Java program for a commission calculator with the following requirements:
    I need to ask the user to enter their total sales (as a double) in at the keyboard and I need to use "if" statements to tell them
    their commission (sales * commission rate) using the following criteria:
    o < $8000 in sales – Commission rate = 10%
    o $8000 to $12000 in sales – Commission rate = 12%
    o $12000.01 to $18000 in sales – Commission rate = 15%
    o $18000.01 to $20000 in sales – Commission rate = 18%
    o > $20000 in sales – Commission rate = 20%
    Then for the output the user’s Commission in a well formatted way (use the DecimalFormat class)
    In comment blocks have a description of what the program does. thank you! I think I did something wrong here is mine
    import java.util.Scanner;
     
    public class CommissionCalculator
    //This program calculates the commission of sales
    {
      public static void main(Strings[] args)
       {
      // create a scanner
      Scanner input = new Scanner(System.in);
     //define variable
       double sales;   //inputted sales amount
       double commission = 0; //commission pay amount
     
     
      System.out.print("Please enter sales amount:");
     
      double sales = input.nextDouble();
     
       if (sales > 20000.01 )
     
    		commission = sales * .20;
     
       else if (sales > 18000.01 && sales <= 20000)
     
    		commission = sales * .18;
     
       else if (sales > 12000.01 && sales <= 18000)
     
    		commission = sales * .15;
     
      else if (sales > 8000.01 && sales <= 12000)
     
    		commission = sales * .12;
     
      else (sales <= 8000)
     
    		commission = sales * .10;
     
    {
    System.out.println("Your Commission + sales total is :$" + mask.format((sales));}
    }
     
    }
    Attached Files Attached Files
    Last edited by Rhiannon1488; March 20th, 2014 at 06:09 PM.


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: need help creating a Commission Calculator

    Hi, Welcome to the forum! Please read Announcements - What's Wrong With My Code? for guidlines on how to code
    I think I did something wrong here is mine
    so what is wrong?

    can't you just paste your code here so others can read it without downloading?

  3. #3
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: need help creating a Commission Calculator

    public static void main(Strings[] args)
    the argument should be String[] args not Strings[]

    else (sales <= 8000)
    you don't have to put condition in else keyword.
    the program will read the statements in else when the if and else if condition falls to false.

    if (sales > 20000.01 )

    commission = sales * .20;

    else if (sales > 18000.01 && sales <= 20000)

    commission = sales * .18;

    else if (sales > 12000.01 && sales <= 18000)

    commission = sales * .15;

    else if (sales > 8000.01 && sales <= 12000)

    commission = sales * .12;

    else (sales <= 8000)

    commission = sales * .10;
    please don't put carriage return every after conditional statement since you are not using braces,
    and please, use braces every conditional statement.

    {
    System.out.println("Your Commission + sales total is :$" + mask.format((sales));}
    why do you have to put the opening and closing braces for printing?
    and you never declare an Object of mask. what is mask?

    double sales; //inputted sales amount
    double commission = 0; //commission pay amount


    System.out.print("Please enter sales amount:");

    double sales = input.nextDouble();
    you declared double sales twice.

Similar Threads

  1. [SOLVED] creating an iterator without creating a class for it
    By Lenjaku in forum Collections and Generics
    Replies: 6
    Last Post: January 22nd, 2014, 03:17 AM
  2. Sales Commission
    By recoone in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 7th, 2013, 06:43 AM
  3. Simple Commission Calculator
    By mrivera8504 in forum What's Wrong With My Code?
    Replies: 22
    Last Post: August 27th, 2012, 06:35 PM
  4. [SOLVED] Calculating Commission with a GUI???
    By jbarcus81 in forum AWT / Java Swing
    Replies: 13
    Last Post: February 25th, 2012, 07:35 AM
  5. Creating and implementing class for creating a calendar object
    By kumalh in forum Object Oriented Programming
    Replies: 3
    Last Post: July 29th, 2011, 08:40 AM