Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program to enter employee data into an array, including each employees name, Social Security number, and salary. The maximum number of employees is

Write a program to enter employee data into an array, including each employees 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 employees 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 employees 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 empoyees 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 employees salary: -42000

Error: You cannot enter a negative salary

Enter employees 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Explain how new technologies are influencing training.

Answered: 1 week ago