I am trying to write a program that calculates the annual raise on salary with different percentages over the course of 4 years. However, the outer loop does not increment the salary or reuse it to calculate the raise after 4 years as required. The program output is also not rounding off to two decimal places as required. What could I be doing wrong?
import java.util.Scanner;
public class AnnualRaise {
public static void main(String[] args) {
//create a scanner for user input
Scanner input = new Scanner(System.in);
System.out.print("Enter a salary: ");
double salary = input.nextInt();
double raise;
int MAX_YEAR = 4;
int MAX_RAISE = 5;
if (salary != 0) {
for (int raiseRate = 3; raiseRate <= MAX_RAISE; raiseRate++) {
System.out.println("Raise rate: " + raiseRate + "%");
raise = Math.round((salary * (raiseRate * 0.01)) * 100 / 100);
salary += raise;
for (int year = 1; year <= MAX_YEAR; year++) {
System.out.println(" Year: " + year + ", Raise: $" + raise + ", Salary: $" + salary);
}
}
}
else
System.out.println("Good bye!");
}
}