Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java: basic cipher

Options
  • 29-11-2006 3:08pm
    #1
    Registered Users Posts: 5,217 ✭✭✭


    For my college assignment this week i have to make a program that encrypts some text using a basic Caesar Cipher(ie shifting the letters) In the first box is my code and in the 2nd is my error message. Could anyone shed some light on what is wrong. As when i have the touchMe() part out of a methods it runs perfectly but we must use a method. so any help please.
    public class Ciphers
    {
    	static void touchMe(char []alphaUp, char []alphaLow, char c1, int blah, char[] replaced)
    	{	
    		for (int j = 0; j < alphaUp.length; j++)
    		{
    			if (j < 23)
    			{
    				if (c1 == alphaUp[j])
    				{
    					replaced[blah] = alphaUp[j + 3];
    					blah++;
    				}
    				else if (c1 == alphaLow[j])
    				{
    					replaced[blah] = alphaLow[j + 3];
    					blah++;
    				}
    			}
    			else if (22 < j && j < 26)
    			{
    				if (c1 == alphaUp[j])
    				{
    					replaced[blah] = alphaUp[j - 23];
    					blah++;
    				}
    				else if (c1 == alphaLow[j])
    				{
    					replaced[blah] = alphaLow[j - 23];
    					blah++;
    				}
    			}
    			else
    			{
    				if (c1 == alphaUp[j])
    				{
    					replaced[blah] = alphaUp[j];
    					blah++;
    				}
    			}
    		}
    	}
    
    	public static void main(String [] args)
    	{
    		char [] alphaUp = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ','.','?','!',',','\'','@',';',':','#','"'};
    		char [] alphaLow = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    		char [] replaced = new char [4000000];
    		int blah = 0;
    		
    		//read in string
    		System.out.println("Please enter the text you wish to encode: ");
    		String encodee = Console.readString();
    		
    		//loops around for the length of the the String
    		for (int i = 0; i < encodee.length(); i++)
    		{
    			//gets char at location of string
    			char c1 = encodee.charAt(i);
    
    			touchMe(char alphaUp[], char alphaLow[], char c1, int blah, char replaced[]);
    		}
    			
    		for (int a = 0; a < encodee.length(); a++)
    		{
    			System.out.print(replaced[a]);
    		}
    	}
    }
    
    
    Ciphers.java:61: '.class' expected
                            touchMe(char alphaUp[], char alphaLow[], char c1, int blah, char replaced[]);
                                         ^
    Ciphers.java:61: ')' expected
                            touchMe(char alphaUp[], char alphaLow[], char c1, int blah, char replaced[]);
    
                        ^
    2 errors
    


Comments

  • Closed Accounts Posts: 362 ✭✭information


    heres the solution
    void method(String s){
    }
    
    String input = "";
    
    method(input);
    


  • Registered Users Posts: 5,217 ✭✭✭Matthewthebig


    I don't understand what you mean by that


  • Registered Users Posts: 304 ✭✭PhantomBeaker


    There are two parts to a method.
    void mymethod(int i, double d, char c){ // This is the method "description" - it tells you what it expects as input)
     //stuff
    }
    

    now if I want to call mymethod
    int weeble = 0;
    double bob = 0.0;
    char splat = '0';
    
    mymethod(weeble, bob, splat);
    

    Notice that when I'm calling mymethod, I'm not telling it what types of variable they are, because the method knows what to expect, and the compiler already knows what type of variable weeble, bob and splat are, so it can see that they 'fit' the method description.

    Does that help at all?

    Aoife


  • Registered Users Posts: 5,217 ✭✭✭Matthewthebig


    Ah brilliant. It now compiles. Now i just need to fix the new problem :p


Advertisement