Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. // The "L" class.
  2. import java.awt.*;
  3. import hsa.*;
  4.  
  5. public class L
  6. {
  7. static Console c; // The output console
  8. static TextInputFile f;
  9. static TextOutputFile o;
  10.  
  11. public static String [] title = new String [20];
  12. public static String [] artist = new String [20];
  13. public static String [] label = new String [20];
  14. public static int [] week = new int [20];
  15. public static int [] national = new int [20];
  16.  
  17. public static void main (String [] args)
  18. {
  19. c = new Console ();
  20.  
  21. String fileName = "Unsorted_Albums.dat";
  22. f = new TextInputFile (fileName);
  23. int i = 0;
  24. while (!f.eof ())
  25. {
  26. title [i] = f.readString ();
  27. artist [i] = f.readString ();
  28. label [i] = f.readString ();
  29. week [i] = f.readInt ();
  30. national [i] = f.readInt ();
  31. i++;
  32. }
  33. f.close ();
  34. c.println (artist [0]);
  35. sortString (artist);
  36. c.println (artist [0]);
  37. write ("test");
  38.  
  39.  
  40. // Place your program here. 'c' is the output console
  41. } // main method
  42.  
  43.  
  44. public static void write (String name)
  45. {
  46. o = new TextOutputFile ("Sorted_Albums.dat");
  47. o.println (name);
  48. for (int j = 0 ; j < title.length - 1 ; j++)
  49. {
  50. o.print (title [j] + spaces (title[j], 33));
  51. o.print (artist [j] + spaces (artist[j], 24));
  52. o.print (label [j] + spaces (label[j], 8));
  53. o.print (week [j] + "\t");
  54. o.println (national [j]);
  55. }
  56. }
  57.  
  58.  
  59. public static String spaces (String str, int max)
  60. {
  61. max = max - str.length();
  62. return " " * max;
  63. }
  64.  
  65.  
  66. public static void sortString (String [] stringarray)
  67. {
  68. int temp;
  69. for (int j = 0 ; j < stringarray.length - 1 ; j++)
  70. {
  71. for (int a = 0 ; a < stringarray.length - 1 ; a++)
  72. {
  73. if (stringarray [a].compareTo (stringarray [a + 1]) > 0)
  74. swap (a);
  75. }
  76. }
  77. }
  78.  
  79.  
  80. public static void sortNum (int [] numarray)
  81. {
  82. int temp;
  83. for (int j = 0 ; j < numarray.length - 1 ; j++)
  84. {
  85. for (int a = 0 ; a < numarray.length - 1 ; a++)
  86. {
  87. if (numarray [a] > numarray [a + 1])
  88. swap (a);
  89. }
  90. }
  91. }
  92.  
  93.  
  94. public static void swap (int a)
  95. {
  96. int temp;
  97. String temp2;
  98. temp2 = title [a];
  99. title [a] = title [a + 1];
  100. title [a + 1] = temp2;
  101. temp2 = artist [a];
  102. artist [a] = artist [a + 1];
  103. artist [a + 1] = temp2;
  104. temp2 = label [a];
  105. label [a] = label [a + 1];
  106. label [a + 1] = temp2;
  107. temp = week [a];
  108. week [a] = week [a + 1];
  109. week [a + 1] = temp;
  110. temp = national [a];
  111. national [a] = national [a + 1];
  112. national [a + 1] = temp;
  113. }
  114. } // L class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement