1 / 6

Managing Data

Managing Data Databases Arrays, Lists, and File I/O An Array-based database public static String Artist[] = new String[ 5 ]; public static String Song[] = new String[ 5 ]; public static int length = 0 ; public static void main ( String [] args) { length = Artist.length;

Ava
Download Presentation

Managing Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Managing Data Databases Arrays, Lists, and File I/O

  2. An Array-based database public static String Artist[] = new String[5]; public static String Song[] = new String[5]; public static int length = 0; public static void main(String [] args) { length = Artist.length; Artist[0] = "System of a Down"; Song[0] = "Hypnotize"; Artist[1] = "Every Time I Die"; Song[1] = "Kill the Music"; // etc……

  3. What’s wrong with this • Two arrays must be synchronized • Filling the arrays with Artists and Songs is done IN THE CODE. Bad. • One more thing….

  4. Sorting public static void sortByArtist() { for (int y = 0; y<length; y++) { for (int z = 0; z<y; z++) { if ( Artist[z].compareTo(Artist[y]) > 0) { swap( y,z); }// end if } // end for z } // end for y } // end sort by artist

  5. Swap –permanently moves items public static void swap( int a, int b) { String temp; temp = Artist[a]; Artist[a] = Artist[b]; Artist[b] = temp; temp = Song[a]; Song[a] = Song[b]; Song[b] = temp; }

  6. Step 1 – get information from files Put all the database info into a file, rather than in your code.

More Related