Advertisement
Guest User

Updated code

a guest
Feb 21st, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. import javax.swing.JOptionPane; //imports the joptionpane
  2.  
  3. public class Testing {
  4. public static void main (String [] args) {
  5.  
  6. int bonus = 100; //assigns the bonus to be 100 ($100)
  7.  
  8.  
  9. String employee = JOptionPane.showInputDialog("Employee name:"); //runs a dialog box to collect string data for the employee's name
  10. int years = Integer.parseInt(JOptionPane.showInputDialog(employee + "'s years of service:")); //runs a dialog box to collect integer data for the years of service
  11. String rating = JOptionPane.showInputDialog(employee + "'s Rating:"); //runs a dialog box to collect string data for the employees performance rating
  12.  
  13. if (rating.equalsIgnoreCase("Below average")) //if the rating string variable is equal to Below average, run this block of code.
  14. {
  15. JOptionPane.showMessageDialog(null, employee + "is NOT eligble for a bonus on account of their " + rating + " performance despite their " + years + " years of service."); //if the rating entered is equal to below average message box will provided stating that the employee is ineligble
  16. return;
  17. }
  18. else if (rating.equalsIgnoreCase("Average"))
  19. {
  20. }
  21. else if (rating.equalsIgnoreCase("Above average")) //proceed if only one of the options for text entry have been inputted
  22. {
  23. }
  24. else if (rating.equalsIgnoreCase("Outstanding"))
  25. {
  26. }
  27. else
  28. {
  29. JOptionPane.showMessageDialog(null, "ERROR - Please start again. Please pick between below average, average, above average and outstanding."); //error message to appear if any string entered into the dialog box doesnt match one of the above options
  30. return;
  31. }
  32.  
  33. if (years < 1) //run this block of code if the years are less than 1
  34. {
  35. JOptionPane.showMessageDialog(null, "This is not a valid input."); //provides error message if the years are less than 0
  36. return;
  37. }
  38. else if (years < 2) //run this code if the years of service are less than 2
  39. {
  40. JOptionPane.showMessageDialog(null, employee + " is NOT eligible for a bonus on account of their " + years + " years of service."); //provides a message detailing ineligbility when the user has less than 2 years of service
  41. return;
  42. }
  43.  
  44.  
  45.  
  46. if (years >= 20) //run this block of code if the years of service are equal to or greater than 2 years
  47. {
  48. int final_bonus = (years * bonus); //calculating the bonus by multiplying the years by the bonus variable assigned at the top of the code
  49. JOptionPane.showMessageDialog(null, "Success! " + employee + " is eligible for a bonus of $" + final_bonus * 2 + " on account of their " + years + " years of service and their " + rating + " performance rating."); //provides a dialog box combining strings and variables to provide a complete bonus total
  50. }
  51. else if (years >= 2) //run this block of code if the years of service are equal to or greater than 20 years
  52. {
  53. int final_bonus = (bonus * years); //calculating the bonus by multiplying the bonus and the years together and then multiplying that by 2
  54. JOptionPane.showMessageDialog(null, "Success! " + employee + " is eligible for a bonus of $" + final_bonus + " on account of their " + years + " years of service and their " + rating + " performance rating."); //provides a dialog box combining strings and variables to provide a complete bonus total
  55. return;
  56. }
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement