Results 1 to 2 of 2

Thread: Code trouble

  1. #1
    Jack_Pyrtle is offline Member
    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Default Code trouble

    My java code complies correctly runs and displays correctly but it is not calculating the annualSales * rate correctly. Can anyone help?


    /*
    * The program will calculate annual salary and commission for a sales person.
    The user shall input the annual sales to calculate.
    */

    package salescommission;

    /**
    * @author Jack Pyrtle
    */
    import java.util.Scanner;
    public class SalesCommission {


    // This is the beginning of the main method
    public static void main(String[] args)
    {

    // This method displays the salesperson's fixed annual salary
    double AnnualSales;// Salesperson's annual sales
    double annualSalary; // Salesperson's annual salary
    annualSalary=10000; //Salesperson's fixed annual salary.
    double rate= 0.10; // Salesperson commision rate
    System.out.println("The Salesperson earns a fixed annual salary of $"
    + annualSalary + "." ) ;

    // Creates Scanner to collect annual sales input from salesperson
    Scanner input = new Scanner(System.in);
    System.out.print("Enter annual sales: ");
    AnnualSales = input.nextDouble();
    double commissionCalc;// Calculates commission of annual sales
    commissionCalc= AnnualSales * rate;
    // This method displays the salesperson's commission rate
    System.out.println("The annual sales of the salesperson is $"
    + commissionCalc + " using a 10% commission.");
    double totalAnnualSum; // Salesperson's total annual compensation
    totalAnnualSum = AnnualSales * rate + annualSalary;
    System.out.println("The total annual compensation of the salesperson "
    + "is: $" + totalAnnualSum + ".");
    } // end main method
    } // end class SalesCommission


    --------------------------------------------------------------------------------------------

    run:
    The Salesperson earns a fixed annual salary of $10000.0.
    Enter annual sales: 100000.00
    The annual sales of the salesperson is $10000.0 using a 10% commission. (the is incorrect)
    The total annual compensation of the salesperson is: $20000.0.
    BUILD SUCCESSFUL (total time: 13 seconds)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,598
    Rep Power
    5

    Default Re: Code trouble

    Well, 10% of $100,000 is $10,000. With a base salary of $10,000 that would be $20,000. What is the error?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Having trouble correcting this code.
    By Denis2k11 in forum New To Java
    Replies: 7
    Last Post: 10-14-2012, 01:13 AM
  2. Having trouble with code in DrJava
    By jonstewart in forum New To Java
    Replies: 15
    Last Post: 04-07-2011, 11:34 PM
  3. trouble understanding code help
    By yasmin k in forum New To Java
    Replies: 4
    Last Post: 11-16-2009, 09:46 PM
  4. Trouble compiling code
    By waelhelbawi in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 04:25 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
  •