Learn how to incorporate exception handling into a Java program.
Download the source files for the Date Calculator application whose user interface is shown below. In Eclipse, create a project containing these files, build the application, and execute it. The goal of the application is to compute the number of days between two dates. Test the program by entering various values for Start Date and End Date. Note how fragile the application is - that is, you can easily make it crash by entering values that don't conform to the expected format. Besides crashing, you can make it produce negative values by entering an End Date that precedes the Start Date, and you can specify dates that are invalid, such as “13/32/1999” (month and day out of range). For our purposes, all these behaviors should be considered incorrect.
Your goal for this lab is to incorporate error checking, exception handling, error reporting, and error recovery into the application so that it responds “correctly” to badly-specified input. Specifically, the application must
The UML Class diagram for this application is shown below. Note that this application is structured in a pattern that separates responsibility for various functionality among three classes. That is, bullet the DateCalculatorApp class is responsible only for creating the UI and presenting information to the user (the other two classes do not present any information to the user)
The UML Sequence diagram for the “Normal Flow” for the Calculate event (i.e. the case where no input specification errors exist) is shown below. This also illustrates how the program you downloaded works, provided no errors are encountered.
The UML Sequence diagrams for the “Alternate Flows” for the Calculate event are shown below. Each of these represents a different case of how input errors occur, and how they should be handled. The program you downloaded does not behave this way yet, since it doesn't implement any error handling. It's your job in this lab to fix that.
Your assignment is as follows: In the Java files you downloaded, no error handling has been implemented. Instead, find the comments containing the word “TODO” that indicate where you need to insert code that will incorporate proper error handling. Follow the detailed instructions contained within the comments; they tell you how you should Incorporate error detection, exception handling, and exception generation into the code to trap all possible types of errors in input and correctly report them so that the program will never crash or produce erroneous results.
You should follow your instructor's instructions for your lab report.
Dr. Suri Dr. TaylorDr. Hornick
If you have any questions, consult your instructor.