Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane; //imports the joptionpane
- public class Testing {
- public static void main (String [] args) {
- int bonus = 100; //assigns the bonus to be 100 ($100)
- String employee = JOptionPane.showInputDialog("Employee name:"); //runs a dialog box to collect string data for the employee's name
- int years = Integer.parseInt(JOptionPane.showInputDialog(employee + "'s years of service:")); //runs a dialog box to collect integer data for the years of service
- String rating = JOptionPane.showInputDialog(employee + "'s Rating:"); //runs a dialog box to collect string data for the employees performance rating
- if (rating.equalsIgnoreCase("Below average")) //if the rating string variable is equal to Below average, run this block of code.
- {
- 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
- return;
- }
- else if (rating.equalsIgnoreCase("Average"))
- {
- }
- else if (rating.equalsIgnoreCase("Above average")) //proceed if only one of the options for text entry have been inputted
- {
- }
- else if (rating.equalsIgnoreCase("Outstanding"))
- {
- }
- else
- {
- 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
- return;
- }
- if (years < 1) //run this block of code if the years are less than 1
- {
- JOptionPane.showMessageDialog(null, "This is not a valid input."); //provides error message if the years are less than 0
- return;
- }
- else if (years < 2) //run this code if the years of service are less than 2
- {
- 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
- return;
- }
- if (years >= 20) //run this block of code if the years of service are equal to or greater than 2 years
- {
- int final_bonus = (years * bonus); //calculating the bonus by multiplying the years by the bonus variable assigned at the top of the code
- 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
- }
- else if (years >= 2) //run this block of code if the years of service are equal to or greater than 20 years
- {
- int final_bonus = (bonus * years); //calculating the bonus by multiplying the bonus and the years together and then multiplying that by 2
- 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
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement