Results 1 to 11 of 11
  1. #1
    bentho is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Post Monogram JOptionPane

    Thanks for helping me fix my program you guys are great
    Last edited by bentho; 10-24-2010 at 01:34 AM. Reason: privacy

  2. #2
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    You are only allowed to return one variable from a method, so when it reaches the first return statement it exits the method. Hence, why they are "unreachable". You could try to make firstName, middleName, and lastName global variables so you won't have to return them. Also, I don't see where you are calling that method anywhere in your code.

    Then you could create a string from the monogram characters and return that (if the teacher allows it). I see no way to do it other than that, or having 3 methods to return each separate character. And I never see where you are calling the method getInitial.
    Sincerely, Joshua Green
    Please REP if I help :)

  3. #3
    bentho is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Ok that makes sense about the unreachable return statement. I am unfamililar with global variables. You're right I need to call methods inputNames and getInitial inside main. I am confused on creating a string from characters. I will look into that. It needs to be one method (setMonogram()) to generate the monogram result, then display it.

    Thanks

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

    Default

    I agree with the recommendation above to have getInitials() return a String with the three chars in it. One way to create a String out of chars is to concatenate the chars, but you'll need to start out this concatenation with a String initially otherwise the compiler will think you're adding ints.

    e.g.,
    Java Code:
       public static void main(String[] args) {
          char myChar1 = 'a';
          char myChar2 = 'b';
          
          String myString = "" + myChar1 + myChar2;
          
          System.out.println(myString);
       }

  5. #5
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    To declare a global variable all you need to do is declare the variable in the class rather than in a method.

    Java Code:
    public class JavaHelp 
    {
        String first, middle, last;
    Sincerely, Joshua Green
    Please REP if I help :)

  6. #6
    bentho is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Thanks for helping me fix my program you guys are great
    Last edited by bentho; 10-24-2010 at 01:34 AM. Reason: privacy

  7. #7
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    You don't put quotation marks around the variable name. To make it a string all you have to do is add an empty quotation to the variables like:

    Java Code:
    String example = "" + variable + variable2;

    If you are using Eclipse I know you can click on the error and it will take you to the line that is giving you the error. (For future reference).
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    You're re-declaring your String variables in the inputNames method and thus setting these String variables (that are only visible within this method) with data, not the class variables.

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

    Default

    Quote Originally Posted by joshdgreen View Post
    If you are using Eclipse I know you can click on the error and it will take you to the line that is giving you the error. (For future reference).
    I'm going to respectfully disagree with the OP's using Eclipse or other large complex IDE at this stage. Better that he have only one steep learning curve to worry about (Java) without adding another on top of it (the IDE).

  10. #10
    bentho is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Ok I have removed quotations and inserted blank quotations on the String initials line. I have NetBeans but have never used it so I have been using notepad and command prompt. Ok I see what you mean about re-declaring the string variables. I finally fixed it! Thanks for clarifying josh and fubarable

  11. #11
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    No problem, and gratz :)
    Sincerely, Joshua Green
    Please REP if I help :)

Similar Threads

  1. Help with JOptionPane
    By sanctishit in forum New To Java
    Replies: 1
    Last Post: 03-10-2010, 11:20 AM
  2. need help with a JOptionPane
    By dr4g0nk1ng in forum Advanced Java
    Replies: 2
    Last Post: 02-19-2010, 10:40 PM
  3. making a monogram swing
    By moostico246 in forum AWT / Swing
    Replies: 29
    Last Post: 04-07-2009, 05:08 AM
  4. Monogram program
    By mistah in forum New To Java
    Replies: 8
    Last Post: 12-24-2008, 05:57 AM
  5. JOptionPane
    By Mir in forum New To Java
    Replies: 5
    Last Post: 11-29-2008, 03:04 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
  •