Computing A Raise File Salary java contains most of a program that takes as inpu
ID: 3722971 • Letter: C
Question
Computing A Raise File Salary java contains most of 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. This is similar to question #3 in the pre-lab, except that the performance rating here is being entered as a String the three possible ratings are "Excellent", "Good", and "Poor". As in the pre-lab, an employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Add the if... .else... statements to program Salary to make it run as described above. Note that you will have to use the equals method of the String class (not the relational operatorto compare two strings (see Section 5.3, Comparing Data). Salary.java Computes the amount of a raise and the new salary for an employee. The current salary /and a performance rating (a String: "Excellent", //Good" or "Poor.) are input import java.util.Scanner import java.text.NumberFormat; public class Salary public static void main (String args) employee's current salary amount of the raise double currentsalarY: double raise double newSalary String rating // new salary for the employee // performance rating Scanner scan new Scanner (System.in); System.out.print ("Enter the current salary: currentSalaryscan.nextDouble) System.out.print ("Enter the performance rating (Excellent, Good, or Poor):); rating scan . next(); / Compute the raise using if newSalary currentSalary + raise ; Print the results NumberFormat moneyNumberFormat.getCurrencyInstance) System.out.println) Systen.out.println( Current Salary: System.out.println Amount of your raise: money.format (raise)); System.out.println( "Your ew salary: System.out.println) +money. format (currentSalary)) +money. format (newSalary)Explanation / Answer
Salary.java:
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 raise
double newSalary; // new salary for the employee
String rating; // performace rating
Scanner scan = new Scanner(System.in);
System.out.print("Enter current salary: ");
currentSalary = scan.nextDouble();
System.out.print("Enter the performance rating (Excellent, Good, Poor): ");
rating = scan.next();
// computing raise
if (rating.toUpperCase().equals("EXCELLENT")) {
raise = (currentSalary * 6) / 100;
}else if(rating.toUpperCase().equals("GOOD")) {
raise = (currentSalary * 4) / 100;
}else if(rating.toUpperCase().equals("POOR")) {
raise = (currentSalary * 1.5) / 100;
}else {
System.out.print("Invalid rating Terminating Program.. ");
raise = 0;
System.exit(1);
}
newSalary = currentSalary + raise;
//Print the result
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();
}
}
Out put:
Enter current salary: 100
Enter the performance rating (Excellent, Good, Poor): Excellent
Current Salary: $100.00
Amount of your raise: $6.00
Your new Salary: $106.00
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.