assignment4
This commit is contained in:
48
labs/lab5/## IF STATEMENT.txt
Normal file
48
labs/lab5/## IF STATEMENT.txt
Normal file
@ -0,0 +1,48 @@
|
||||
## IF STATEMENT
|
||||
|
||||
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 = 0; // amount of the raise (initialized to 0)
|
||||
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();
|
||||
|
||||
// Consume the newline character left by nextDouble
|
||||
scan.nextLine();
|
||||
|
||||
System.out.print("Enter the performance rating (Excellent, Good, or Poor): ");
|
||||
rating = scan.nextLine();
|
||||
|
||||
// Compute the raise using if-else
|
||||
if (rating.equals("Excellent")) {
|
||||
raise = currentSalary * 0.06; // 6% raise for Excellent
|
||||
} else if (rating.equals("Good")) {
|
||||
raise = currentSalary * 0.04; // 4% raise for Good
|
||||
} else if (rating.equals("Poor")) {
|
||||
raise = currentSalary * 0.015; // 1.5% raise for Poor
|
||||
} else {
|
||||
System.out.println("Invalid rating entered.");
|
||||
return; // Exit the program if the rating is not valid
|
||||
}
|
||||
|
||||
// Compute the new salary
|
||||
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user