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: Converting Name.

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Converting Name.

    What can I do in my convertName method to convert the users input to last,first from first last? I have already written the method to determine if it was last,first and if it was, it just returns. If they input first/last, I need to convert to last/first using convertName method, how would I go about doing that?
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package name;
     
    /**
     *
     * @author student
     */
    import java.util.Scanner;
    public class Name {
     
     
        public static void main(String[] args) {
            String haveComma;
            String finishedName;
            String hasComma;
     
            Scanner reader = new Scanner(System.in);
            System.out.println("What is your name?");
            System.out.println("Ex: Logan Crone or Crone, Logan");
            String myName = reader.nextLine();
     
            hasComma(myName, haveComma);
            convertName (myName, hasComma);
            // May need conversion if not in First Last format   
     
        }
        public static void hasComma (String myName, String haveComma) {
            String hasCommaName = myName;
            int doesItHaveComma = hasCommaName.indexOf(',');         
            if (doesItHaveComma > 0){
                System.out.println("Last then first! Converting!");
                boolean convertMe = true;
                System.out.println(myName);
            }
     
    }
        public static void convertName (String myName,String hasComma) {
                  //Oh no! Here because format is first/last, need to convert!
            String finishedName;
     
     
     
     
        }
     
     
     
     
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Converting Name.

    Isn't that the entire point of your homework assignment? We can't just do your homework for you.

    I'd recommend checking out the API for the String class for useful functions. Post what you try after that, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Converting Name.

    I just wish someone would point me in the right direction as far as what I should be using so I can research it. I don't know what to use. My book this chapter only talked about upperstring and touppercase and tolowercase. What should I be using? Do i need to use 2 seperate strings for firstname and lastname?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Converting Name.

    Like I said, you should be looking at the API for String. If you're programming in Java, the API is your new best friend.

    Java Platform SE 6
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. converting int to char
    By surfbumb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 19th, 2011, 12:59 AM
  2. Converting Cases Help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 27th, 2010, 12:07 PM
  3. Converting to String
    By darek9576 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 13th, 2010, 06:09 PM
  4. Converting an array
    By Scottj996 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 6th, 2010, 09:58 AM
  5. Replies: 4
    Last Post: May 1st, 2009, 03:32 PM