Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

this programm is a execption handling method example problem. this is a pretty begginer calss so we havent discussed any major tops we are using

this programm is a execption handling method example problem. this is a pretty begginer calss so we havent discussed any major tops we are using abstract methods and execption hadling to deal with this problem. I put this Question up already but the code was far to complex for the level i am at tright now and was hard to understand.. will include an example of a person Class as reference to how much we have used.

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

then output in a table using print f

listings of your Employee, SSNLengthException, and SSNCharacterException classes, along with the class that contains main().

EXAMPLE OF CODE FROM DIFFERENT PROJECT

public class Person { private String name ; private Date born ; private Date died ; //null indicates still alive. // Full constructor public Person(String initialName, Date birthDate, Date deathDate) { if (consistent(birthDate, deathDate)) { name = initialName ; born = new Date(birthDate) ; if (deathDate == null) died = null ; else died = new Date(deathDate) ; } else { System.out.println("Inconsistent dates. Aborting.") ; System.exit(0) ; } } // Copy constructor public Person(Person original) { if (original == null) { System.out.println("Fatal error.") ; System.exit(0) ; } name = original.name ; born = new Date(original.born) ; if (original.died == null) died = null ; else died = new Date(original.died) ; } // Setter for all instance variables of this Person public void set(String newName, Date birthDate, Date deathDate) { if (consistent(birthDate, deathDate)) { name = newName ; born = new Date(birthDate) ; if (deathDate == null) died = null ; else died = new Date(deathDate) ; } else { System.out.println("Inconsistent dates. Aborting.") ; System.exit(0) ; } } public String toString( ) { if (died == null) { return (name + ", Born: " + born) ; } return (name + ", Born: " + born + "-" + died) ; } public boolean equals(Object anObject) { if (anObject == null || getClass() != anObject.getClass()) { return false ; } Person otherPerson = (Person) anObject ; return (name.equals(otherPerson.name) && born.equals(otherPerson.born) && datesMatch(died, otherPerson.died) ) ; } // To match date1 and date2, they must either be the same date or both be null. private static boolean datesMatch(Date date1, Date date2) { if (date1 == null) return (date2 == null) ; else if (date2 == null) //&& date1 != null return false ; else // both dates are not null. return(date1.equals(date2)) ; } /** Precondition: newDate is a consistent date of birth. Postcondition: Date of birth of the calling object is newDate. */ public void setBirthDate(Date newDate) { if (consistent(newDate, died)) born = new Date(newDate) ; else { System.out.println("Inconsistent dates. Aborting.") ; System.exit(0) ; } } /** Precondition: newDate is a consistent date of death. Postcondition: Date of death of the calling object is newDate. */ public void setDeathDate(Date newDate) { if (!consistent(born, newDate)) { System.out.println("Inconsistent dates. Aborting.") ; System.exit(0) ; } if (newDate == null) died = null ; else died = new Date(newDate) ; } public void setName(String newName) { name = newName ; } /** Precondition: The date of birth has been set, and changing the year part of the date of birth will give a consistent date of birth. Postcondition: The year of birth is (changed to) newYear. */ public void setBirthYear(int newYear) { if (born == null) { //Precondition is violated System.out.println("Fata ; Error. Aborting.") ; System.exit(0) ; } born.setYear(newYear) ; if (!consistent(born, died)) { System.out.println("Inconsistent dates. Aborting.") ; System.exit(0) ; } } /** Precondition: The date of death has been set, and changing the year part of the date of death will give a consistent date of death. Postcondition: The year of death is (changed to) newYear. */ public void setDeathYear(int newYear) { if (died == null) { //Precondition is violated System.out.println("Fata ; Error. Aborting.") ; System.exit(0) ; } died.setYear(newYear) ; if (!consistent(born, died)) { System.out.println("Inconsistent dates. Aborting.") ; System.exit(0) ; } } public String getName() { return name ; } public Date getBirthDate( ) { return new Date(born) ; } public Date getDeathDate( ) { if (died == null) return null ; else return new Date(died) ; } /** To be consistent, birthDate must not be null. If there is no date of death (deathDate == null), that is consistent with any birthDate. Otherwise, the birthDate must come before or be equal to the deathDate. */ private static boolean consistent(Date birthDate, Date deathDate) { if (birthDate == null) return false ; else if (deathDate == null) return true ; else return (birthDate.precedes(deathDate) || birthDate.equals(deathDate )) ; } } 

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_2

Step: 3

blur-text-image_3

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students explore these related Databases questions