# Java - Calculation Program



## Nakima (May 28, 2014)

Any help appreciated. I have a program that calculates specific sales at different rates if certain target's are reached. I ma having a problem at the end of the program where specifically I am trying to get it to display potential sales at 5k increments. The whole program works except for this last loop at the end. It only displays 1 amount and ends the program. Any guidance as to what I am doing wrong would be appreciated . Thanks ( I tried to copy over the format with indentation and edit it, but the screen here would not allow me to do it.)

//This program calculates annual sales 
import java.util.Scanner; // Program assigned to use Scanner for input

public class AnnualSales
{
//Main method begins execution of Java application
public static void main(String[] args)
{
//create scanner to obtain input from the command window
Scanner input=new Scanner(System.in);

double annualSales; //Annual sales made during the year
double annualTotal = 0; //The total annual compensation 
double salary; //Annual Salary of sales representative
double commRate; //Commission rate
double salesTarget;
double potSales; //Potential sales
double counter;

salary = 60000; //set rate of 60,000.00 per sales rep
commRate=.10; //set commission rate of 10 percent
salesTarget=100000;

System.out.println("The current sales target is $100,000.00");
System.out.print("Enter the amount of sales:$"); //input query of sales
annualSales = input.nextInt(); //input value stored

if (annualSales >= 80000)
{
if (annualSales < 100000)
{
annualTotal = annualSales * commRate + salary;
System.out.println("You earned 10% sales incentive!");
System.out.println("Total compensation is :$" + annualTotal);
}

else
{
annualTotal = annualSales * (commRate * 2.5) + salary;
System.out.println("You earned a 10% sales incentive!");
System.out.println("You also earned the extra incentive!");
System.out.println("Total compensation is :$" + annualTotal);
}
}
else
{
//output of claculation
System.out.println("No sales incentive was earned.");
System.out.println("The total compensation is:$" + salary);
}

potSales = annualSales * .50 + annualSales;

System.out.println("This is your potential sales in 5k increments.");
System.out.println("Total Sales Total Compensation");
System.out.println("----------------------------------");

for (counter = annualSales; counter <= potSales; counter++); 
// the loop and then print the commission with the projected sales. 
System.out.println(counter + "\t\t" + counter );

} //end main method
} //end class AnnualSales


----------



## Ent (Apr 11, 2009)

The problem you have is a semicolon after the for statement, which is like a full stop or period in English. Therefore the for loop is effectively saying "count from annualSales to potSales, full stop" instead of "count from annual sales to potSales and for each one print out the message.

You want to replace 

```
for (counter = annualSales; counter <= potSales; counter++); 
// the loop and then print the commission with the projected sales. 
System.out.println(counter + "\t\t" + counter );
```
with

```
for (counter = annualSales; counter <= potSales; counter++) {
	// the loop and then print the commission with the projected sales. 
	System.out.println(counter + "\t\t" + counter ); 
}
```


----------



## Ethan9355 (Jun 9, 2014)

Thanks Ent, for the answer. I was facing same problem in Java calculation program. Reusability is one of the greatest features of Java which make life of a developer so simple. Recently, I used the services of [advertizing deleted by mod] for migration of my application servers to JEE platform. They did quite a good job at a very reasonable cost.


----------

