Exercises
¢ Create 3 strings with names and initialization as follows:
String Name Initialized With
FirstString This is a string.
SecondString And this is another string.
¢ Print the two strings, appropriately labeled
¢ Create a third string named ConcatenatedString and initialize it with the result of concatenating the two strings. Print
ConcatenatedString, appropriately labeled.
¢ Replace each occurrence of the character i in ConcatenatedString with the character z and then print the result, appropriately labeled.
¢ Change all characters in the string named ConcatenatedString (as it currenty exists at this point) to uppercase and print the
result, appropriately labeled.
¢ Remove all occurrences of the character T in the string named ConcatenatedString (as it currently exists at this point) and print
the result, appropriately labeled.
Part a: Caesar's Shift
¢ Prompt the user to enter a sentence that states the user's name (My name is George, for example).
¢ Prompt the user to enter a character shift from 1 to 4.
¢ Print the sentence and the amount of the shift, appropriately labeled.
¢ Encrypt the sentence using Caesar's shift.
¢ Print the encrypted sentence, appropriately labeled.
¢ Recover and print the original sentence, appropriately labeled.
Part b: Vigenere's Shift
Same as above except prompt the user to enter 2 shifts (shift1 and shift2), each from 1 to 4
As the word is read, the first character is shifted by shift1, the second is shifted by shift2, the third by shift1, etc.
Part a
¢ One technique to encrypt a message is to place words created by the random selection of characters at predetermined locations in the message. The
objective would be to confuse the search for a pattern.
Ø Create and print a word consisting of 6 randomly selected upper and lower case characters (ASCII table numbers 65 through 122), appropriately labeled.
Part b
¢ Pig Latin is a form of coded language often used for amusement.
¢ For this lab, to translate a word into pig Latin, place the first letter of the English word at the end of the
word and add the letters ay.
¢ Thus, the word jump becomes umpjay. The word the becomes hetay.
¢ Prompt the user to enter a word.
¢ From the main method
Ø Call a method named printIt that will receive and print the word input by the user, appropriately labeled.
Ø Call a method named PLConverter that will receive the word input by the user. The method will convert
the word to pig Latin and return the result.
Ø Call the method named printIt that will receive and print the word that has been converted to pig Latin,
appropriately labeled.
¢ Prompt the user to enter a sentence.
¢ Print the sentence with each word on a separate line, with the last word on the first line.
For example, if the sentence entered is This is a sentence.
Then the following would be printed
sentence.
a
is
This
¢ Run Exercise 5 with the following modifications
Add a GUI that will print the number of aces drawn
Add a GUI that will print the number of cards dealt
Add a GUI that will print You Win if 4 aces are drawn
Note: You can shuffle the deck (as many times as you want but not after the first card is drawn
¢ Run Exercise 5 with the following modifications
Add a GUI that will print the number of clubs drawn
Add a GUI that will print the number of diamonds drawn
Add a GUI that will print the number of spades drawn
Add a GUI that will print the number of clubs drawn
Add a GUI that will print Flush if 5 of a suit are drawn
Add a GUI that will print the number of cards dealt
Note: You can shuffle the deck (as many times as you want but not after the first card is drawn