Solved

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

Posted on 2004-10-01
5
195 Views
Last Modified: 2010-03-31
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:

import TerminalIO.KeyboardReader;
public class teacherpay{
      public static void main(String [] args) {

      KeyboardReader reader = new KeyboardReader();

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

      startSalary = reader.readDouble("Please enter your starting salary: $ ");
      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();
   }

   }
0
Comment
Question by:Brayn66
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
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

by:objects
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

by:Brayn66
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:

import TerminalIO.KeyboardReader;
public class _startsalary {
      public static void main(String [] args) {

      KeyboardReader reader = new KeyboardReader();

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

      startSalary = reader.readDouble("Please enter your starting salary: $ ");
      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 Comment

by:Brayn66
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

by:
objects earned 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now