Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nameSort;
- /*
- * Joshua Padgett
- * ask the user to enter a name they wish to look up and
- * display all of the data that goes along with it
- */
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- NameSort<> ns = new NameSort();
- Scanner kybd = new Scanner(System.in);
- String inputs = "";
- String yOrN = "";
- int index = 0;
- ArrayList<NameInfo> nameList = new ArrayList<>();
- //Scanner input = new Scanner(new File("LastNames2000Census.txt"));
- Scanner input = new Scanner(new File("hi.txt"));
- String inString;
- NameInfo nextNameInfo;
- String[] nextString;
- String nextName;
- int nextRank;
- int nextCount;
- double nextProp100k;
- double nextCumProp100k;
- while(input.hasNextLine()){
- inString = input.nextLine();
- nextString = inString.split(",");
- nextName = nextString[0];
- nextRank = Integer.parseInt(nextString[1]);
- nextCount = Integer.parseInt(nextString[2]);
- nextProp100k = Double.parseDouble(nextString[3]);
- nextCumProp100k = Double.parseDouble(nextString[4]);
- nextNameInfo = new NameInfo(nextName, nextRank, nextCount, nextProp100k, nextCumProp100k);
- nameList.add(nextNameInfo);
- }//while
- input.close();
- ns.insertionSort(nameList);
- for(int i = 0; i< nameList.size(); i++){
- System.out.println(nameList.get(i));
- }
- do{
- System.out.println("Please enter the name you wish to look up.");
- inputs = kybd.nextLine().toUpperCase();
- //ns.binarySearch(input);
- if(index == -1){
- System.out.println("The name you have enetered could not be found.");
- }else{
- }
- System.out.println("Would you like to enter another name?");
- yOrN = kybd.nextLine().toUpperCase();
- }while(yOrN.charAt(0) == 'Y');
- kybd.close();
- System.exit(0);
- }//main
- }//Main
- import java.util.*;
- public class NameSort<T> implements Comparable<T>{
- public NameSort(){
- }// NameSort
- public <T extends Comparable<T>> void insertionSort(ArrayList<T> names) {
- T newValue;
- int scan;
- for (int i = 1; i < names.size(); i++) {
- newValue = names.get(i);
- scan = i - 1;
- while(scan >= 0 && newValue.compareTo(names.get(scan)) < 0) {
- names.set(scan + 1, names.get(scan));
- scan--;
- }//while
- names.set(scan + 1, newValue);
- }//for
- }// insertionSort
- @Override
- public int compareTo(T o) {
- // TODO Auto-generated method stub
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement