# trying to loop for a salary schedule w/ raises for 10 years

The following code is supposed to:

Display a ten year schedule that show the increase for ten years worth of work based oon a users input.

The inputs are:
1.starting salary
2.annual percentage increase (this amount entered remains contant throughout the program)
3.years worked (experience)

I have a problem with implementing a way to get the annual salary to incrementhigher during the ten year schedule.
Thanks, lauren

My source code:

public class teacherpay{
public static void main(String [] args) {

double startSalary;
double percentageIncrease;
double annualSalary;
int yearsWorked;
double salaryRange;
double yearN;   // extra variable declared

System.out.println("");

percentageIncrease = reader.readDouble("Please enter a whole number for the annual increase percentage: % ");
System.out.println("");

yearsWorked = reader.readInt("Please enter the number of years worked:  ");
System.out.println("");
System.out.println();

percentageIncrease = (percentageIncrease / 100);
annualSalary = ((startSalary * percentageIncrease) + startSalary);

for(yearsWorked = 1; yearsWorked<=10; yearsWorked = yearsWorked+1)

System.out.println("Annual salary for year:  " + yearsWorked + ": " + annualSalary);
System.out.println();
System.out.println();
System.out.println();
}

}
###### Who is Participating?

Commented:
theres a missing {

annualSalary = startSalary;

for(yearsWorked = 1; yearsWorked<=10; yearsWorked = yearsWorked+1)
{
annualSalary += annualSalary * percentageIncrease;

System.out.println("Annual salary for year:  " + yearsWorked + ": " + annualSalary);
System.out.println();
System.out.println();
System.out.println();
}

0

Commented:
put the calculation iside your loop:

annualSalary = startSalary;

for(yearsWorked = 1; yearsWorked<=10; yearsWorked = yearsWorked+1)

System.out.println("Annual salary for year:  " + yearsWorked + ": " + annualSalary);
System.out.println();
System.out.println();
System.out.println();
annualSalary += annualSalary * percentageIncrease;
}
0

Commented:
may want to do the calc first:

annualSalary = startSalary;

for(yearsWorked = 1; yearsWorked<=10; yearsWorked = yearsWorked+1)

annualSalary += annualSalary * percentageIncrease;
System.out.println("Annual salary for year:  " + yearsWorked + ": " + annualSalary);
System.out.println();
System.out.println();
System.out.println();
}
0

Author Commented:
Thanks! I have added but it still won't calculate and display the schedule range.

*The terminal window results display:

Annual salary for year: 1: \$ 10000
Annual salary for year: 2: \$ 10000
Annual salary for year: 3: \$ 10000
Annual salary for year: 4: \$ 10000
and so forth....

.........the amount doesn't change (\$10000).  lauren

*Here is the changed source code:

public class _startsalary {
public static void main(String [] args) {

double startSalary;
double percentageIncrease;
double annualSalary;
int yearsWorked;
double salaryRange;
double yearN;   // extra variable declared

System.out.println("");

percentageIncrease = reader.readDouble("Please enter a whole number for the annual increase percentage: % ");
System.out.println("");

yearsWorked = reader.readInt("Please enter the number of years worked:  ");
System.out.println("");
System.out.println();

percentageIncrease = (percentageIncrease / 100);
annualSalary = ((startSalary * percentageIncrease) + startSalary);//after your message(object) I tried keeping and taking out this line of code and it made no difference?

annualSalary = startSalary;

for(yearsWorked = 1; yearsWorked<=10; yearsWorked = yearsWorked+1)

System.out.println("Annual salary for year:  " + yearsWorked + ": " + annualSalary);
System.out.println();
System.out.println();
System.out.println();
annualSalary += annualSalary * percentageIncrease;
}

}

0

Author Commented:
I put the change in and it displayed only the 11th year (?) result that looked like it could have been a correct amount for that year.

annualSalary = startSalary;

for(yearsWorked = 1; yearsWorked<=10; yearsWorked = yearsWorked+1)

annualSalary += annualSalary * percentageIncrease;

System.out.println("Annual salary for year:  " + yearsWorked + ": " + annualSalary);
System.out.println();
System.out.println();
System.out.println();
}

}

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.