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

    Unhappy Help with sorting arrays

    HEY GUYS I HAVE THIS COMPLIELING BUT I CANT GET IT TOO LOOK RIGHT AND IT GOES INTO THE GETNAME() TWICE BUT I ONLY WANT TO DO IT ONCE HERE IS WHAT I WANT IT TO LOOK LIKE


    unsorted:
    Java Code:
    date      name    atachment
    ----      ------   ----------
    6          john          7
    5          kevin         8
    4          jim            4
    but i need to sort it to be like this:

    Java Code:
    date      name    atachment
    ----      ------   ----------
    4          jim            4
    5          kevin         8
    6          john           7
    AS YOU CAN SEE IT IS AN EMAIL IN VOICE BUT I NEED TO SORT THE FROM BIGGEST TO SMALLEST
    HERE IS MY CODE RUN IT AND YOU WILL SEE WHAT IT LOOK LIKE I RUNS THE NAMES TWICE WHICH I DONT WANT AND I CANT GET IT TOO LOOK RIGHT

    Java Code:
    class WS7QC
    {
    
    
        public static void main(String args[])
        {
    
           
                  System.out.print("------------------------------------------------------------------------\n");
    
    		int A[][] = new int[5][2];
    		GetArray(A);
    	    System.out.println(" ---------------------------------------------");
    		SortedArray(A);
    
    }//end of main
    	public static void GetArray(int A[][])
       {
    	System.out.println(" --------------UNSORTED_EMAIL-----------------");
    	System.out.println();
    	System.out.println(" Date:		From:		Attachments:");
    	System.out.println(" ----		-----		-----------");
    
    
    		for (int row = 0; row<A.length; row++)
    	     {
    		  for(int col = 0; col<A[row].length; col++)
    		   {
    		     A[row][col] =(int)(Math.random( )*10000) % 10+1;//generate randome nuihem in array
     			 System.out.print(" "+A[row][col]+ "\t\t\t\t  ");
    
               if(col == 0)
    			 {
    			  GetName(A,row);
    		     }
    
    		    } //end of loop
    		        System.out.println();
    		  }//end of first loop
    
    		}//end of procedure
    
    
    
      public static void GetName(int A[][],int row)
      {
    	for(int i=0;i<A[row].length;i++){
    	 switch(A[row][0])
    	  {
    		 case 1:System.out.println("  Kevin \t\t  ");break;
    		 case 2:System.out.println("  Ian \t\t  ");break;
    		 case 3:System.out.println("  Andy \t\t  ");break;
    		 case 4:System.out.println("  James \t\t  ");break;
    		 case 5:System.out.println("  Dave \t\t  ");break;
    		 case 6:System.out.println("  Conor \t\t  ");break;
    		 case 7:System.out.println("  Shane \t\t  ");break;
    		 case 8:System.out.println("   Ciarn \t\t  ");break;
    		 case 9:System.out.println("  Christian \t  ");break;
    		 case 10:System.out.println(" Barry \t\t  ");
    	  }//end of switch
    }
      }//end of procedure 'GetNmane'
    
       public static void SortedArray(int A[][])
       {
    	   System.out.println(" --------------UNSORTED_EMAIL-----------------");
    	   	System.out.println();
    	   	System.out.println(" Date:		From:		Attachments:");
    	System.out.println(" ----		-----		-----------");
    /*
    int hold,hold1,hold2,hold3,hold4;
    
        	for(int r=0; r<A.length-1; r++)
        	{
        	  for(int c=0; c<A.length-r-1; c++)
        	{
        		if (A[c][0]>A[c+1][0])
        		{
        			hold=A[c][0];
        			hold1=A[c][1];
        			hold2=A[c][2];
        			hold3=A[c][3];
        			hold4=A[c][4];
    
        			A[c][0]=A[c+1][0];
        			A[c][1]=A[c+1][1];
        			A[c][2]=A[c+1][2];
        			A[c][3]=A[c+1][3];
        			A[c][4]=A[c+1][4];
    
        			A[c+1][0]=hold;
        			A[c+1][1]=hold1;
        			A[c+1][2]=hold2;
        			A[c+1][3]=hold3;
        			A[c+1][4]=hold4;
    
        		}// end of if
        		*/
      	}//end of sort
    
    
    
    
    
    
    
    }//end of class
    as you see i need to print it first then use an other method to sort the numbers and go back in to get the names

    CAN SOMEONE PLEASE HELP
    Last edited by Joycey; 03-30-2010 at 07:38 PM.

  2. #2
    Joycey is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    Remember the sorted array method is commonts not code

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Joycey View Post
    HEY GUYS I HAVE THIS COMPLIELING BUT I CANT GET IT TOO LOOK RIGHT AND IT GOES INTO THE GETNAME() TWICE BUT I ONLY WANT TO DO IT ONCE HERE IS WHAT I WANT IT TO LOOK LIKE
    There is no reason to shout. Those date, name and attachment are details of something larger: an email specification so I had expected something like this:

    Java Code:
    public class Email {
       private int date;
       private String name;
       private int attachment;
       ...
       // constructor(s) and getters etc. go here
    }
    Next I expected a simple one dimensional array like this:

    Java Code:
    Email[] emails= ...
    You have to sort this array. The Arrays class has a sort( ... ) method that can do the job. Also read the API documentation for the Comparator interface.

    kind regards,

    Jos

  4. #4
    Joycey is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default hey

    we havent learned any of that yet

  5. #5
    Joycey is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  2. Sorting Two Arrays
    By Faye Rett in forum New To Java
    Replies: 4
    Last Post: 03-07-2010, 01:00 AM
  3. Problem: Arrays and Sorting
    By Rhez in forum New To Java
    Replies: 7
    Last Post: 02-03-2010, 02:18 PM
  4. Replies: 0
    Last Post: 01-17-2010, 06:09 AM
  5. Sorting Arrays by enum
    By sahity1a@yahoo.com in forum New To Java
    Replies: 3
    Last Post: 11-26-2009, 09:08 AM

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
  •