In: Computer Science
Directions: Create a program that takes as input an employee's salary and a rating of the employee's performance and then computes the appropriate raise for the employee based on that rating. The performance rating is entered into the program as a String. The three possible ratings are "Outstanding", "Acceptable", and "Needs Improvement". An employee who is rated as Outstanding will receive a 10.2% raise, one rated Acceptable will receive a 7% raise, and one rated as Needs Improvement will receive a 1.2% raise.
Add the if... else... statements to program PerformanceRating to make it run as described above. Note that you will have to use the equals method of the String class (not the relational equality operator ==) to compare two strings (the user input and the rating).
You should also note how the NumberFormat class from the text package is being used to format currency in this lab.
Download the Performance Rating instructions and the Performance Rating source file. Follow your teacher's instructions for submitting the .java file and a screenshot from the BlueJ terminal window.
The .equals() method will compare two strings and return true if the strings are identical and false if the strings differ at all.
1. Create a hand drawn flow chart showing the logic of the if... else...statements
2. Open PerformanceRating. Copy and paste the code from this document intoBlueJ.
3. Add your identifying information to the comments at the top of the code
4. Finish the code to execute the if...else and accurately calculate the raise.
5. Test your code for: a. Rating of Outstanding b. Rating of Acceptable c. Rating of Needs Improvement
.
Here is an example of using the .equals() method:
System.out.print ("Enter the day of the week (Sunday, Monday, etc.): "); String day = scan.next();
if (day.equals("Sunday"))
System.out.println("Stay at home.");
else
System.out.prntln("Go to school.");
Positive ratings needed. Thank you.
Flow Chart :
Java Code :
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
double salary;
System.out.println("Enter the
salary of the employee: ");
salary = sc.nextFloat(); /// input
the salary
System.out.println("Enter the
Performance rating of the employee: ");
String PerformanceRating =
sc.next(); /// input the Performance Rating
if(PerformanceRating.equals("Outstanding"))
{
salary = salary + salary * 0.102;
/// if the rating is Outstanding then raise will be 10.2%
System.out.println("Salary of the
employee after the raise: "+salary);
}
else
if(PerformanceRating.equals("Acceptable"))
{
salary = salary + salary * 0.07;
/// if the rating is Acceptable then raise will be 7%
System.out.println("Salary of the
employee after the raise: "+salary);
}
else
{
salary = salary + salary * 0.012;
/// if the rating is Need Improvement then raise will be 1.2%
System.out.println("Salary of the
employee after the raise: "+salary);
}
}
}
Output: