Results 1 to 10 of 10
  1. #1
    thomachan21 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Post How do I properly finish this code I made to complete it? Any help would be great.

    Hey there guys, this is thomachan21 once again, here to recieve some help on a code I created.

    Exactly what I am trying to do is that I need to input a String and with that String I need to remove all capital characters, remove spaces, and punctuation. When all of that is done I need to reverse the string and combine the two to make a palindrome.

    Is there another form of string I should write? Or do I need to put in another system.print line?
    This is for Java btw (BlueJ)

    Any help would be appreciated
    Or a walk through ;P
    Looking forward to getting ur replies



    Java Code:
    import java.util.*;
    public class Palindrome
    {
        public String lowerCase(String str)
        {
            str.toLowerCase();
            return str;
        }
     
        public String reverse(String str)
        {
            if (("" == str) || (str.length()  <= 1))
            {
                return str;
            }
            else
            {
                return reverse(str.substring(1)) + str.charAt(0);
            }
        }
    }
    
    
    
    
    import java.util.*;
    public class Driver
    {
        private static Scanner in;
        public static void main(String[] args)
        {
            Palindrome pal = new Palindrome();
            in = new Scanner(System.in);
            String tempPhrase = "";
            String phrase = "";
            System.out.println("What Up Dog? Welcome to the Palindrome Creater");
            System.out.println("What phrase or word you heard on the streets you want to use bro? ");
            tempPhrase = in.nextLine();
            phrase = tempPhrase;
            System.out.println();
            System.out.println("Due to some extensive researching, we have come up with your word.");
            System.out.println(phrase);
            phrase = pal.lowerCase(phrase);
            System.out.println(phrase);
            phrase = pal.reverse(phrase);
           
        }
    }
    Last edited by thomachan21; 12-17-2012 at 06:40 PM. Reason: Made it better to understand

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    You need to have some method in there that tests if the String is a palindrome and returns a boolean result -- true if its a palindrome, false if not. Where is your code attempt to do this?

  3. #3
    thomachan21 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    We dont need that. All the IT said was too just create it, not check whether or not its a palindrome.
    So was seeing what I did wrong. xD

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    Ah, my bad. Please ignore my answer then.

  5. #5
    thomachan21 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    Quote Originally Posted by Fubarable View Post
    Ah, my bad. Please ignore my answer then.
    Haha its okay, just wondering if you knew what to do.... or whether or not its possible to even attempt to create the palindrome. with another code.. or if i edit the code.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    What output are you currently seeing?

  7. #7
    thomachan21 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    Its returning the string that was originally inputted

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    But in lower-case. I think that you need to experiment with this more. Yes you need more println's especially at the bottom. I think that once you see the result from the last println, you'll be able to figure out how to solve this (mostly -- you still need a method for punctuation et al.).

  9. #9
    thomachan21 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: How do I properly finish this code I made to complete it? Any help would be great

    Quote Originally Posted by Fubarable View Post
    But in lower-case. I think that you need to experiment with this more. Yes you need more println's especially at the bottom. I think that once you see the result from the last println, you'll be able to figure out how to solve this (mostly -- you still need a method for punctuation et al.).

    Ahh never mind.. I got it :P if u could please lock this thread or delete it. That would be great :P I just had to add more printlns and fixed up a few things.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Not sure hot to finish this Java code..
    By john_java in forum New To Java
    Replies: 8
    Last Post: 03-29-2012, 11:37 PM
  2. complete the code
    By blackz in forum New To Java
    Replies: 2
    Last Post: 09-11-2011, 02:04 AM
  3. Replies: 3
    Last Post: 08-10-2011, 09:17 AM
  4. Replies: 8
    Last Post: 06-06-2010, 03:10 PM
  5. Complete code won't run in eclipse
    By confusedStudent in forum New To Java
    Replies: 2
    Last Post: 12-19-2008, 08:43 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
  •