In: Computer Science
I need someone to create a program for me:
Create a program that takes as input an employee's salary and a
rating of the
employee's performance and computes the raise for the employee. The
performance rating here is being entered as a String
—
the three possible ratings are
"Outstanding",
"Acceptable", and "
Needs Improvement
". An employee who is
rated
outstanding
will receive a
10.2
% raise, one rated
acceptable
will receive a
7
% raise, and one rated
needs improvement
will receive a
1.
2
% raise.
Add the
if... else...
statements to program
Raise
to make i
t run as described above.
Note that you will have to use the
equals
method of the String class (not the
relational operator ==) to compare two strings
.
You should also note how the NumberFormat class from the text package is being
used to format currency i
n this lab.
1.
Create a hand drawn flow chart showing the logic of the if
... else...
statements
2.
Open
P
erformance
R
ating
. Copy and paste the code from this document into
BlueJ.
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
6.
Submit your
.java file
, your flowchart, and your
screenshot
from the BlueJ
terminal window
.
Java Program:
import java.util.*;
import java.text.NumberFormat;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Salary : ");
double salary = sc.nextDouble();
sc.nextLine(); // holds the scanner Class to not skip
System.out.print("Enter Rating : ");
String rating = sc.nextLine();
double raise = 0;
NumberFormat nf = NumberFormat.getInstance(Locale.US); // NumberFormat Class
if (rating.equals("Outstanding"))
{
raise = (salary * 10.2) / 100;
}
else if (rating.equals("Acceptable"))
{
raise = (salary * 7) / 100;
}
else if (rating.equals("Needs Improvement"))
{
raise = (salary * 1.2) / 100;
}
System.out.println("\nSalary Raise For Employee : "+ nf.format(raise));
System.out.println("New Salary For Employee : " + nf.format(salary + raise));
}
}
Output:
FlowChart:
Thumbs Up Please !!!