Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 6

Java programming homework help?

We're doing while statements and I've been working on this program forever and I can't get it to do what I want, mostly because I have no idea what I'm doing. Here's the problem:

Teachers in most school districts are paid on a schedule that provides a salary based on their number of years of teaching experience. For example, a beginning teacher in the Bellingham School District might be paid $30,000 the first year. For each year of experience after this up to 10 years, a 2 percent increase over the preceding value is received. Write a program that displays a salary schedule for teachers in a school district. The inputs are the starting salary, the percentage increase, and the number of years in the schedule. Each row in the schedule should contain the year number and the salary for that year.

Here's the code I've got so far. I might be pretty off, I don't know.

import java.util.Scanner;

public class Schedule{

public static void main(String[] args){

Scanner reader = new Scanner(System.in);

System.out.print("Enter the starting salary without commas: ");

double StartingSalary = reader.nextDouble();

System.out.print("Enter the percentage increase: ");

double percent = reader.nextDouble();

System.out.print("Enter the number of years in the schedule: ");

double years = reader.nextDouble();

double numyears;

double Salary;

while (numyears <= years){

Salary = StartingSalary+(StartingSalary*percent);}

System.out.print(numyears);

System.out.print(Salary);

}

}

2 Answers

Relevance
  • 9 years ago
    Favorite Answer

    Inside your loop you are not doing any math. Look at this one

    import java.util.Scanner;

    public class CalcTeacherSalary {

    public static void main( String[] args ) {

    // I like just grabbing the String input and change it later, if I need to.

    Scanner sc = new Scanner( System.in );

    System.out.println("Enter starting salary =>: ");

    String salary = sc.nextLine();

    System.out.println("Enter annual percentage increase =>: ");

    String percent = sc.nextLine();

    System.out.println("Enter number of years in the report =>: ");

    String years = sc.nextLine();

    double perc = Double.parseDouble(percent);

    System.out.println("Yr\tSalary\t" + perc*100 + "%");

    int yrCount = 1;

    int yrs = Integer.parseInt( years );

    double pay = Double.parseDouble(salary);

    while( yrCount <= yrs ) {

    System.out.print(yrCount + "\t");

    System.out.print( String.format( "%.2f",pay) + "\t");

    System.out.println(perc);

    pay += perc * pay;

    yrCount++;

    }

    }

    }

  • ?
    Lv 4
    5 years ago

    Bellingham School District Salary Schedule

Still have questions? Get your answers by asking now.