Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CLASS zcl_scrabble_score DEFINITION PUBLIC .
- PUBLIC SECTION.
- METHODS score
- IMPORTING
- input TYPE string OPTIONAL
- RETURNING
- VALUE(result) TYPE i.
- METHODS letter_score
- IMPORTING
- input TYPE c
- RETURNING
- VALUE(result) TYPE i.
- PROTECTED SECTION.
- PRIVATE SECTION.
- ENDCLASS.
- CLASS zcl_scrabble_score IMPLEMENTATION.
- METHOD score.
- " add solution here
- DATA(i) = strlen( input ).
- WHILE i >= 0.
- result += letter_score( input+i(1) ).
- i -= 1.
- ENDWHILE.
- ENDMETHOD.
- METHOD letter_score.
- DATA(input_upper) = to_upper( input ).
- result = COND #(
- WHEN input_upper CA 'AEIOULNRST' THEN 1
- WHEN input_upper CA 'DG' THEN 2
- WHEN input_upper CA 'BCMP' THEN 3
- WHEN input_upper CA 'FHVWY' THEN 4
- WHEN input_upper CA 'K' THEN 5
- WHEN input_upper CA 'JX' THEN 8
- WHEN input_upper CA 'QZ' THEN 10
- ELSE 0 ).
- ENDMETHOD.
- ENDCLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement