Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with my code.

  1. #1
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Talking Help with my code.

    I'm trying to make a Albhed Converter from FFX. But the Letters wont covert right. Can someone help me?

    The Output:
    Push 1 to convert English to AlBhed
    Push 2 to convert AlBhed to English
    1
    Enter the phase you wish to convet to AlBhed.
    A
    A Means...
    O


    But the letter A should be Y not O. Please Help


    /**
     * @(#)AlBhedCoverter.java
     *
     * AlBhedCoverter application
     *
     * @author 
     * @version 1.00 2013/7/26
     */
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.util.Scanner;
     
     
    public class AlBhedCoverter {
     
        public static void main(String[] args) {
     
    		Scanner input = new Scanner(System.in);
        	Scanner keyboard = new Scanner(System.in);
        	AlBhed x = new AlBhed();
        	English y = new English();
     
        	System.out.println("Push 1 to convert English to AlBhed");
        	System.out.println("Push 2 to convert AlBhed to English");
        		int choice1 = keyboard.nextInt();
        		switch (choice1)	{ 
        			case 1: 
        				x.AlBhedCov();
        				break;
     
        			case 2:
        				y.EnglishCov();
        				break;
     
        		}
     
     
        }
    }

    /**
     * @(#)AlBhed.java
     *
     *
     * @author 
     * @version 1.00 2013/7/26
     */
     
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.util.Scanner;
    public class AlBhed {
     
        public void AlBhedCov() {
     
        Scanner keyboard = new Scanner(System.in);	
        String letter = " ";	
    	System.out.println("Enter the phase you wish to convet to AlBhed.");
    	letter = keyboard.nextLine();
    	System.out.println(letter + " Means...");
    	String newLetter = letter.replaceAll("A","Y")
                                 .replaceAll("a","y")
                                 .replaceAll("B","P")	
                                 .replaceAll("b","p")
                                 .replaceAll("C","L")	
                                 .replaceAll("c","l")   	                         	
                                 .replaceAll("D","T")	
                                 .replaceAll("d","t")
                                 .replaceAll("E","A")	
                                 .replaceAll("e","a") 
                                 .replaceAll("F","V")
                                 .replaceAll("f","v")	
                                 .replaceAll("G","K")
                                 .replaceAll("g","k")	
                                 .replaceAll("H","R")   	                         	
                                 .replaceAll("h","r")	
                                 .replaceAll("I","E")
                                 .replaceAll("i","e")	
                                 .replaceAll("J","Z")
                                 .replaceAll("j","z")	
                                 .replaceAll("K","G")
                                 .replaceAll("k","g")	
                                 .replaceAll("L","M")   	                         	
                                 .replaceAll("l","m")	
                                 .replaceAll("M","S")
                                 .replaceAll("m","s")	
                                 .replaceAll("N","H")
                                 .replaceAll("n","h")	
                                 .replaceAll("O","U")
                                 .replaceAll("o","u")	
                                 .replaceAll("P","B")   	                         	
                                 .replaceAll("p","b")	
                                 .replaceAll("Q","X")
                                 .replaceAll("q","x")	
                                 .replaceAll("R","N")
                                 .replaceAll("r","n")	
                                 .replaceAll("S","C")
                                 .replaceAll("s","c")	
                                 .replaceAll("T","D")   	                         	
                                 .replaceAll("t","d")	
                                 .replaceAll("U","I")
                                 .replaceAll("u","i")	
                                 .replaceAll("V","J")
                                 .replaceAll("v","j")	
                                 .replaceAll("W","F")
                                 .replaceAll("w","f")	
                                 .replaceAll("X","Q")   	                         	
                                 .replaceAll("x","q")	
                                 .replaceAll("Y","O")
                                 .replaceAll("y","o")
                                 .replaceAll("Z","W")
                                 .replaceAll("z","w");            
     
    		System.out.println(newLetter);
     
        } 
    }

    /**
     * @(#)English.java
     *
     *
     * @author 
     * @version 1.00 2013/7/26
     */
     
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.util.Scanner;
    public class English {
     
        public void EnglishCov() {	
        Scanner keyboard = new Scanner(System.in);	
        String letter = " ";	
    	System.out.println("Enter the phase you wish to convet to English.");
    	letter = keyboard.nextLine();
    	System.out.println(letter + " Means...");
        String newLetter = letter.replaceAll("Y","A")
                                 .replaceAll("y","a")
                                 .replaceAll("P","B")	
                                 .replaceAll("p","b")
                                 .replaceAll("L","C")	
                                 .replaceAll("l","c")   	                         	
                                 .replaceAll("T","D")	
                                 .replaceAll("t","d")
                                 .replaceAll("A","E")	
                                 .replaceAll("a","e") 
                                 .replaceAll("V","F")
                                 .replaceAll("v","f")	
                                 .replaceAll("K","G")
                                 .replaceAll("k","g")	
                                 .replaceAll("R","H")   	                         	
                                 .replaceAll("r","h")	
                                 .replaceAll("E","I")
                                 .replaceAll("e","i")	
                                 .replaceAll("Z","J")
                                 .replaceAll("z","J")	
                                 .replaceAll("G","k")
                                 .replaceAll("g","k")	
                                 .replaceAll("M","L")   	                         	
                                 .replaceAll("m","l")	
                                 .replaceAll("S","M")
                                 .replaceAll("s","m")	
                                 .replaceAll("H","N")
                                 .replaceAll("h","n")	
                                 .replaceAll("U","O")
                                 .replaceAll("u","o")	
                                 .replaceAll("B","P")   	                         	
                                 .replaceAll("b","p")	
                                 .replaceAll("X","Q")
                                 .replaceAll("x","q")	
                                 .replaceAll("N","R")
                                 .replaceAll("n","r")	
                                 .replaceAll("C","S")
                                 .replaceAll("c","s")	
                                 .replaceAll("D","T")   	                         	
                                 .replaceAll("d","t")	
                                 .replaceAll("I","U")
                                 .replaceAll("i","u")	
                                 .replaceAll("J","V")
                                 .replaceAll("j","v")	
                                 .replaceAll("F","W")
                                 .replaceAll("f","w")	
                                 .replaceAll("Q","X")   	                         	
                                 .replaceAll("q","X")	
                                 .replaceAll("O","Y")
                                 .replaceAll("o","y")
                                 .replaceAll("W","Z")
                                 .replaceAll("w","z");                                  
     
    		System.out.println(newLetter);
     
        } 
    }


  2. #2
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Help with my code.

    Hello.
    You are invoking the method calls in chain.
    So what is happening is first 'A' is converted into 'Y' and then 'Y' into 'O'. Thats why you are getting 'O'.
    Instead of that you should replace each letter invidually. I mean you need to invoke replace method for each character separately.
    You need to change your design.

    thanks,
    Syed.

  3. #3
    Member
    Join Date
    Jul 2013
    Location
    Franklin, TN
    Posts
    47
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: Help with my code.

    Hey.

    Syedbhai is exactly right, you are invoking method chains and in turn, the ".replaceAll" function is replacing each letter before it can be checked for the letter you want it to be checked for.

    My suggestion is to put all possibilities of letters, for each language, in a 2D array and find their conversions that way. Ill even get you started...

    private String[][] englishLanguage = new String[1][#ofletters];

    Put each of the letters for that language in englishLanguage[0][0-#number of letters];
    Then put their conversions in the corresponding dimension, englishLanguage[1][0-#number of letters];


    Of course this method will involve knowledge of parsing strings and a good understanding of multi-dimenional arrays would help as well. But you can go through each letter changing it to the same index in the other dimension of the array, in order to convert it.

  4. The Following User Says Thank You to AlexHail For This Useful Post:

    surfelijo (July 30th, 2013)

  5. #4
    Junior Member surfelijo's Avatar
    Join Date
    Feb 2013
    Location
    Fallbrook, CA
    Posts
    14
    My Mood
    Nerdy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Help with my code.

    AlexHail can you explain your method more? Thank YOU!!!

    --- Update ---

    Im not very good at multi-dimenional arrays haha So you help would be greatly appreciated

Similar Threads

  1. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  2. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  3. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM