Click here to Skip to main content
15,794,124 members
Home / Discussions / Java
   

Java

 
AnswerRe: jfreechar tooltip not able to show Pin
Richard MacCutchan5-Dec-19 23:35
mveRichard MacCutchan5-Dec-19 23:35 
QuestionWhat is a medium-size Java open source project with really well maintained automated tests? Pin
Member 146772343-Dec-19 19:49
Member 146772343-Dec-19 19:49 
AnswerRe: What is a medium-size Java open source project with really well maintained automated tests? Pin
Richard MacCutchan4-Dec-19 0:19
mveRichard MacCutchan4-Dec-19 0:19 
GeneralHelp with a website written in Java Pin
Tim Kohl26-Nov-19 0:13
Tim Kohl26-Nov-19 0:13 
GeneralRe: Help with a website written in Java Pin
Richard MacCutchan26-Nov-19 23:59
mveRichard MacCutchan26-Nov-19 23:59 
GeneralRe: Help with a website written in Java Pin
Tim Kohl27-Nov-19 22:21
Tim 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 
QuestionHelp With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 7:15
eskomo8424-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"}


Java
<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
mveRichard MacCutchan24-Nov-19 7:23 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 7:45
eskomo8424-Nov-19 7:45 
GeneralRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 7:52
mveRichard MacCutchan24-Nov-19 7:52 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 10:09
eskomo8424-Nov-19 10:09 
GeneralRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan25-Nov-19 0:14
mveRichard MacCutchan25-Nov-19 0:14 
QuestionJavaFX Background not beeing used on a ScrollPane element [Solved] Pin
Valentinor24-Nov-19 5:48
Valentinor24-Nov-19 5:48 
AnswerSolution Pin
Valentinor27-Nov-19 7:40
Valentinor27-Nov-19 7: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
Member 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
mveRichard 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
Member 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
Member 1465076510-Nov-19 13:03 
QuestionGlobal Histogram Implementation in Java Pin
Member 146130164-Oct-19 12:37
Member 146130164-Oct-19 12:37 
AnswerRe: Global Histogram Implementation in Java Pin
phil.o4-Oct-19 23:06
professionalphil.o4-Oct-19 23:06 
QuestionBiometric attendace machine data Pin
Member 146125164-Oct-19 2:15
Member 146125164-Oct-19 2:15 
AnswerRe: Biometric attendace machine data Pin
Richard MacCutchan4-Oct-19 4:19
mveRichard MacCutchan4-Oct-19 4:19 
AnswerRe: Biometric attendace machine data Pin
Gerry Schmitz4-Oct-19 7:35
mveGerry Schmitz4-Oct-19 7:35 
QuestionNeed to develop a program on Java for desktop Pin
Ryder Weber1-Oct-19 4:32
Ryder Weber1-Oct-19 4:32 

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.