Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- A class to calculate employee payroll using the
- Company interface and the Salaried and Hourly classes.
- @auth Dave Lastname
- @date 11/14/13
- */
- import java.util.*;
- public class Payroll
- {
- public static void main(String args[])
- {
- Scanner scan = new Scanner(System.in);
- int numEmps = 0;
- ArrayList<Company> employees = new ArrayList<Company>();
- boolean go = true;
- while(go == true)
- {
- System.out.println("What do you want to do?");
- System.out.println(" 1. Create a new employee");
- System.out.println(" 2. Set pay");
- System.out.println(" 3. Show weekly pay");
- System.out.println(" 4. Show annual pay");
- System.out.println(" 5. Show summary");
- System.out.println(" 6. Quit");
- int num = scan.nextInt();
- if(num > 6 || num < 0)
- {
- System.out.println("ERROR: Bad option, please try again.");
- }
- if(num == 1)
- {
- System.out.println("What type of employee would you like to create (Salaried or Hourly)?");
- String typeInput = scan.next();
- while(!(typeInput.equalsIgnoreCase("salaried") || typeInput.equalsIgnoreCase("hourly")))
- {
- System.out.printf("Please enter either 'salaried' or 'hourly'");
- typeInput = scan.next();
- }
- if(typeInput.equalsIgnoreCase("hourly"))
- {
- System.out.printf("Please enter the name: \n");
- String name = scan.next();
- System.out.printf("Please enter the social security number: \n");
- String SSN = scan.next();
- System.out.printf("Please enter the rate of hourly pay: \n");
- double pay = scan.nextDouble();
- while(pay <= 0)
- {
- System.out.println("Please enter a number > 0");
- pay = scan.nextDouble();
- }
- System.out.printf("Please enter the average number of hours worked per week: \n");
- double avgHours = scan.nextDouble();
- while(avgHours <= 0)
- {
- System.out.println("Please enter a number > 0");
- avgHours = scan.nextDouble();
- }
- Hourly hourlyEmp = new Hourly(name, SSN, avgHours);
- hourlyEmp.setPay(pay);
- employees.add(hourlyEmp);
- numEmps++;
- System.out.printf("Employee " + numEmps + " has been created. \n");
- }
- else if(typeInput.equalsIgnoreCase("salaried"))
- {
- System.out.printf("Please enter the name: \n");
- String name = scan.next();
- System.out.printf("Please enter the social security number: \n");
- String SSN = scan.next();
- System.out.printf("Please enter the annual pay: \n");
- double pay = scan.nextDouble();
- while(pay <= 0)
- {
- System.out.println("Please enter a number > 0");
- pay = scan.nextDouble();
- }
- Salaried salariedEmp = new Salaried(name, SSN);
- salariedEmp.setPay(pay);
- employees.add(salariedEmp);
- numEmps++;
- System.out.printf("Employee " + numEmps + " has been created. \n");
- }
- }//end of case 1
- else if(num == 2)
- {
- Company emp;
- if(numEmps >= 2)
- {
- System.out.println("Which employee do you wish to use (enter 1 to " + numEmps + ")?");
- int empNum = scan.nextInt();
- while(!(empNum > 0 && empNum < numEmps))
- {
- System.out.println("ERROR: Please enter number between 1 and " + numEmps + ".");
- empNum = scan.nextInt();
- }
- emp = employees.get(empNum - 1);
- }
- else
- {
- emp = employees.get(0);
- }
- System.out.printf("How much would you like to set the annual pay to? \n");
- int pay = scan.nextInt();
- while(pay <= 0)
- {
- System.out.println("Please enter an amount > 0");
- pay = scan.nextInt();
- }
- emp.setPay(pay);
- }//end of case 2
- else if(num == 3)
- {
- Company emp1;
- if(numEmps >= 2)
- {
- System.out.println("Which employee do you wish to use (enter 1 to " + numEmps + ")?");
- int empNum1 = scan.nextInt();
- while(!(empNum1 > 0 && empNum1 < numEmps))
- {
- System.out.println("ERROR: Please enter number between 1 and " + numEmps + ".");
- empNum1 = scan.nextInt();
- }
- emp1 = employees.get(empNum1 - 1);
- }
- else
- {
- emp1 = employees.get(0);
- }
- System.out.printf("The weekly pay is $ %.2f", emp1.calcWeeklyPay());
- System.out.println(" ");
- }//end of case 3
- else if(num == 4)
- {
- Company emp2;
- if(numEmps >= 2)
- {
- System.out.println("Which employee do you wish to use (enter 1 to " + numEmps + ")?");
- int empNum2 = scan.nextInt();
- while(!(empNum2 > 0 && empNum2 < numEmps))
- {
- System.out.println("ERROR: Please enter number between 1 and " + numEmps + ".");
- empNum2 = scan.nextInt();
- }
- emp2 = employees.get(empNum2 - 1);
- }
- else
- {
- emp2 = employees.get(0);
- }
- System.out.printf("The weekly pay is $ %.2f", emp2.calcAnnualPay());
- System.out.println(" ");
- }//end of case 4
- else if(num == 5)
- {
- Company emp3;
- if(numEmps >= 2)
- {
- System.out.println("Which employee do you wish to use (enter 1 to " + numEmps + ")?");
- int empNum3 = scan.nextInt();
- while(!(empNum3 > 0 && empNum3 < numEmps))
- {
- System.out.println("ERROR: Please enter number between 1 and " + numEmps + ".");
- empNum3 = scan.nextInt();
- }
- emp3 = employees.get(empNum3 - 1);
- }
- else
- {
- emp3 = employees.get(0);
- }
- System.out.print(emp3);
- System.out.println(" ");
- }//end of case 5
- else if(num == 6)
- {
- go = false;
- }//end of case 6
- }//end of while loop GO
- }//end of main
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment