Create an exception class called ssnformatexception

Assignment Help Computer Engineering
Reference no: EM132083607

Note: Please ensure that the social security numbers use the following digit pattern for the first output line which is 000-00-000. Basicaly three digits, two digits and three digits again.

Introduction:

In this lab, you will be creating your own exception class. You will also create a class that will use the exception class in its constructor and set methods and a driver program that will demonstrate how the exception can be handled. Note: In this lab, you will be creating all classes from scratch so there are no files template files

Note: Please ensure that the social security numbers use the following digit pattern for the first output line which is 000-00-000. Basicaly three digits, two digits and three digits again.

Problem 1.

Create an exception class called SSNFormatException that extends Exception. Include four constructors for the class as described in your book. One with no arguments, one with a String argument, one with a String and a Throwable argument and one with a Throwable argument. The latter two could be used for chaining exceptions. All the constructors should be calling the respective super class constructor giving at least a String argument to it.

Problem 2.

Create a new class called Employee. The class should contain 3 instance variables,firstName,lastNameandsocialSecurityNumber of type String. It should have at least a no argument and a three argument constructor and respective set and get methods for the three instance variables.

The 3 argument constructor and the setSocialSecurityNumber method should validate that the Social Security Number provided as a String parameter is well formed and throw a SSNFormatException if it is not. According to good programming practices, the constructor and the setSocialSecurityNumber method should call a static method called testSSN that takes a String as argument and throws a SSNFormatException if the String is not well formed.

The static testSSN method checks for the following errors:

Number of characters not equal to 11. (Just check the length of the

string).

Dashes in the wrong spots.

Any non-digits exist in the non-dash spots of the SSN.

[Hint:] Use a loop to step through each character of the string, checking for a digit or hyphen in the appropriate spots.

Problem 3.

Create a test application that demonstrates the use of your class and its methods. In particular the main method of your test app, should contain a try-catch statement. This statement tries to create a new employee using a firstName, lastName and SSN provided by the user. If the social security number is invalid a SSNFormatException will be thrown from the constructor.

It should catch it and print out the name and social security number entered, and an associated error message indicating why the social security number is invalid. In order to be able to understand why the SSN is invalid, this message should be retrieved from the SSNFormatException.

As a result it should be the testSSN method that produces messages that describe what kind of format error is encountered in the SSN, and provides these messages to the constructor of the SSNFormatException as it throws the exception. A loop should be used to allow the user to continue inserting employees until the user indicates that they do not want to continue.

Sample output.

Insert Employee First Name: Sam Insert Employee Last Name: Sly Insert Employee SSN: 333-00-999 Invalid the social security number, wrong number of characters Continue? y Insert Employee First Name: George
Insert Employee Last Name: Washington

Insert Employee SSN: 123-45-6789 Employee created successfully. Continue? y Insert Employee First Name: Jane Insert Employee Last Name: Doe Insert Employee SSN: 222-00-999o Invalid the social security number, contains a character that is not a digit Continue? y Insert Employee First Name: Harry Insert Employee Last Name: Potter Insert Employee SSN: 333-333-333 Invalid the social security number, dashes at wrong positions Continue?

Reference no: EM132083607

Questions Cloud

Victims of a mass homicide possible : Is a typology of the victims of a mass homicide possible? Can it help inform policies?
What is the power elite model : What is the Power Elite Model and do you believe that the American political institutions are controlled by the rich and powerfu.
Calculate the net cost per unit : Calculate the net cost per unit and compare your answer to the amount listed by the program when the inventory data is entered
How does automation that allows customers : How does automation that allows customers to do their own work impact the job market?
Create an exception class called ssnformatexception : Create an exception class called SSNFormatException that extends Exception. Include four constructors for the class as described in your book.
Importance of dr solomon asch''s experiment : Explain the importance of Dr.Solomon Asch's experiment on peer pressure. Explain how you have dealt with peer pressure in your life?
Is joe paterno a perpetrator or a victim : Is Joe Paterno a perpetrator or a victim? What types of victimization occurred at Penn State, and what is the relevance to the US society?
Distinguish the most important users for this product : Distinguish the most important users for this product from those who are less important to satisfy.
What are the expected receipts from accounts receivable : The company's accounts receivable payment history is as follows: 30% in the month of sale, What are the expected receipts from accounts receivable

Reviews

Write a Review

Computer Engineering Questions & Answers

  Create a message displayer that has one combobox object

Create a Message Displayer that has one ComboBox object with a list of at least four of your favorite sayings.

  What are the ramifications if test fails or is not performed

What tools are used to perform the test? Who are the stakeholders for the test? What are the ramifications if this test fails or is not performed?

  What are the major issues with wi-fi in homes

What are the main differences between Wi-Fi, Wireless and 3G? What are their advantages and disadvantages. What are the main issues with Wi-Fi in homes?

  How many are decision-support systems

How many are decision-support systems? How many are strategic planning systems? Are there any other useful categories of systems?

  Generating the printstream object

Generate a PrintStream object utilizing the dos and allocate the resulting reference to ps, a PrintStream variable which has already been declared.

  What are some of the disadvantages of cloud computing

What are some of the disadvantages of cloud computing. For your discussion, think of a process at work or in your personal experience that required some type of hardware and/or software needing to be purchased, stored and maintained at the current ..

  Why a flow from a higher to a lower numbered bubble

Explain why a flow from a higher- to a lower-numbered bubble on a logical DFD is a physical manifestation of the system. Give an example.

  Analyze the circuit for its operation as an sr flip-flop

Replace the NOR gates in Figure with NAND gates and analyze the circuit for its operation as an SR flip-flop.

  Create a generic function that outputs one line of countdown

Create a generic function that outputs one line of the countdown as an alert, and receives the data to output as an input parameter. Use that function to output each line of the countdown.

  Identify the cost drivers that affect the development time

Estimate the cost in labor months of developing a complete software system that will be used by mechanical engineers to model thermal effects on engine parts. The program replaces an older version.

  Design a function that uses nested for loops to rotate image

Transformations are most common operations in image-processing software. Design a function that uses nested for loops to rotate an image 90 degrees clockwise.

  Make the get/set methods for each of your variables

select a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd