Question: import java.util,Scanner; public class Messages { private String message; private int code; Scanner keyboard = new Scanner ( System.in ) ; / / This method

import java.util,Scanner;
public class Messages
{
private String message;
private int code;
Scanner keyboard = new Scanner(
System.in);
// This method prompts the user to enter a string
public void setMessage()
r
System.out, println("Please enter a message to encrypt: ");
message = keyboard.nextlinel);
}// end setMessage()
// This method will print out the contents of the string
public void getMessage()
{
System.out.println("The message you entered is as follows: "+ message);
System.out.println();
}// end getMessage()
// This method prompts the user to enter the code with which to encrypt the string
public void setCode()
System_out-println("Please enter the code with which to encrypt the message: ");
code = keyboard,nextInt();
3// end setCode(10)
// This method show's the user what the value for code is that they gave
public void getCode()
{
System.out-println("The code you entered is as follows: "+ code);
System.aut.println();
}// end getCode()
// This method converts the character that is passed in to the encrypted version
private char encrypt(char letter)
l
if (letter ='')
else
return letter;
letter =(char)((int)letter + code)s
return letter;
}// end encrypt()
// This method calls encrypt, passing in one character at a time using as loop
private void encryptall()
i
char[l] messageArray = message,tocharArray();
charif cncryptedArray = new char(message. length()];
for (int index =0; index message. length(); Indext +)
}
}
encryptedArray[findex]= magrynt{l
}// end encryptall()
"/ This method prints out the results of encryptAll
public void printOut()
System.out.println("The encrypted message is as follows:" *
import java.util,Scanner; public class Messages {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!