Please create the code in Java. The instructions to create the code are as follows: 1) You will be entering input from t
Posted: Fri Jul 08, 2022 6:43 am
Please create the code in Java. The instructions to create thecode are as follows:
1) You will be entering input from the keyboard so you mustimport the Scanner class into your program. The following arevariables and constants that you will need to declare in yourprogram (within the main() method): "firstName" and "lastName" willbe strings, "yearlySalary" and "monthlySalary" will be doubles,"exitLoop" will be a boolean and initialized to the value falseselection will be an integer.
The following three will be constants of type double. They mustbe assigned their respective values as shown. "MAX_SALARY" withvalue 120000.00, "MIN_SALARY" with value 12000.00,"MIDDLE_SALARY" with value 50000.00.
Instantiate an object from the Scanner class for reading in fromthe keyboard.
2) You will need the following information from the user: firstname, last name, and their yearly salary. Write the code to dothis. However, for the yearly salary make sure that the user entersa valid value. A valid value for the yearly salary is any valuebetween "MIN_SALARY" and "MAX_SALARY", inclusive on both ends. Youmust use a do-while loop to check the validity of the yearly salaryand use the variable "exitLoop" as the condition. If the userenters an invalid value, print out the following message:
"Error! Invalid salary, must be between $12,000.00 and$120,000.00 Re-enter yearly salary:"
Repeat this process until the user does enter a valid value forwhich you must exit the do-while loop.
3) At this point you should reinitialize your variable exitLoopas it will be used as a condition inside a while loop to do thefollowing. Print out a menu for the user to select differentoperations.
For example, if the user's name was Sally Jones, the menu shouldlook like the following:
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection:
You are to then read in what the user's response is and assignit to the variable selection. At this point if you wish, you mayprint out what the user has entered (what their selection was).Doing this is not really part of the program but if you just wantto convince yourself that program is working correctly up to thispoint it is recommended.
4) Now that you have part 3) done correctly, your program shouldnow react to the operation that the user wants. However, it ispossible that user has entered an invalid value for the operation(i.e., they entered a number such as 23). This is an invalid entryand you should print out the following message: "Error! Invalidentry. Please try again!"
(Will get back to where this should be done shortly). Of course,you still need to have code to react upon the correct operationthat user has chosen. For this, you need to insert a switchstatement within your while loop that you made in step 3) above. Ascan be seen from the menu that your program prints out, there arefive possible choices (Raise, Demote, Promote, Monthly Salary, andExit). Here is what you need to do for each:
Raise - the user will get a raise of 5% so make sure that youincrease the user's yearly salary by that much. Print out theuser's first name, last name, and new yearly salary and state thatthey got a raise (example shown below in expected output)
Demote - the user has been demoted. Here is how much you mustdecrease their salary: if the user's current yearly salary isstrictly greater than the value of MIDDLE_SALARY, then subtract5000.00 dollars from their current yearly salary. Otherwise,subtract 3000.00 dollars from their current yearly salary.Print out the user's first name, last name, and new yearly salaryand state that they got demoted (example shown below in expectedoutput)
Promote - the user has been promoted. The user's yearly salarywill be doubled since they got promoted. Print out the user's firstname, last name, and new yearly salary and state that they gotpromoted (example shown below in expected output)
Monthly Salary - the user's monthly salary will be calculatedand this value will be assigned to the variable monthlySalary.Print out the user's first name, last name, and monthly salary andstate that this is their monthly salary (example shown below inexpected output)
Exit - user is finished so you must exit the while loop(remember the variable exitLoop?)
Now we get back to what to do if the user enters an invalidvalue. Set up a default in your switch statement to catch this andhave it print out the error message: Error! Invalid entry. Pleasetry again!
Remember that all of step 4) is within your while loop that youdid in step 3)
5) The very last thing that should appear in your output shouldbe the following two lines (assume for example that your name isSally Jones): "This program was written by Sally Jones. End ofprogram."
EXPECTED OUTPUT:
Enter first name: Sally
Enter last name: Jones
Enter yearly salary: 110000.50
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection: 1
Sally Jones got a raise! New salary: $115,500.53
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection: 2
Sally Jones has been demoted! New salary: $110,500.53
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection: 3
Sally Jones got promoted and works at the administration level!New salary: $221,001.05
....and forth with all the options.
Again, please ensure that all the instructions are followed andthat the output is matched to the example given above. Thankyou!
1) You will be entering input from the keyboard so you mustimport the Scanner class into your program. The following arevariables and constants that you will need to declare in yourprogram (within the main() method): "firstName" and "lastName" willbe strings, "yearlySalary" and "monthlySalary" will be doubles,"exitLoop" will be a boolean and initialized to the value falseselection will be an integer.
The following three will be constants of type double. They mustbe assigned their respective values as shown. "MAX_SALARY" withvalue 120000.00, "MIN_SALARY" with value 12000.00,"MIDDLE_SALARY" with value 50000.00.
Instantiate an object from the Scanner class for reading in fromthe keyboard.
2) You will need the following information from the user: firstname, last name, and their yearly salary. Write the code to dothis. However, for the yearly salary make sure that the user entersa valid value. A valid value for the yearly salary is any valuebetween "MIN_SALARY" and "MAX_SALARY", inclusive on both ends. Youmust use a do-while loop to check the validity of the yearly salaryand use the variable "exitLoop" as the condition. If the userenters an invalid value, print out the following message:
"Error! Invalid salary, must be between $12,000.00 and$120,000.00 Re-enter yearly salary:"
Repeat this process until the user does enter a valid value forwhich you must exit the do-while loop.
3) At this point you should reinitialize your variable exitLoopas it will be used as a condition inside a while loop to do thefollowing. Print out a menu for the user to select differentoperations.
For example, if the user's name was Sally Jones, the menu shouldlook like the following:
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection:
You are to then read in what the user's response is and assignit to the variable selection. At this point if you wish, you mayprint out what the user has entered (what their selection was).Doing this is not really part of the program but if you just wantto convince yourself that program is working correctly up to thispoint it is recommended.
4) Now that you have part 3) done correctly, your program shouldnow react to the operation that the user wants. However, it ispossible that user has entered an invalid value for the operation(i.e., they entered a number such as 23). This is an invalid entryand you should print out the following message: "Error! Invalidentry. Please try again!"
(Will get back to where this should be done shortly). Of course,you still need to have code to react upon the correct operationthat user has chosen. For this, you need to insert a switchstatement within your while loop that you made in step 3) above. Ascan be seen from the menu that your program prints out, there arefive possible choices (Raise, Demote, Promote, Monthly Salary, andExit). Here is what you need to do for each:
Raise - the user will get a raise of 5% so make sure that youincrease the user's yearly salary by that much. Print out theuser's first name, last name, and new yearly salary and state thatthey got a raise (example shown below in expected output)
Demote - the user has been demoted. Here is how much you mustdecrease their salary: if the user's current yearly salary isstrictly greater than the value of MIDDLE_SALARY, then subtract5000.00 dollars from their current yearly salary. Otherwise,subtract 3000.00 dollars from their current yearly salary.Print out the user's first name, last name, and new yearly salaryand state that they got demoted (example shown below in expectedoutput)
Promote - the user has been promoted. The user's yearly salarywill be doubled since they got promoted. Print out the user's firstname, last name, and new yearly salary and state that they gotpromoted (example shown below in expected output)
Monthly Salary - the user's monthly salary will be calculatedand this value will be assigned to the variable monthlySalary.Print out the user's first name, last name, and monthly salary andstate that this is their monthly salary (example shown below inexpected output)
Exit - user is finished so you must exit the while loop(remember the variable exitLoop?)
Now we get back to what to do if the user enters an invalidvalue. Set up a default in your switch statement to catch this andhave it print out the error message: Error! Invalid entry. Pleasetry again!
Remember that all of step 4) is within your while loop that youdid in step 3)
5) The very last thing that should appear in your output shouldbe the following two lines (assume for example that your name isSally Jones): "This program was written by Sally Jones. End ofprogram."
EXPECTED OUTPUT:
Enter first name: Sally
Enter last name: Jones
Enter yearly salary: 110000.50
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection: 1
Sally Jones got a raise! New salary: $115,500.53
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection: 2
Sally Jones has been demoted! New salary: $110,500.53
Please select an operation for Sally Jones
1 - Raise
2 - Demote
3 - Promote
4 - Monthly salary
5 - Exit
Enter selection: 3
Sally Jones got promoted and works at the administration level!New salary: $221,001.05
....and forth with all the options.
Again, please ensure that all the instructions are followed andthat the output is matched to the example given above. Thankyou!