Problem Statement
A good system is to use a substitution code, in which each digit is encoded by a letter. An easy to remember 10-letter word or phrase, the key, is chosen. Every '1' in the value is replaced by the first letter of the key, every '2' is replaced by the second letter of the key, and so on. Every '0' is replaced by the last letter of the key. Letters that do not appear in the key can be inserted anywhere without affecting the value represented by the code.. This helps to make the resulting code much harder to break (without knowing the key).
Create a class SubstitutionCode that contains the method getValue that is given the
Definition
- Class:
- SubstitutionCode
- Method:
- getValue
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int getValue(String key, String code)
- (be sure your method is public)
Constraints
- code contains between 1 and 9 characters inclusive, all uppercase letters 'A'-'Z'
- code contains at least one letter that is found in key
- key contains exactly 10 uppercase letters 'A'-'Z', all distinct from each other
Examples
"TRADINGFEW"
"LGXWEV"
Returns: 709
The L,X, and V are ignored since they do not appear in the key. G is the seventh letter in the key, W is the 10th letter, and E is the 9th letter.
"ABCDEFGHIJ"
"XJ"
Returns: 0
"CRYSTALBUM"
"MMA"
Returns: 6
"ABCDEFGHIJ"
"BLKVA"
Returns: 21
"KLMNOPQRST"
"P"
Returns: 6
"ABCDEFGHIJ"
"JAJAJAJAX"
Returns: 1010101
"ABCDEFGHIJ"
"IXJYXIJAX"
Returns: 90901
"ACFHTBDEGQ"
"QGEDBTHFC"
Returns: 98765432
"ABCDEFGHIJ"
"JJJJJJJJJ"
Returns: 0
"ABCDEFGHIJ"
"XDJYXDJ"
Returns: 4040
"ABCDEFGZYX"
"YAZLDKSMN"
Returns: 9184
"FREAKYQUIP"
"ZBFEK"
Returns: 135
"PLASTERWIG"
"ASTERWIX"
Returns: 3456789
"FGHIJKLMNO"
"ABKAOAK"
Returns: 606
"ABCDEFGHIJ"
"I"
Returns: 9
"THREWAKING"
"DIJKLSIY"
Returns: 878
"CRYSTALBUM"
"MMA"
Returns: 6
"ABCDEFGHIJ"
"BCA"
Returns: 231
"ABCDEFGHIJ"
"C"
Returns: 3
"TRADINGFEW"
"LGXWEVTA"
Returns: 70913
"TRADINGFEW"
"LGXWEV"
Returns: 709
"ABCDEFGHIW"
"ABDRYHGOW"
Returns: 124870
"ABCDEFGHIJ"
"XJABJ"
Returns: 120
"ABCDEFGHIJ"
"BABA"
Returns: 2121
"CRYSTALBUM"
"MMA"
Returns: 6
"ABCDEFGHIJ"
"AAABCDEFG"
Returns: 111234567
"LRADINGFEW"
"LGXWEV"
Returns: 1709
"TRADINGFEW"
"LGXWEVFAF"
Returns: 709838