Guest User

Untitled

a guest
Jul 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. /**
  6. * User: Souleiman Ayoub
  7. * Date: Nov 13, 2009
  8. * Time: 3:06:17 PM
  9. */
  10. public class Main {
  11. public static void main(String[] args) throws IOException {
  12. Address[] list = new Address[getLines()];
  13. scanF(list);
  14. //compareTo(list, new Scanner(System.in));
  15. System.out.println(Arrays.toString(list));
  16. }
  17. private static void scanF(Address[] list) throws IOException { //Scans File
  18. Scanner run = new Scanner(new File("Data.txt"));
  19. for(int i = 0;i < getLines();i++){
  20. list[i] = new Address(run.nextLine());
  21. }
  22. }
  23. private static void compareTo(Address[] list, Scanner s){
  24. System.out.print("Select an option to sort:\n"+
  25. "\t1: First Name\n"+
  26. "\t2: Last Name\n"+
  27. "\t3: Street Address\n"+
  28. "\t4: City\n"+
  29. "\t5: State\n"+
  30. "\t6: Zip Code\n"+
  31. "\t0: Quit\n"+
  32. "Sort: ");
  33.  
  34. switch(s.nextInt()){
  35. case 1:
  36. for (int i = 0; i < list.length-1; i++) {
  37. int mIndex = i; // Index of smallest remaining value.
  38. for (int j=i+1; j < list.length; j++) {
  39. if (list[mIndex].getData(1).compareTo(list[j].getData(1)) > 0) {
  40. mIndex = j; // Remember index of new minimum
  41. }
  42. }
  43. if (mIndex != i) {
  44. //... Exchange current element with smallest remaining.
  45. String temp = list[i].getData(1);
  46. //First_Name[i] = First_Name[mIndex];
  47. list[mIndex].setData(1, list[i].getData(1));
  48. //First_Name[mIndex] = temp;
  49. list[mIndex].setData(1, temp);
  50. }
  51. }
  52. }
  53. }
  54. private static int getLines() throws IOException { //Gets the number of lines
  55. InputStream is = new BufferedInputStream(new FileInputStream("Data.txt"));
  56. byte[] c = new byte[1024];
  57. int count = 1;
  58. int readChars;
  59. while ((readChars = is.read(c)) != -1) {
  60. for (int i = 0; i < readChars; i++) {
  61. if (c[i] == '\n')
  62. count++;
  63. }
  64. }
  65. return count;
  66. }
  67. }
Add Comment
Please, Sign In to add comment