Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    danthegreat is offline Member
    Join Date
    Sep 2011
    Location
    Washington DC
    Posts
    51
    Rep Power
    0

    Default Re: Pig Latin Translator

    Quote Originally Posted by milovan View Post
    And just one question about your logic. Do you need to use
    Java Code:
    substring(int start,int end)
    I think that
    Java Code:
    substring(int start)
    is just enough for your needs...
    That fixed the problem!! Thank you so much. I didn't know substring(start) would automatically grab until the end of the string.


    Now I have a new problem. I'm trying to re-arrange capitalization for example:

    Daniel Goldburg
    output: Anielday Oldburggay

    it works fine, when I run it but when I add a whole sentence it gets messy, here is the few functions are used:

    Java Code:
    public static String wordToPig (String english){        
            String end, start, fin="", word_lower;
            int index=0;
            
            
    
    
            
            index=hasAVowel(english);
            
            
            //if no vowels
            if(index==-1){
                fin = english+"ay";
            }
            
            //else if begins with vowel
            if(index==0){
                fin=english+"yay";
            }
            
            //else has vowel and doesn't start with vowel
            if(isCapitalized(english)==true){
                word_lower=lowerCase(english);
                if(index>0){
                    start = word_lower.substring(0, index);
                    end = word_lower.substring(index);
                    fin = end+start+"ay";
                    fin = upperCase(fin);
    
    
                }
            }
            
            
            return fin;
        
            
    }
    
    
        public static boolean isCapitalized (String word){
            
            if(word.charAt(0) >= 'A' && word.charAt(0) <= 'Z'){
                return true;
                
            }
            else
                return false;
            
        }
        
        public static String lowerCase(String word){
            
            word=word.toLowerCase();
            return word;
        }
        
        
        
        
        public static String upperCase(String word){
            
            String first_char, fin, without_first_char;
            
            without_first_char= word.substring(1);
            
            first_char = word.substring(0,1);
            first_char = first_char.toUpperCase();
            
            fin = first_char + without_first_char;
    
    
            
            return fin;
            
            
    }
    Current output trials: (bolded are incorrect)

    English: Daniel Goldburg
    Translation: Anielday Oldburggay

    English: He sells sea shells by the sea shore
    Translation: Ehay byay

    English: Boom Bang Bang
    Translation: Oombay Angbay Angbay

    English: Boom bang bang
    Translation: Oombay

    Whoa! So now according to the trial above, it seems that when there is a capitalized word, the non-capitalized words get messed up!why is that happening? My if statements "If(iscapital()==true)" should be triggered and isCapital() should be outputting with "false" causing the computer to ignore what's inside the if. Anyone have a slight clue?


    EDIT: I realized that I did not handle the condition if the word has a vowel but not at the start and is NOT capital!! Woot the program is finished!
    Thank you all extremely for your tremendous help and having to put up with me!
    Last edited by danthegreat; 09-10-2011 at 11:41 PM.

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Pig Latin Translator

    (bolded are incorrect)
    You have bolded the whole output and not shown what perhaps single letter is wrong and then shown immediately next to the wrong output what the correct output should be.

    it seems that when there is a capitalized word, the non-capitalized words get messed up!why is that happening?
    Again: to find your logic problems you need to print out what your code is doing at each step.
    Or you can wait for someone else to do your work for you.

  3. #23
    danthegreat is offline Member
    Join Date
    Sep 2011
    Location
    Washington DC
    Posts
    51
    Rep Power
    0

    Default Re: Pig Latin Translator

    Thank you Norm but not needed :)

    I finished it! It came to me as I was commenting.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. applicaton for nokia S60 devices(Translator), need help
    By Basit781 in forum CLDC and MIDP
    Replies: 0
    Last Post: 05-18-2010, 03:42 PM
  2. java spanish translator needed for jni
    By Nicholas Jordan in forum Jobs Offered
    Replies: 5
    Last Post: 08-11-2009, 03:43 PM
  3. Custom Font Translator
    By Nerdopolis in forum New To Java
    Replies: 3
    Last Post: 04-18-2009, 03:50 AM
  4. Translator hashtable
    By editor35 in forum New To Java
    Replies: 1
    Last Post: 01-11-2009, 02:02 AM
  5. Java multilanguage translator
    By mnprakash in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-05-2009, 08:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •