Rafael
2010-10-27 18:18:10 UTC
// Salary.java
//
// Computes the amount of a raise and the new
// salary for an employee. The current salary
// and a performance rating (a String: "Excellent",
// "Good" or "Poor") are input.
// ***************************************************************
import java.util.Scanner;
import java.text.NumberFormat;
public class Salary {
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.nextLine();
// Compute the raise using if ...
if (rating == "Excellent")
{raise = currentSalary * 0.06;
newSalary = currentSalary + raise;
}
if (rating == "Good")
{raise = currentSalary * 0.04;
newSalary = currentSalary + raise;
}
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();
}
}
The problem is that JCreator says the variables 'raise' and 'newSalary' aren't initialized in the printing process. What's wrong with the code?