Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The "L" class.
- import java.awt.*;
- import hsa.*;
- public class L
- {
- static Console c; // The output console
- static TextInputFile f;
- static TextOutputFile o;
- public static String [] title = new String [20];
- public static String [] artist = new String [20];
- public static String [] label = new String [20];
- public static int [] week = new int [20];
- public static int [] national = new int [20];
- public static void main (String [] args)
- {
- c = new Console ();
- String fileName = "Unsorted_Albums.dat";
- f = new TextInputFile (fileName);
- int i = 0;
- while (!f.eof ())
- {
- title [i] = f.readString ();
- artist [i] = f.readString ();
- label [i] = f.readString ();
- week [i] = f.readInt ();
- national [i] = f.readInt ();
- i++;
- }
- f.close ();
- c.println (artist [0]);
- sortString (artist);
- c.println (artist [0]);
- write ("test");
- // Place your program here. 'c' is the output console
- } // main method
- public static void write (String name)
- {
- o = new TextOutputFile ("Sorted_Albums.dat");
- o.println (name);
- for (int j = 0 ; j < title.length - 1 ; j++)
- {
- o.print (title [j] + spaces (title[j], 33));
- o.print (artist [j] + spaces (artist[j], 24));
- o.print (label [j] + spaces (label[j], 8));
- o.print (week [j] + "\t");
- o.println (national [j]);
- }
- }
- public static String spaces (String str, int max)
- {
- max = max - str.length();
- return " " * max;
- }
- public static void sortString (String [] stringarray)
- {
- int temp;
- for (int j = 0 ; j < stringarray.length - 1 ; j++)
- {
- for (int a = 0 ; a < stringarray.length - 1 ; a++)
- {
- if (stringarray [a].compareTo (stringarray [a + 1]) > 0)
- swap (a);
- }
- }
- }
- public static void sortNum (int [] numarray)
- {
- int temp;
- for (int j = 0 ; j < numarray.length - 1 ; j++)
- {
- for (int a = 0 ; a < numarray.length - 1 ; a++)
- {
- if (numarray [a] > numarray [a + 1])
- swap (a);
- }
- }
- }
- public static void swap (int a)
- {
- int temp;
- String temp2;
- temp2 = title [a];
- title [a] = title [a + 1];
- title [a + 1] = temp2;
- temp2 = artist [a];
- artist [a] = artist [a + 1];
- artist [a + 1] = temp2;
- temp2 = label [a];
- label [a] = label [a + 1];
- label [a + 1] = temp2;
- temp = week [a];
- week [a] = week [a + 1];
- week [a + 1] = temp;
- temp = national [a];
- national [a] = national [a + 1];
- national [a + 1] = temp;
- }
- } // L class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement