Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. A cryptogram is a message that is encoded by replacing each letter in a message by another. In the original message, all occurrences of a single letter are all replaced by the same new letter in the encoded message. Additionally, there is a one-to-one mapping between letters in the original message and letters in the encoded message. This means that no two different letters in the original message are replaced with the same letter.
  2.  
  3. You are going to write a program that allows the user to type in an encoded cryptogram message. The user will then be able to try to decode the message by replacing letters one at a time in the message until the message is completely decoded. In this program, you will need one class named Cryptogram that will use Vectors to store the messages. You will also provide a MissingLetterException class and a InvalidInputException class for input errors.
  4.  
  5. SETUP
  6.  
  7. Use two Vectors of Character objects to store the characters of the encoded message and the decoded message respectively. The encoded message will NOT be read in from the keyboard. You are to store the encoded message directly in the program as a "constant" (this is done to simplify grading). You can do this by defining a String object that is initialized to the encoded message. Then add each character of the message into a Vector. Set up the second Vector so that it is an exact copy of the encoded message, except that each letter is replaced with an asterisk (*). For example, here is the encoded message you will be using:
  8.  
  9. Encoded Message: X AQC'M YCQO OKJM BQG OJCM DGM X SJC'M WXZP XM JCB TQVP
  10. Decoded Message: * ***'* **** **** *** **** *** * ***'* **** ** *** ****
  11.  
  12. Note that non-letters are not encoded (e.g. the quote).
  13.  
  14. INPUT & OUTPUT PROCESSING
  15.  
  16. Input will come from the keyboard in this program. The user will enter a letter from the encoded message, and then the user will enter what to change the letter to in the original message. For example, it might look like this (user input in purple):
  17.  
  18. Pick a letter from encoded message: M
  19. Replace with which letter (A-Z,*): S
  20. Encoded Message: X AQC'M YCQO OKJM BQG OJCM DGM X SJC'M WXZP XM JCB TQVP
  21. Decoded Message: * ***'S **** ***S *** ***S **S * ***'S **** *S *** ****
  22.  
  23. The user may replace a letter with an asterisk (*). For example, the next input might look like this (user input in purple):
  24.  
  25. Pick a letter from encoded message: M
  26. Replace with which letter (A-Z,*): *
  27. Encoded Message: X AQC'M YCQO OKJM BQG OJCM DGM X SJC'M WXZP XM JCB TQVP
  28. Decoded Message: * ***'* **** **** *** **** *** * ***'* **** ** *** ****
  29.  
  30. The user will continue to decode the message, one letter at a time. If the decoded message has NO ASTERISKS, you should ask the user if the message is decoded. If it is, your program should end. Otherwise, it will continue to ask for letters.
  31.  
  32. EXCEPTION PROCESSING
  33.  
  34. If the user inputs a letter not in the encoded message, you should throw a LetterMissingException. The exception handler should report the error and prompt the user for another letter until the user finally enters a letter in the encoded message. If the user inputs a character for the decoded message that is not a letter or an asterisk, you should throw a InvalidInputException. The exception handler should report the error and prompt the user for a letter or asterisk until the user finally enters one. These exceptions should NOT end the program.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement