Results 1 to 3 of 3
  1. #1
    Joycey is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Unhappy bla

    ugivbg bhjvghjv jhvc bv
    Last edited by Joycey; 04-15-2010 at 04:47 PM.

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

    Default

    Hello. If you have a compile problem or any exception, it's always a good idea to post the error messages here. Else we won't have any idea about what's wrong.

    Also, I added code tags to your post to make it more readable. Please look at my signature below to see how to do this yourself on your next post. Best of luck!

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Java Code:
        public static void GetName(String A2[],int A[][])
        {
            for(int i=0;i<A.length;i++){
                switch(A2)
                {
                    case 1:A2="Kevin \t\t  ";break;
                    case 2:A2="Ian \t\t  ";break;
                    case 3:A2="Andy \t\t  ";break;
                    case 4:A2="James \t\t  ";break;
                    case 5:A2="Dave \t\t  ";break;
                    case 6:A2="Conor \t\t  ";break;
                    case 7:A2="Shane \t\t  ";break;
                    case 8:A2="Ciarn \t\t  ";break;
                    case 9:A2="Christian \t  ";break;
                    case 10:A2="Barry \t\t  ";
                }//end of switch
            }
        }//end of procedure 'GetNmane'
    There is so much wrong with this code, that it's going to seem like I'm being very mean as I explain it all. Please know that is not my intent.

    Overall, you are being stingy with spaces, which makes your code cramped and difficult to read, and therefore confusing.

    First of all, "GetName()" is a very bad name for this method. Method names should begin with a lower-case letter (such as "getName()"), and names that start with "get" should return a value. Specifically, a method called "getName()" should probably return a String containing the name of something -- probably the name assigned to the object the method is attached to. This method seems to want to fill an array with names, so a much better name would be something like "fillArrayWithNames()".

    The names "A" and "A2" are also bad. Choose names for your variables that clearly describe the data they will contain, and spell them, like method names, starting with lower case letters, and capitalizing any subsequent words. From what I can see, your A2 array should simply be called "names", and I really can't tell what your "A" array is supposed to be.

    Next, your method signature calls for two parameters: an array of Strings and an array of arrays of ints. You're only using the array of arrays of ints to get its length, so you might consider making that parameter a simple int. But wait, you don't really seem to want the length of array A anyway, because it has a length of 5, and you seem to want to load 10 values into array A2. So maybe you don't need the second parameter at all.

    Then you have a for loop, which looks reasonable enough (except for using A.length), and within it you have a switch statement. Java's switch statement calls for a byte, short, char or int, and you are giving it a String[]. (Hint: maybe you wanted switch(i)? If that's what you intended, note that i will go from 0 to 9, while your switch block goes from 1 to 10.)

    Then on each line of the body of your switch block, you are trying to assign a String to A2, which is a String[] (maybe you want A2[i]?). You have embedded tabs in the Strings you are trying to assign, which I'm sure is for the sake of presentation when you do your printing later on. Don't do it like that. Let data be data, and presentation be presentation.

    Finally, the comment explaining your last curly brace has your method name misspelled.

    And to top it all off, when you call this method, you do it with the parameters reversed:
    Java Code:
    			  GetName(A,A2);
    And the whole method looks like it's supposed to do basically this:
    Java Code:
        String[] A2 = { "Kevin", "Ian", "Andy", "James", "Dave",
                              "Conor", "Shane", "Ciarn", "Christian", "Barry" };
    I advise you to start again from the beginning. Write out what you want to accomplish in pseudo-code. Break your tasks into small, easy-to-understand methods, and test them one at a time. Think carefully about what data each method needs, whether it should get it from passed parameters or from object data members, and what it should return. Be patient with yourself. Trying to hurry through your coding will only confuse you.

    Hope that helps.

    -Gary-

Similar Threads

  1. 2 dimensional array help!
    By ber1023 in forum New To Java
    Replies: 9
    Last Post: 01-02-2011, 12:29 AM
  2. 2 dimensional array with strings.
    By dbashby in forum New To Java
    Replies: 12
    Last Post: 10-13-2009, 10:52 PM
  3. Mulit dimensional Array
    By jonsamwell in forum New To Java
    Replies: 7
    Last Post: 02-03-2009, 12:35 PM
  4. two-dimensional array
    By kHim in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 07:21 PM
  5. How to initialize a two dimensional Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:48 PM

Tags for this Thread

Posting Permissions

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