# Thread: If Else Statement using String

1. Member
Join Date
Oct 2010
Location
Baltimore, MD
Posts
5
Rep Power
0

## If Else Statement using String

Hello,

I am having some issues with a small program I have to complete for my Java class. Basically, the program will determine a worker's raise based on their current salary. It will first ask for the current salary, and then for a performance rating (Excellent, Good, or Poor). An Excellent rating will receive a 6% raise, a Good rating will receive a 4% raise, and a Poor rating will receive a 1.5% raise.

Requirements ask for an If Else statement to compute the raise. I have tried many different String mutations with no luck. So far I have the following:

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.next();

***From here, what do I need to do in order to have the rating (Excellent, Good, or Poor) changed in order to use an If Else Statement?***

// Compute the raise using if ...
if (????)
{
raise = (currentSalary * .06);
}
else if (???)
{
raise = (currentSalary * .04);
}
else
{
raise = (currentSalary * .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();
}
}

Thanks in advance for any Pointers!

2. Senior Member
Join Date
Oct 2010
Location
Germany
Posts
785
Rep Power
11
I'm not sure if I understood you correctly...

Java Code:
```if ("excellent".equals(rating.toLowerCase())) {
//....
}else if("good".equals(rating.toLowerCase())){
//...
}```

3. Member
Join Date
Oct 2010
Location
Baltimore, MD
Posts
5
Rep Power
0
Wow, yeah that is definitely what I needed, thanks eRaaaa. I was definitely overthinking what needed to be done.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•