Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Homework
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
Edited 5-Oct-12 8:25am
v2
Comments
Wes Aday at 5-Oct-12 14:29pm
   
So put your algorithm under your for loop.... what could possibly be the problem with that?
Rate this: bad
good
Please Sign up or sign in to vote.

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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,189
1 Sergey Alexandrovich Kryukov 5,666
2 CPallini 4,810
3 George Jonsson 3,429
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100