Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A hotel validates each booking before it is added. The checks are made in this order, and a booking stops at the first check it fails.
BookingRef is H followed by four digits.GuestName is not empty.Nights is from to .These bookings are typed in (reference, name, nights): (H2041, Diaz, 2), (H2042, empty, 3), (H204, Kato, 1), (H2044, Moyo, 9), (H2045, Berg, 4), (X2046, Hale, 2), (H2047, Nkosi, 0), (H2048, Ivanova, 6).
How many bookings are added? How many are rejected by each check?
Validation is an automatic check that data is sensible before it is stored: a range check, a length check, a type check, a presence check, a format check or a check digit. A field can need several checks. Validation cannot prove that a sensible value is the true one.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Take each booking in turn and apply the checks in order. A booking that fails is counted once, at the first check it fails.
Step 1. The format check. H204 has only three digits, and X2046 starts with X. So bookings fail here.
Step 2. The presence check. Of the rest, only H2042 has no name: booking.
Step 3. The range check. Of the rest, H2044 has nights and H2047 has nights. Both are outside to : bookings.
Step 4. The bookings added. H2041, H2045 and H2048 pass all three checks: bookings.
Check. , the number of bookings typed in.
Watch out. nights is outside the range, even though looks harmless. A range check has a lowest value too.
Answer: bookings are added. The format check rejects , the presence check and the range check .
Log in to join the discussion.
Loading…