Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Arrays;
- import java.util.Scanner;
- /**
- * User: Souleiman Ayoub
- * Date: Nov 13, 2009
- * Time: 3:06:17 PM
- */
- public class Main {
- public static void main(String[] args) throws IOException {
- Address[] list = new Address[getLines()];
- scanF(list);
- //compareTo(list, new Scanner(System.in));
- System.out.println(Arrays.toString(list));
- }
- private static void scanF(Address[] list) throws IOException { //Scans File
- Scanner run = new Scanner(new File("Data.txt"));
- for(int i = 0;i < getLines();i++){
- list[i] = new Address(run.nextLine());
- }
- }
- private static void compareTo(Address[] list, Scanner s){
- System.out.print("Select an option to sort:\n"+
- "\t1: First Name\n"+
- "\t2: Last Name\n"+
- "\t3: Street Address\n"+
- "\t4: City\n"+
- "\t5: State\n"+
- "\t6: Zip Code\n"+
- "\t0: Quit\n"+
- "Sort: ");
- switch(s.nextInt()){
- case 1:
- for (int i = 0; i < list.length-1; i++) {
- int mIndex = i; // Index of smallest remaining value.
- for (int j=i+1; j < list.length; j++) {
- if (list[mIndex].getData(1).compareTo(list[j].getData(1)) > 0) {
- mIndex = j; // Remember index of new minimum
- }
- }
- if (mIndex != i) {
- //... Exchange current element with smallest remaining.
- String temp = list[i].getData(1);
- //First_Name[i] = First_Name[mIndex];
- list[mIndex].setData(1, list[i].getData(1));
- //First_Name[mIndex] = temp;
- list[mIndex].setData(1, temp);
- }
- }
- }
- }
- private static int getLines() throws IOException { //Gets the number of lines
- InputStream is = new BufferedInputStream(new FileInputStream("Data.txt"));
- byte[] c = new byte[1024];
- int count = 1;
- int readChars;
- while ((readChars = is.read(c)) != -1) {
- for (int i = 0; i < readChars; i++) {
- if (c[i] == '\n')
- count++;
- }
- }
- return count;
- }
- }
Add Comment
Please, Sign In to add comment