13,451,090 members (53,781 online)
See more:
I am confused on how to finish my project. I just need to put my algorithm under my for loop but I am lost. Here is the code so far:

import java.util.Scanner;

public class Encryption {
public Encryption () {
//Empty constructor.
}

public void run() {

boolean quit = false;
Scanner input = new Scanner(System.in);

while(quit == false)
{

System.out.println("Please enter a number between 1 and 26 or q to quit.\n");

// Accept the user input
String userKey = input.next();

// Check to see if the user is quitting instead of entering in a new number
if( userKey.charAt(0) == 'q' )
{
quit = true;
// Exits out of the loop
System.out.println("Now exiting...");
}

else
{
// Convert user input into a number
int userNum = Integer.parseInt(userKey);

// Check if the number is within the valid range
if( userNum > 0 || userNum < 27 )
{
System.out.println("Enter the message you wish to encrypt:\n");
String userMessage = input.next();

for(int i = 0; i < userMessage.length(); i++)
{
userMessage.charAt(i);
}

}

else
{
System.out.println("Error: Please enter a number between 1 and 26 or q to quit.");
}

}
}

// Close the input stream
input.close();
}
}
Posted 5-Oct-12 7:48am
Updated 5-Oct-12 8:25am
v2

So put your algorithm under your for loop.... what could possibly be the problem with that?

## Solution 1

So you have done the whole thing, except the bit that makes it a Caesar Cypher program?

And you want us to "fill in the blanks".

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

## Solution 2

You are just a step (or, at least, few steps) away from the solution having the current char and the translation parameter. Add them (handling the 'overflow') in order to obtain the current character of the output string.

Top Experts
Last 24hrsThis month
 OriginalGriff 538 Richard Deeming 280 CHill60 135 Jochen Arndt 130 Maciej Los 130
 OriginalGriff 5,135 Maciej Los 2,712 CPallini 1,722 Richard Deeming 1,710 ppolymorphe 1,553