Results 1 to 3 of 3
Thread: If Else Statement using String
- 10-08-2010, 04:13 PM #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!
- 10-08-2010, 04:21 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
I'm not sure if I understood you correctly...
Java Code:if ("excellent".equals(rating.toLowerCase())) { //.... }else if("good".equals(rating.toLowerCase())){ //... }
- 10-08-2010, 04:29 PM #3
Member
- Join Date
- Oct 2010
- Location
- Baltimore, MD
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
The constructor Person(String, String, Date) is undefined
By fh84 in forum New To JavaReplies: 7Last Post: 11-03-2009, 02:18 AM -
Let eclipse warn about a semicolon after an if statement and string == string?
By foobar.fighter in forum EclipseReplies: 5Last Post: 01-11-2009, 10:12 AM -
Sql string with callable statement..
By nathan in forum JDBCReplies: 1Last Post: 09-24-2008, 01:41 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Statement or Prepared Statement ?
By paty in forum JDBCReplies: 3Last Post: 08-01-2007, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks