Salary Raises Write a program that determines the raise that
Salary Raises
Write a program that determines the raise that sales employees will receive for a car company. The company issues a 6% raise if the employee sells 100 or more cars during the year. If not the employee receives a 1.5% raise.
Your program should receive as input: the name of the employee, their current salary and the number of cars they sold this year. It should output: the employee’s name, their current salary, the raise and the new salary. Your program should also have the option of processing more than one salary raise per execution.
Input validation: Do not accept values less than 10000 for the salary. Do not accept values less than or equal to 0 for the number of cars sold.
You will need:
A do while loop to repeat the method. This will allow you to enter one or more employee information to determine their raises. You MUST use a do while loop to enclose most of your main method definition.
In the do-while loop you will need:
Assignment statements to store the name, current salary and number of cars sold for each sales person.
Two while loops for input validation. The first loop should ensure that the salary entered is not less than $10000. The second loop should ensure that the number of cars sold is less than or equal to 0.
A conditional operator to determine the raise. If the number of cars sold in the year is greater than or equal to 100, then the raise is 6% of the current salary; otherwise the raise is only 1.5% of the current salary. You MUST use the conditional operator for this part, NOT an if-else statement!
An assignment statement to compute the new salary
Output statements for the name, current salary, amount of raise and new salary. Make sure to include proper formatting for money.
An output statement to prompt the user for repeating the program, as well as an assignment statement to store the response.
A method to skip (or ignore) the [Enter] key after responding to part f. (This is useful for preventing logical errors within your loop and has been provided for you in the code shell.)
Sample Output:
Enter the employee\'s name: Joe Cool
Enter the current salary: 6000
Salary cannot be less than $10000.
Re-enter the current salary: 60000
Enter the number of cars Joe Cool sold this year: 102
Name: Joe Cool
Current Salary: $60,000.00
Amount of raise: $3,600.00
New salary: $63,600.00
Process next employee salary and raise? Enter yes or no: Yes
Enter the employee\'s name: Bobby Knox
Enter the current salary: 50000
Enter the number of cars Bobby Knox sold this year: -12
That\'s clearly invalid.
Re-enter the number of cars Bobby Knox sold this year: 12
Name: Bobby Knox
Current Salary: $50,000.00
Amount of raise: $750.00
New salary: $50,750.00
Process next employee salary and raise? Enter yes or no: no
Code Shell
// ********************************************************
// Salary.java
//
// Computes the amount of a raise and the new salary for
// one or more employees. If the employee sells 100 or
// more cars, the employee receives a higher raise
// ********************************************************
import java.util.Scanner;
import java.text.NumberFormat;
public class Salary
{
public static void main (String[] args)
{
final int CARS = 100; // car threshold
String employeeName; // name of employee
double currentSalary; // employee\'s current salary
double raise; // amount of the raise
double newSalary; // new salary for the employee
String response; // response
int carsSold; // number of cars sold
Scanner scan = new Scanner (System.in);
//Begin do while
do
{
//Get the employee\'s name
//Get the employee\'s salary
//Input validation for salary
//Get the number of cars sold by the employee
//Input validation for number of cars sold
// Compute the raise using conditional operator
// Compute the new salary
// Print the results
//Run the program again?
scan.nextLine(); //Reads extra newline character
}while (…); //end do while
}
}
Solution
Salary.java
import java.util.Scanner;//keyboard inputting
public class Salary {//main class
public static void main(String[] args) {//main method
final int CARS = 100; // car threshold
String employeeName; // name of employee
double currentSalary; // employee\'s current salary
double raise; // amount of the raise
double newSalary; // new salary for the employee
String response = \"Yes\"; // response
int carsSold; // number of cars sold
Scanner scan = new Scanner(System.in);
//Begin do while
do {
//Get the employee\'s name
System.out.print(\"Enter the employee name :\");
employeeName = scan.next();
System.out.print(\"Enter the current salary :\");
//Get the employee\'s salary
currentSalary = scan.nextDouble();
if (currentSalary < 10000) {
System.out.print(\" Salary cannot be less than $10000.\");
System.out.print(\"Reenter the current salary :\");
currentSalary=scan.nextDouble();
}
//Input validation for salary
System.out.print(\"Enter the no of cars\"+employeeName +\"sold this year :\");
carsSold = scan.nextInt();
if (carsSold <= 0) {
System.out.println(\"That\'s clearly invalid.\");
System.out.println(\"ReEnter the no of cars sold :\");
carsSold=scan.nextInt();
}
//Get the number of cars sold by the employee
//Input validation for number of cars sold
// Compute the raise using conditional operator
if (carsSold > 100) {
newSalary = currentSalary + (currentSalary * 6) / 100;
} else {
newSalary = currentSalary + (currentSalary * 1.5) / 100;
}
raise = newSalary - currentSalary;
// Compute the new salary
String currsal = String.format(\"%.2f\", currentSalary);// Print the results
String raisee = String.format(\"%.2f\", raise);
String newsal = String.format(\"%.2f\", newSalary);
System.out.println(\"Current Salary \"+currsal);
System.out.println(\"Amount of raise \"+raisee);
System.out.println(\"New Salary :\"+newsal);
//Run the program again?
scan.skip(\"\ \"); //Skips newline character
System.out.println(\"Process next employee salary and raise? Enter yes or no:\");
response = scan.next();
} while (response.equalsIgnoreCase(\"Yes\")); //end do while
}
}
output
run:
Enter the employee name :joecool
Enter the current salary :6000
Salary cannot be less than $10000.Reenter the current salary :10000
Enter the no of carsjoecoolsold this year :60000
Current Salary 10000.00
Amount of raise 600.00
New Salary :10600.00
Process next employee salary and raise? Enter yes or no:
yes
Enter the employee name :bobbyknox
Enter the current salary :50000
Enter the no of carsbobbyknoxsold this year :-12
That\'s clearly invalid.
ReEnter the no of cars sold :
12
Current Salary 50000.00
Amount of raise 750.00
New Salary :50750.00
Process next employee salary and raise? Enter yes or no:
no



