Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

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

Posted on 2004-10-01
Medium Priority
208 Views
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("");

System.out.println("");

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();
}

}
0
Question by:Brayn66
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 92

Expert Comment

ID: 12205761
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

LVL 92

Expert Comment

ID: 12205764
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 Comment

ID: 12205813
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("");

System.out.println("");

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 Comment

ID: 12205824
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

LVL 92

Accepted Solution

objects earned 2000 total points
ID: 12205825
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
###### Suggested Courses
Course of the Month9 days, 19 hours left to enroll