Question: public static void main(String[] args) { //Add a do-while loop that keeps looping while the user //enters either 1 or 2. int menuOption = displayMenu();
public static void main(String[] args)
{ //Add a do-while loop that keeps looping while the user //enters either 1 or 2. int menuOption = displayMenu(); switch(menuOption) { case 1: encryptPassword(); case 2: decryptPassword(); case 3: selfDestruct(); } } public static int displayMenu() { //Display the menu to show: // 1. Encrypt a Password? // 2. Decrypt a Password? // 3. Stop Spying...END //Get input from user and store in a local variable //loop to validate value entered as 1, 2, or 3 //and if not, keep looping and asking user to enter valid value //return value entered return 0; //temporary } public static void encryptPassword() { //1. Ask user for for to encrypt //2. Instantiate the PasswordEncryption object, passing // it the word and a boolean value of true, meaning encrypt //3. Display the encrypted word to the user. //4. Extra Credit: Before displaying encrypted word, // ask user to guess the encrypted word. If user guesses // correctly, state "Successfully encryptedmission accomplished" // If user did not guess correctly, state "Unsuccessfully encrypted...Danger, danger! } public static void decryptPassword() { //1. Ask user for encrypted word to decrypt //2. Instantiate the PasswordEncryption object, passing // it the word and a boolean value of false, meaning decrypt //3. Display the decrypted word to the user. //4. Extra Credit: Before displaying decrypted word, // ask user to guess the decrypted word. If user guesses // correctly, state "Successfully decryptedmission accomplished" // If user did not guess correctly, state "Unsuccessfully decrypted...Danger, danger! } public static void selfDestruct() { //Advise the user that this program will self-destruct in 5 seconds //5 - 4 - 3 - 2 - 1 - 0 Boom!
}
public class PasswordEncryption { String origWord; String encryptWord;
public PasswordEncryption(String word, boolean encrypt) { if (encrypt) { this.origWord = word; this.encryptWord = ""; } else { this.encryptWord = word; this.origWord = ""; } }
public String getOrigWord() { return origWord; }
public void setOrigWord(String origWord) { this.origWord = origWord; }
public String getEncryptedWord() { return encryptWord; }
public void setEncryptedWord(String encryptWord) { this.encryptWord = encryptWord; } public String toString() { return "Original Word: " + origWord + " Encrypted Word:" + encryptWord; } public void encryptOrig() { //Add code to take the origWord and encrypt it, storing //the encrypted word in encryptWord } public void decryptEncrypt() { //Add code to take the encryptWord and decrypt it, storing //the original word in orgiWord } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
