Maureen Charlton

Ranch Hand
+ Follow
since Oct 04, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Maureen Charlton

Paul,

THANK YOU
17 years ago
Ernest
Many thanks for your response.
I'm still confused though as I expected the output to be:
"Date not valid: Needs to be ALL digits" as thrown in my caught Number FormatException in the validateDate method which throws InvalidRecord

Instead I'm getting an output of "Date Not Valid" as caught in my main method?

Thanking you in advance
17 years ago
I have a main method in the VehicleRecord class:
the date is a String containing three digits and a letter


At present the main method is catching the exception when a character i.e. a letter is put in a four digit date.

I want the method to catch the exception and can't work out why it isnt

My method catching the exception is:


I would appreciate any suggestions?

[ EJFH: Let Emacs format the code so we can see structure more easily. ]
[ January 29, 2007: Message edited by: Ernest Friedman-Hill ]
17 years ago
Many thanks all - I'll do some further reading in the API
17 years ago
Jasper Thank you for your response.

I have no error message.
My understanding is the Date class has been deprecated and replaced using the Gregorian Calandar so I'm attempting to get an understanding.

Are you implying that the SimpleDateFormat can be used for the Gregorian Calander?

Therefore I would use
Calendar c = Calendar.getInstance();
c.set(sdf);
17 years ago


In the above code please note the first line after the try block.
This uses the Date class of which I understand is depicted.
Does anyone know whether or not there is a similiar method in the Gregorian Calander?
17 years ago
Ah! Because a while loop has been used it will go through it once and use the singular bottle. The if statement should of been outside the while loop then.

Thank you!
18 years ago
I've just started introducing myself to the Head First Java book. On page 14 there is a program as follows:



In the book it states that there is a flaw in the program but I can't see where it is as the output to screen I get is (which starts from 99 but I can't copy that far up from DOS screen):

6 bottles of beer on the wall
6 bottles of beer on the wall
6 bottlesof beer.
Take one down.
Pass it around.
5 bottles of beer on the wall
5 bottles of beer on the wall
5 bottlesof beer.
Take one down.
Pass it around.
4 bottles of beer on the wall
4 bottles of beer on the wall
4 bottlesof beer.
Take one down.
Pass it around.
3 bottles of beer on the wall
3 bottles of beer on the wall
3 bottlesof beer.
Take one down.
Pass it around.
2 bottles of beer on the wall
2 bottles of beer on the wall
2 bottlesof beer.
Take one down.
Pass it around.
1 bottles of beer on the wall
1 bottle of beer on the wall
1 bottleof beer.
Take one down.
Pass it around.
No more bottles of been on the wall

C:\Java>

Can anyone highlight what the flaw is?
18 years ago
I'm trying to get my head around exceptions.

I have a test program with the following code:

The line of code: test1.store(record4); calls a method store in my VehicleDB class but I get the following error when compiling:

C:\java\PoliceDatabase>javac TestApp.java
TestApp.java:176: unreported exception InvalidRecord; must be caught or declared
to be thrown
test1.store(record4);
^
1 error

My store method contains the following code:



My understanding is the store method in my VehicleDB class is throwing, catching and declaring the exception. Is my understanding correct?

I wish my store method to handle this exception hence I don't want to put a try and catch in my test class
18 years ago
Is it possible to convert a object to an array?

I have read that you can convert an array to an object but it doesn't mention the other way round!

If this is possible could someone suggest where I start?
18 years ago
OK, I tried the following in my store method in the VehicleDB class:



Expecting to get "Only Vehicle Record object can be stored." when passing the Employee record in. i.e.

VehicleRecord test = new Employee ("1234567", "0185", "Maureen", "Charlton", "UK");
VehicleDB record32 = new VehicleDB (test);
test.display( );
try {
record32.store(test);
}//end try block
However I get:
This is a Vehicle Record object so it will be stored can be stored.

For absolutely everything.

Output to screen is:
Car Colour has an empty String value. This record will not be stored.
This is a Vehicle Record object so it will be stored can be stored.
null value not permitted for Car Colour. This record will not be stored.
Entry Set is:
[NV52SSD=NV52SSD 1003 Ford Mondeo White, QP43SSX=qp43SSX 100
3 Ford Fiesta Pink, ZZ43SSX=ZZ43SSX 0182 Ford Fiesta
Yellow]
The number of records within the collections is: 3

Finished!!!

VehicleRecord details:
======================
Registration Registration: Car Car Car
Number: Date: Make: Model: Colour:

1234567 0185 Maureen Charlton UK
This is a Vehicle Record object so it will be stored can be stored.

Am I going mad? Or am I getting so tired I should call it a day?
18 years ago
Hi, I'm back again. Sorry to trouble you.

I'm still have difficulties with outputting the error "Only Vehicle object Records can be stored".

I think maybe I'm being a little dumb and I apologise if this is the case. I don't normally have any difficulty producing errors.

My program is working fine BUT I don't want it to.....

I have used the type casting of an object successfully.

My code in my test cast is as follows:



my store method in the VehicleDB class is as follows:

//method to store the vehicle registration
public void store (VehicleRecord vr) throws InvalidRecord

Which is what we are told we are NOT to change; we have to use this.

And the result output to screen I get is:

VehicleRecord details:
======================
Registration Registration: Car Car Car
Number: Date: Make: Model: Colour:

1234567 0185 Maureen Charlton UK

Validating Registration Date: 0185
The length of the date input by user is: 4
Length of date successfully validated i.e. four digits or characters
VALIDATING YEAR
newYear is: 1985
Finished validating Registration
VALIDATING MONTH
newDate is: 01
Registration Month successfully validated
VALIDATING REGISTRATION NUMBER: 1234567
The length of the reg input by user is: 7
Length of registration: VALID i.e is 7 characters

VALIDATING FORMAT OF REGISTRATION:
First Character is NOT a letter
Invalid Registration Number Format

Working like a dream!!! Which is NOT what I wish to have.

I would like an Exception to be caught but it isn't happening. I have no errors. Not something I have a problem with normally!

Am I missing something BIG time here?
18 years ago
You are all so great!

Thank you very much for your excellent and quick responses. Much appreciated!
18 years ago
I am trying to produce the message in an Exception using try and catch.

Only Vehicle Record objects can be stored.

I thought the following code would produce this but unfortunately it doesn't. Could someone help me understand why?



The output to screen when compiling is as follows:

TestApp.java:759: store(VehicleRecord) in VehicleDB cannot be applied to (Employee)
recordTest.store(recordEmp);
^
Surely to create the message 'Only Vehicle Record objects can be stored' I need to try and store something in VehicleDB which is not a VehicleRecord, hence I tried to store an Employee
18 years ago
James,

You darling! I've spent hours trying to find a way to do this.

Thank you.
18 years ago