Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
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:

Java
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
Updated 5-Oct-12 8:25am
v2
Comments
[no name] 5-Oct-12 14:29pm    
So put your algorithm under your for loop.... what could possibly be the problem with that?

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!
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900