Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37
  1. #21
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    Here is what I currently have

    Java Code:
    String[][] mbrnum = new String [20][2]; // 2 dimensional array
                    mbrnum[0][0]= "DAN100215";mbrnum[1][0]= "BUC200475";
    			    mbrnum[2][0]= "ADA505630";mbrnum[3][0]= "JOH300312";
    			    mbrnum[4][0]= "WHI776543";mbrnum[5][0]= "PEN134567";
    			    mbrnum[6][0]= "MUR455621";mbrnum[7][0]= "CRA097681";
    			    mbrnum[8][0]= "SIM0409152";mbrnum[9][0]= "MCC609863";
                    mbrnum[10][0] = "HAL609702";mbrnum[11][0] = "BUC408941";
                    mbrnum[12][0] = "NEW509039";mbrnum[13][0] = "PAR955542";
                    mbrnum[14][0] = "WALIIII999";mbrnum[15][0] = "THE479819";
                    mbrnum[16][0] = "LUC341287";mbrnum[17][0] = "WIL953216";
                    mbrnum[18][0] = "FAL200474";mbrnum[19][0] = "ABR970351";
    
                    mbrnum[0][1] = "21.675";mbrnum[1][1] = "24.798";
                    mbrnum[2][1]= "16.567";mbrnum[3][1] = "25.014";
                    mbrnum[4][1] = "32.907";mbrnum[5][1] = "31.456";
                    mbrnum[6][1] = "41.876";mbrnum[7][1] = "22.123";
                    mbrnum[8][1] = "20.945";mbrnum[9][1] = "20.679";
                    mbrnum[10][1] = "18.398";mbrnum[11][1] = "17.075";
                    mbrnum[12][1] = "40.025";mbrnum[13][1] = "26.564";
                    mbrnum[14][1] = "30.712";mbrnum[15][1] = "29.897";
                    mbrnum[16][1] = "23.397";mbrnum[17][1] = "35.548";
                    mbrnum[18][1] = "22.123";mbrnum[19][1] = "31.398";
    
               for (String[] array : mbrnum ) {
                    Arrays.sort(array);
                        }

  2. #22
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    That code won't throw any exceptions.

  3. #23
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    The code I currently have is

    Java Code:
    System.out.println("After Search");
    
                   /*     String[] nums={"21.675", "24.798", "16.567", "25.014",
                        "32.907", "31.456", "41.876", "22.123", "20.945","20.679",
                        "18.398", "17.075", "40.025", "26.564", "30.712", "29.897",
                        "23.397", "35.548", "22.123", "31.398" }; */
    String[][] mbrnum = new String [20][2]; // 2 dimensional array
                    mbrnum[0][0]= "DAN100215";mbrnum[1][0]= "BUC200475";
    	        mbrnum[2][0]= "ADA505630";mbrnum[3][0]= "JOH300312";
    		mbrnum[4][0]= "WHI776543";mbrnum[5][0]= "PEN134567";
    		mbrnum[6][0]= "MUR455621";mbrnum[7][0]= "CRA097681";
    		mbrnum[8][0]= "SIM0409152";mbrnum[9][0]= "MCC609863";
                    mbrnum[10][0] = "HAL609702";mbrnum[11][0] = "BUC408941";
                    mbrnum[12][0] = "NEW509039";mbrnum[13][0] = "PAR955542";
                    mbrnum[14][0] = "WALIIII999";mbrnum[15][0] = "THE479819";
                    mbrnum[16][0] = "LUC341287";mbrnum[17][0] = "WIL953216";
                    mbrnum[18][0] = "FAL200474";mbrnum[19][0] = "ABR970351";
    
                    mbrnum[0][1] = "21.675";mbrnum[1][1] = "24.798";
                    mbrnum[2][1]= "16.567";mbrnum[3][1] = "25.014";
                    mbrnum[4][1] = "32.907";mbrnum[5][1] = "31.456";
                    mbrnum[6][1] = "41.876";mbrnum[7][1] = "22.123";
                    mbrnum[8][1] = "20.945";mbrnum[9][1] = "20.679";
                    mbrnum[10][1] = "18.398";mbrnum[11][1] = "17.075";
                    mbrnum[12][1] = "40.025";mbrnum[13][1] = "26.564";
                    mbrnum[14][1] = "30.712";mbrnum[15][1] = "29.897";
                    mbrnum[16][1] = "23.397";mbrnum[17][1] = "35.548";
                    mbrnum[18][1] = "22.123";mbrnum[19][1] = "31.398";
    
               for (String[] array : mbrnum ) {
                    Arrays.sort(array);
                        }
                     //   txtResult.setText([array]); // sends 1st (lowest) number to textfield
                        // send number to textfield
                        System.out.println("Lowest Bmi Reading = " + mbrnum[0]);
                            System.out.println("Maximum = " + mbrnum[mbrnum.length-1]);
                        // Prints out variable nums which is highest number ^^^^^^^^

  4. #24
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    When it runs through the print statements for the lowest and highest I get

    Lowest Bmi Reading = [Ljava.lang.String;@14a8cd1
    Maximum = [Ljava.lang.String;@1630ab9

    and the above errors and they can only apply to this section of code as everything else works fine.

  5. #25
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    We are getting nowhere fast. You claim to be getting exceptions with code that doesn't throw any exception.
    Do yourself a favor and read a tutorial about arrays. Then read a basics tutorial about about variable scoping rules.

  6. #26
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by dbashby View Post
    When it runs through the print statements for the lowest and highest I get

    Lowest Bmi Reading = [Ljava.lang.String;@14a8cd1
    Maximum = [Ljava.lang.String;@1630ab9

    and the above errors and they can only apply to this section of code as everything else works fine.
    Those are arrays being printed. What does the lowest array mean? Your code doesn't make much sense. Revise your design.

  7. #27
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    Well it builds, runs but when i select the RB to search for lowest number it throws those errors, I will go to look where you suggest but if you say that it shouldnt throw the exceptions then you can see why I am confused.

  8. #28
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Which errors? Those print outs are not errors. They are toString representations of the arrays. If you want to print the array's contents then use Arrays.toString(array).

  9. #29
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    lowest number in the array and secondly the highest, I had them printing out the correct numbers when I was using a 1 dimensional array but now the print statements output

    Java Code:
    Lowest Bmi Reading = [Ljava.lang.String;@14a8cd1
    Maximum = [Ljava.lang.String;@1630ab9
    I kept these in so that it was a backup for the output that is placed in the textbox on the GUI.

  10. #30
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    I have removed the print statements for now and I do not get any exceptions, so thanks for that.

    Onto the next stage

    Thanks again

  11. #31
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You are not reading my posts at all!
    You now have an array of arrays. Your concept of lowest value no longer makes sense. What does lowest array mean?
    Use that Arrays.toString method like I suggested to see what I mean.
    [Ljava.lang.String;@14a8cd1 is an array. The toString is just [L className;hashCode(in hex). That's why you see things you think are errors.

  12. #32
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    its not lowest array, i have to find the lowest number in the array, so in the 2d array which yes i am reading your posts is an array inside an array that contains 2 arrays.

    When I removed the print statements all the exceptions I listed stopped.

    I am now trying to get the lowest number to print out in the output window to make sure that it is the lowest number that it is sorting.

  13. #33
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Those are not exceptions. You really need to read a Java basics tutorial.
    For your program, better throw all that mess away and use OOP instead. Create a class called, say Data with two fields ..
    Java Code:
    class Data {
       String code;
       double value;
       public Data(String code, double value) {
        this.code = code;
        this.value = value;
      }
    
    }
    Then you make your Data class comparable.
    When you then put those elements into a TreeSet<Data> you are done with it all.
    Those arrays all over the place go away because you are not developing with FORTRAN.

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

    Default

    I have a different concern here in that I think that using a 2-dimensional array here is faulty design and shouldn't be done at all. An array, be it one dimensional, 2-dimensional or other dimensional should contain only one type of information, and you appear to be trying to use a 2D array to hold two completely different types of information, a double precision floating point number and a String.

    Much better would be to create a class that holds a String and a double, that implements the Comparable<T> interface with an appropriate compareTo method.

    Edit: I'm too late as it seems that r035198x has beat me to the OOPs punch! So we both agree: throw out the current code as it's following faulty logic and start over using OOPs concepts.

  15. #35
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    The fact that im usin a 2d array is because that is what I have been asked to do, it is within netbeans ide as this is the tool we use, I am aware that most people in here do not like NB but that is what I have to use, I am not on a java course, this is an element of the course.

    I am not doing maths with this array so I do not need to use a float, hence both arrays are strings, as I said earlier when I was just using a 1d array everything worked fine but now things have changed and I have been asked to use a 2d array with the additional information.

    The code below is what I used for the 1d array and as I say everything worked fine

    This one is for the highest number within the array but this will also need changing but I started with the lowest.

    Java Code:
    String[] nums={"21.675", "24.798", "16.567", "25.014",
                "32.907", "31.456", "41.876", "22.123", "20.945","20.679",
                "18.398", "17.075", "40.025", "26.564", "30.712", "29.897",
                "23.397", "35.548", "22.123", "31.398" };
                Arrays.sort(nums); // Binary sort through list of Strings
                
                txtResult.setText(nums[19]); // prints out in textfield last (largest in array)
                System.out.println("Highest Bmi Reading = " + nums[nums.length-1]);
                // Output from the sorted list for highest bmi

  16. #36
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    If I post more replies you will either ignore them or not understand them so I'm out of here.

  17. #37
    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 dbashby View Post
    The fact that im usin a 2d array is because that is what I have been asked to do,
    What are the specific requirements of the assignment?

    it is within netbeans ide as this is the tool we use, I am aware that most people in here do not like NB but that is what I have to use, I am not on a java course, this is an element of the course.
    This has absolutely nothing to do with the current problem. Why mention it?

    I am not doing maths with this array so I do not need to use a float, hence both arrays are strings, as I said earlier when I was just using a 1d array everything worked fine but now things have changed and I have been asked to use a 2d array with the additional information.
    Again: specific requirements?

    The code below is what I used for the 1d array and as I say everything worked fine
    and again, this cannot be done with a 2-D array. Does this make sense because I don't see in any of your posts that you've registered this fact at all.

    Much luck.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Problem With Dimension of Jasper Report
    By Prashant.surwade in forum Advanced Java
    Replies: 3
    Last Post: 09-19-2009, 03:29 PM
  2. applet and dimension
    By mensaFool in forum New To Java
    Replies: 5
    Last Post: 09-15-2009, 05:37 AM
  3. Replies: 5
    Last Post: 05-18-2009, 01:42 PM
  4. noob: two-dimension array
    By bobmasta5 in forum New To Java
    Replies: 5
    Last Post: 03-16-2009, 12:42 AM
  5. Arraylist to a 2- dimension array conversion
    By mars123 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 12:24 PM

Posting Permissions

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