1. Member
Join Date
Jul 2014
Posts
1
Rep Power
0

## 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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,908
Rep Power
10

## 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•