You would need to code your setDetails method along the lines of the followig:
Code: Select all
setDetails(
pFirstName : String ;
pLastName : String
) : Boolean ;
begin
if pFirstName.containsSpecialCharacters or
pLastName.containsSpecialCharacters then
// Invalid first or last name, so bail now
return false ;
endif;
// The names validate ok, so set the properties and return true to indicate success
self.firstName := pFirstName ;
self.lastName := pLastName ;
return true ;
end;
Obviously you then need to create the String::containsSpecialCharacters primitive method to return true/false dependent on whether or not that string contains any of what you consider to be special characters. Given that this is for a programming assignment, I won't write example code for that method. You should, however, review the RootSchema supplied methods on the String primitive as there are existing methods that could help achieve the desired result. In particular, the String::scan**** methods could prove useful in writing an efficient String::containsSpecialCharacters method to suit your requirements.
Cheers,
BeeJay.