Assignment I
Assignment I
Exercise I
The usual definition of a palindrome is a word that reads the same both for ward and backward,
like “otto” and “palindromeemordnilap.” An alternative way to define a property like this is to
specify a way of testing for the property. For example, we might say, “a single letter is a
palindrome, and a two-letter word is a palindrome if the letters are the same, and an y other word
is a palindrome if the first letter is the same as the last and the middle is a palindrome.” Write a
recursive method named isPalindrome that takes a String and that returns a boolean indicating
whether the word is a palindrome or not.
Exercise II
A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For
example, the following are all 6-letter En glish abecedarian words. abd est,acknow, acorsy,
adempt, adipsy, agnosy, befist, behint, beknow, bijoux, biopsy, cestuy,chintz, deflux, dehors,
dehort, deinos, diluvy, dimpsy .
a) Describe an algo rithm for checking whether a given word (String) is abecedarian, assuming
that the word contains only lower-case letters. Yo ur algorithm can be iterative or recursive.
b) Implement your algorithm in a method called isAbecedarian .
Exercise III
The Captain Crunch decoder ring works by taking each letter in a string and adding 13 to it. For
example, ’a’ becomes ’n’ and ’b’ becomes ’o’. The letters “wrap around” at the end, so ’z’
becomes ’m’. Write a method that takes a String and that returns a new String containing the
encoded version. You should assume that the String contains upper and lower case letters, and
spaces, but no other punctuation. Lower case letters should be transformed into other lower case
letters; upper into upper.
You should not encode the spaces.
Exercise IV
A dupledrome is a word that contains only double letters, like “llaammaa” or “ssaabb ”. I
conjecture that there is no dupledromes in common English use. To test that conjecture, I would
like a program that reads words from the dictionary one at a time and checks them for
dupledromity. Write a method called isDupledrome that takes a Strin g and returns a boolean
indicating whether the word is a dupledrome.
Exercise Exercise
I IV
II III
III II
IV I
I IV
II III
III II
IV I
I IV
II III
III IV
IV III
I II
II I
III