Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. package nameSort;
  2. /*
  3. * Joshua Padgett
  4. * ask the user to enter a name they wish to look up and
  5. * display all of the data that goes along with it
  6. */
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class Main {
  11.  
  12. public static void main(String[] args) throws IOException {
  13.  
  14. NameSort<> ns = new NameSort();
  15. Scanner kybd = new Scanner(System.in);
  16. String inputs = "";
  17. String yOrN = "";
  18. int index = 0;
  19.  
  20. ArrayList<NameInfo> nameList = new ArrayList<>();
  21. //Scanner input = new Scanner(new File("LastNames2000Census.txt"));
  22. Scanner input = new Scanner(new File("hi.txt"));
  23. String inString;
  24. NameInfo nextNameInfo;
  25. String[] nextString;
  26. String nextName;
  27. int nextRank;
  28. int nextCount;
  29. double nextProp100k;
  30. double nextCumProp100k;
  31.  
  32. while(input.hasNextLine()){
  33. inString = input.nextLine();
  34. nextString = inString.split(",");
  35. nextName = nextString[0];
  36. nextRank = Integer.parseInt(nextString[1]);
  37. nextCount = Integer.parseInt(nextString[2]);
  38. nextProp100k = Double.parseDouble(nextString[3]);
  39. nextCumProp100k = Double.parseDouble(nextString[4]);
  40. nextNameInfo = new NameInfo(nextName, nextRank, nextCount, nextProp100k, nextCumProp100k);
  41. nameList.add(nextNameInfo);
  42. }//while
  43. input.close();
  44.  
  45.  
  46. ns.insertionSort(nameList);
  47.  
  48.  
  49.  
  50. for(int i = 0; i< nameList.size(); i++){
  51. System.out.println(nameList.get(i));
  52. }
  53.  
  54. do{
  55. System.out.println("Please enter the name you wish to look up.");
  56. inputs = kybd.nextLine().toUpperCase();
  57.  
  58. //ns.binarySearch(input);
  59.  
  60. if(index == -1){
  61. System.out.println("The name you have enetered could not be found.");
  62. }else{
  63.  
  64. }
  65.  
  66. System.out.println("Would you like to enter another name?");
  67. yOrN = kybd.nextLine().toUpperCase();
  68. }while(yOrN.charAt(0) == 'Y');
  69.  
  70. kybd.close();
  71. System.exit(0);
  72. }//main
  73. }//Main
  74.  
  75.  
  76. import java.util.*;
  77.  
  78. public class NameSort<T> implements Comparable<T>{
  79.  
  80.  
  81. public NameSort(){
  82.  
  83. }// NameSort
  84.  
  85. public <T extends Comparable<T>> void insertionSort(ArrayList<T> names) {
  86. T newValue;
  87. int scan;
  88.  
  89. for (int i = 1; i < names.size(); i++) {
  90. newValue = names.get(i);
  91.  
  92. scan = i - 1;
  93. while(scan >= 0 && newValue.compareTo(names.get(scan)) < 0) {
  94. names.set(scan + 1, names.get(scan));
  95. scan--;
  96. }//while
  97. names.set(scan + 1, newValue);
  98. }//for
  99. }// insertionSort
  100.  
  101. @Override
  102. public int compareTo(T o) {
  103. // TODO Auto-generated method stub
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement