The variable "raise" isn't classed as initialised despite trying to do so in the nested "if" statements. This is an exercise for university where all we're supposed to do is add the necessary if statements to get it to work. The if statements are ignored no matter what I do. What am I doing wrong?
Here is the code with the if statements I entered.
package selectionIteration;
import java.util.Scanner;
import java.text.NumberFormat;
public class Raise {
public static void main (String[] args)
{
double currentSalary; // employee's current salary
double raise; // amount of the raise
double newSalary; // new salary for the employee
String rating; // performance rating
Scanner scan = new Scanner(System.in);
System.out.print ("Enter the current salary: ");
currentSalary = scan.nextDouble();
System.out.print ("Enter the performance rating (Excellent, Good, or Poor): ");
rating = scan.next();
// Compute the raise using if ...
if (rating == "Excellent")
raise = currentSalary * 0.06;
if (rating == "Good")
raise = currentSalary * 0.04;
if (rating == "Poor")
raise = currentSalary * 0.015;
newSalary = currentSalary + raise;
// Print the results
NumberFormat money = NumberFormat.getCurrencyInstance();
System.out.println();
System.out.println("Current Salary: " + money.format(currentSalary));
System.out.println("Amount of your raise: " + money.format(raise));
System.out.println("Your new salary: " + money.format(newSalary));
System.out.println();
}
}