Rubric:
-View Alphabetical list by last name
-View list sorted by name of city
-view list sorted by zip code
(the data can be built into the program so you don't need to enter it upon running it)
Names: Address: City:
Barney Fife------10 Warbler Rd.----------Mountainville, SC 34765
William Clinton--1600 Pennsylvania Ave.--Washington, DC 44623
Cruella Deville--123 Witchey Way---------Hollywood Ca 12345
Sally Smith------3862 Street Blvd.-------Springfield, IL 31733
Marsha Brady-----1970 Groovy Street------Arlington, VA 51266
Gomez Addams-----1 Spooky Circle---------Tombstone, AZ 63341
John Adams-------3445 President Plaza----New York, NY 11220
Marie Antoinette-2 Rue Morgue------------New Orleans, LA 25993
Albert Einstein--7 Relativity Rd.--------Topeka KS 63121
Mick Jagger------100 Rolling Stone Path--Seattle, WA 23733
Mickey Mouse-----2 Disney Lane-----------Orlando, FL 72272
Here is what code I have so far. I can only figure out how to sort the names.
package datasorting;
public class datasorting {
String[ ] names = {"Barney Fife", "William Clinton", "Cruella Deville", "Sally Smith", "Marsha Brady", "Gomez Addams", "John Adams", "Marie Antoinette", "Albert Einstein", "Mick Jagger", "Mickey Mouse"};
sortStringBubble (names);
for ( int k = 0; k < 4; k++ )
System.out.println( names [ k ] );
}
public static void sortStringBubble( String x [ ] )
{
int j;
boolean flag = true; // will determine when the sort is finished
String temp;
while ( flag )
{
flag = false;
for ( j = 0; j < x.length - 1; j++ )
{
if ( x [ j ].compareToIgnoreCase( x [ j+1 ] ) > 0 )
{ // ascending sort
temp = x [ j ];
x [ j ] = x [ j+1]; // swapping
x [ j+1] = temp;
flag = true;
}
}
}
}
}
This post has been edited by macosxnerd101: 27 January 2016 - 09:20 PM
Reason for edit:: Renamed title to reflect the language. Java != JavaScript. Also, post your code *between* the code tags.

New Topic/Question
Reply


MultiQuote






|