Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to enter employee data into an array, including each employee’s

ID: 3863654 • Letter: W

Question

Write a program to enter employee data into an array, including each employee’s name, Social Security number, and salary. The maximum number of employees is 100, but your program should work with any number of employees less than 100.

Your program should have two exception classes, one called SSNLengthException which is thrown when the Social Security number entered – without the dashes or spaces – is not exactly nine characters, and the other called SSNCharacterException which is thrown when any character in the Social Security number is not a digit.

Note #1: In this program, you may use the abbreviation SSN for “Social Security Number” in both variables and class names.

Your program also should check that a valid number is entered for an employee’s salary. This would including checking for a numeric entry (NumberFormatException) and that a negative number is not entered (InvalidArgumentException). Both of the exceptions are already part of the Java language

Note #2: When an exception is thrown, the user should be reminded of what he or she entered, told why it is inappropriate, and asked to reenter the data that was rejected.

After all of the data has been entered, your program should display the records for all employees, with an annotation stating whether the employee’s salary is above or below the average.

You will need to define the classes Employee, SSNLengthException, and SSNCharacterException. Derive the class Employee from the class Person given on Blackboard along with the Homework Assignment. Every Employee object should record the empoyee’s name (recorded in Person), salary, Social Security Number, and any other data you think might be appropriate.

Here is an example of how you might enter data into your program (user input is underlined in blue):

Entering info for employee #1

Enter employee name (or Q to finish): G. Washington

Enter month name, day, year (no commas): February 22 1732

Enter 9-digit SSN: 0000000000001

Error: "11122333344" does not have 9 digits, please re-enter.

Enter 9-digit SSN: 000000001

Enter employee's salary: 90000

Entering info for employee #2

Enter employee name (or Q to finish): Oprah Winfrey

Enter month name, day, year (no commas): January 29 1954

Enter 9-digit SSN: 987654321ABC

Error: "987654321ABC" is not all numeric, please re-enter.

Enter 9-digit SSN: 987654321

Enter employee's salary: 125000

Entering info for employee #3

Enter employee name (or Q to finish): Pancho Villa

Enter month name, day, year (no commas): June 05 1878

Enter 9-digit SSN: 123456789

Enter employee's salary: 63500

Entering info for employee #4

Enter employee name (or Q to finish): Harry Potter

Enter month name, day, year (no commas): July 31 1980

Enter 9-digit SSN: 248492940

Enter employee's salary: 42,000

Error: "42,000" is not all numeric

Enter employee’s salary: -42000

Error: You cannot enter a negative salary

Enter employee’s salary: 42000

Entering info for employee #5

Enter employee name (or Q to finish): q

Here is an example of the output of your program once all employee data has been entered.

The average salary is $80,125.00  

No.   Employee-Name     SSN         Birth-date        Salary    to Avg.

--- --------------- --------- ------------------ ---------- -------

1 G. Washington   000000001 February 22, 1732    90,000.00 Over

2 Oprah Winfrey    987654321 January 29, 1954    125,000.00 Over

3 Pancho Villa     123456789 June 5, 1878         63,500.00 Under

4 Harry Potter     248492940 July 31, 1980        42,000.00 Under

Using toString():

  G. Washington, Born: February 22, 1732, SSN: 000000001, Salary: 90,000.00

  Oprah Winfrey, Born: January 29, 1954, SSN: 987654321, Salary: 125,000.00

  Pancho Villa, Born: June 5, 1878, SSN: 123456789, Salary: 63,500.00

  Harry Potter, Born: July 31, 1980, SSN: 248492940, Salary: 42,000.00

Explanation / Answer


#include<iostream>
using namespace std;
int main(){
   int count=0;
   string *ename=new string[100];
   string *month=new string[100];
   int *day=new int[100];
   int *year = new int[100];
   string *ssn= new string[100];
   float *salary = new float[100];
   int avgSalary=0;
   for(int i=0;i<100;i++){
       cout<<"Entering info for employee #"<<(i+1);
       cout<<" Enter employee name (or Q to finish): ";
       cin.get();
       string en;
       getline(cin,en);
       ename[i] = en;
       if(!(ename[i].compare("q")) || !(ename[i].compare("Q")))
           break;
       cout<<"Enter month name, day, year (no commas): ";
       cin>>month[i]>>day[i]>>year[i];
       cout<<"Enter 9-digit SSN: ";
       cin>>ssn[i];
       while(ssn[i].length()!=9){
           cout<<"Error: "<<ssn[i]<<" does not have 9 digits, please re-enter."<<endl;
           cout<<"Enter 9-digit SSN: ";
           cin>>ssn[i];
       }
       cout<<"Enter employee's salary: $";
       cin>>salary[i];
       while(salary[i]<0){
           cout<<"Error: You cannot enter a negative salary";
           cin>>salary[i];
       }
       avgSalary+=salary[i];
       count++;
   }
   avgSalary/=count;
   cout<<endl<<endl<<"The average salary is "<<avgSalary;
   cout<<endl<<"No. Employee-Name SSN Birth-date Salary to Avg.";
   cout<<endl<<"--- --------------- --------- ------------------ ---------- -------"<<endl;
   for(int i=0;i<count;i++){
       cout<<(i+1)<<". "<<ename[i]<<" "<<ssn[i]<<" "<<month[i]<<" "<<day[i]<<", "<<year[i]<<salary[i]<<" "<<(salary[i]>avgSalary?"Over":"Under")<<endl;
   }
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote