Marc Weber, M Beck and James Carmen,
I owe you all a drink!!
A BIG drink!
I got there in the end.......
My problem was I had InvalidRecord class which extended the Exception class.
This declare the constructor InvalidRecord(String message) and InvalidRecord( ).
What I was doing wrong through was putting the method to validateDate (date) throws InvalidRecord in the InvalidRecord class.
The method validateDate (date) throws InvalidRecord was written with the business logic in the InvalidRecord class. BIG MISTAKE!
I now understand that the validateDate (date) throws InvalidRecord should actually be written in the VehicleRecord class.
So I now have my method validateDate(date) throws InvalidRecord in the VehicleRecord class.
The InvalidRecord class simply extends Exception and has two constructors.
I use a TestApp class to test whether it works. This calls the method and gets the relevant message.
Yippppeee!!! is all I can say now PLUS a big THANK YOU!
To those that have followed this
thread here is the code which I feel is now correct:
In my InvalidRecord class I have the following: (with no methods)
In my VehicleRecord class I have the following method:
In my TestApp class I have the following code:
Note: there were many other tests here but I didn't think it necessary to show them all.
[BOLD]The output was as follows:[/BOLD]
Validating Date: 1003
Date successfully validated
Date input by user: 1003
dateFrom is:= Thu Jan 01 00:00:00 GMT 1981
dateUntil is:= Tue Dec 01 00:00:00 GMT 2020
Finished!!!
Testing when format of date is NOT valid i.e. 11/2/91
===================================
Validating Date: 11/2/91
Date input by user:= 11/2/91 Not valid.
Needs to be four digits i.e. MMYY
Finished Validation
Testing when format of date is NOT valid i.e. 12th January 2001
===================================
Validating Date: 12th January 2001
Date input by user:= 12th January 2001 Not valid.
Needs to be four digits i.e. MMYY
Finished Validation
Testing when date is before 0181 i.e. 0180
==================================
Validating Date: 0180
date NOT valid. Before 0181
Finished Validation
Testing when date is after 1220 i.e. 1221
===================================
Validating Date: 1221
date NOT valid. After 1220
Finished Validation
Again, many thanks! You have made me happy!