Click here to Skip to main content
14,426,461 members
   

Java

 
AnswerRe: What is a medium-size Java open source project with really well maintained automated tests? Pin
Richard MacCutchan4-Dec-19 0:19
communityengineerRichard MacCutchan4-Dec-19 0:19 
GeneralHelp with a website written in Java Pin
Tim Kohl26-Nov-19 0:13
MemberTim Kohl26-Nov-19 0:13 
GeneralMessage Closed Pin
26-Nov-19 22:57
MemberCarla Santos Alves26-Nov-19 22:57 
GeneralRe: Help with a website written in Java Pin
Richard MacCutchan26-Nov-19 23:59
communityengineerRichard MacCutchan26-Nov-19 23:59 
GeneralRe: Help with a website written in Java Pin
Tim Kohl27-Nov-19 22:21
MemberTim Kohl27-Nov-19 22:21 
GeneralRe: Help with a website written in Java Pin
Gerry Schmitz28-Nov-19 6:37
mveGerry Schmitz28-Nov-19 6:37 
QuestionMessage Closed Pin
24-Nov-19 7:42
Memberravens game24-Nov-19 7:42 
QuestionHelp With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 7:15
Membereskomo8424-Nov-19 7:15 
I am new to Java, but to expand my knowledge of it. Below is a project that I'm having a very, very difficult time completing. I need to create a method that passes in a two dimensional string array and then sorts the array by the second element.

Method sortContacts()

o Declared as a public static method, it should take a two-dimensional String array as a parameter,
and an integer value for the number of contacts in the array
o Returns nothing
o Sorts the contents of the contact list given as a parameter using the lastName as the sorting
field
o You may use any of the sorting mechanisms described in the text (bubble, insertion or selection)
o Key concept: as you implement the sort, the trick is to identify the dimension for the values you
are comparing and how they relate to the values from your loops.
o Hints:
 Do not rely on the array’s length for your loops, instead use the value from the number
of contacts
 Your temp variable will be an array of size 3, String[] temp = new String[3];
 You will need to use the string1.compareTo(string2) method to compare two strings.
My biggest problem is where to put the temp array.

Sample data: (first name, last name, phone number)

String [][] contactsArray = {

{"Emily","Watson","913-555-0001"},
{"Madison","Jacobs","913-555-0002"},
{"Joshua","Cooper","913-555-0003"},
{"Brandon","Alexander","913-555-0004"},
{"Emma","Miller","913-555-0005"},
{"Daniel","Ward","913-555-0006"},
{"Olivia","Davis","913-555-0007"},
{"Isaac","Torres","913-555-0008"},
{"Austin","Morris","913-555-0009"}


<pre>public static void sortContact(String[][] contactsArray, int numContacts) {
		// TODO Auto-generated method stub
 		
 		String[] temp = new String[3];
 		String [] words = contactsArray[3];
 		 		
 		for(int i = 0; i < numContacts-1; i++)
 		{
 		    int smallest = i;
 		    for(int j = i + 1; j < numContacts-1; j++) 
 		    {
 		    	
 		    	//Prints loop variables so I can see them before any action
 		    	System.out.println("First: "+words[j]+" " +"Second "+words[i]);
 		        if(words[j].compareTo(words[i]) < 0)
 		            smallest = j;
 		    }
 		
 		   //put the new minimum in the i-th position.
 		   
 		    //String temp = words[i];
 		    words[i] = words[smallest];
 		    words[smallest] = temp[i];
 		} 	
	}



There are tons of examples for integer arrays but not a lot for string arrays,

Any suggestions are appreciated.
AnswerRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 7:23
communityengineerRichard MacCutchan24-Nov-19 7:23 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 7:45
Membereskomo8424-Nov-19 7:45 
GeneralRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 7:52
communityengineerRichard MacCutchan24-Nov-19 7:52 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 10:09
Membereskomo8424-Nov-19 10:09 
GeneralRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan25-Nov-19 0:14
communityengineerRichard MacCutchan25-Nov-19 0:14 
QuestionJavaFX Background not beeing used on a ScrollPane element [Solved] Pin
Valentinor24-Nov-19 5:48
MemberValentinor24-Nov-19 5:48 
AnswerSolution Pin
Valentinor27-Nov-19 7:40
MemberValentinor27-Nov-19 7:40 
QuestionMessage Closed Pin
22-Nov-19 22:40
MemberMember 1466552522-Nov-19 22:40 
Question!!Please Help!! Student Needs Help It Shows me exercise/ wrong catagory moved to web dev JS Pin
Member 1465076510-Nov-19 7:04
MemberMember 1465076510-Nov-19 7:04 
QuestionRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Richard MacCutchan10-Nov-19 7:24
communityengineerRichard MacCutchan10-Nov-19 7:24 
AnswerRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Member 1465076510-Nov-19 12:15
MemberMember 1465076510-Nov-19 12:15 
AnswerRe: !!Please Help!! Student Needs Help It Shows me exercise 2 is correct but exercise 1 is not defined Pin
Member 1465076510-Nov-19 13:03
MemberMember 1465076510-Nov-19 13:03 
QuestionGlobal Histogram Implementation in Java Pin
Member 146130164-Oct-19 12:37
MemberMember 146130164-Oct-19 12:37 
AnswerRe: Global Histogram Implementation in Java Pin
phil.o4-Oct-19 23:06
mvephil.o4-Oct-19 23:06 
QuestionBiometric attendace machine data Pin
Member 146125164-Oct-19 2:15
MemberMember 146125164-Oct-19 2:15 
AnswerRe: Biometric attendace machine data Pin
Richard MacCutchan4-Oct-19 4:19
communityengineerRichard MacCutchan4-Oct-19 4:19 
AnswerRe: Biometric attendace machine data Pin
Gerry Schmitz4-Oct-19 7:35
mveGerry Schmitz4-Oct-19 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.