Results 1 to 3 of 3
  1. #1
    j@v@ is offline Member
    Join Date
    Oct 2010
    Location
    Baltimore, MD
    Posts
    5
    Rep Power
    0

    Default 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. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    I'm not sure if I understood you correctly...

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

  3. #3
    j@v@ is offline Member
    Join Date
    Oct 2010
    Location
    Baltimore, MD
    Posts
    5
    Rep Power
    0

    Default

    Wow, yeah that is definitely what I needed, thanks eRaaaa. I was definitely overthinking what needed to be done.

Similar Threads

  1. Replies: 7
    Last Post: 11-03-2009, 02:18 AM
  2. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  3. Sql string with callable statement..
    By nathan in forum JDBC
    Replies: 1
    Last Post: 09-24-2008, 01:41 AM
  4. Replies: 0
    Last Post: 11-20-2007, 04:59 PM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM

Posting Permissions

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