daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Code by fictive
  2.  
  3. package oving6;
  4.  
  5. import java.io.*;
  6. import java.util.Collections;
  7. import java.util.List;
  8. import java.util.ArrayList;
  9.  
  10. public class PersonSorter {
  11.  
  12.     public static void main(String in[]) throws IOException
  13.     {
  14.         List<String> persons = new ArrayList();
  15.         String inFile = in[0];
  16.         String outFile = in[1];
  17.         String line;
  18.         String[] name;
  19.         String firstname = "", lastname = "";      
  20.        
  21.         FileReader file = new FileReader(inFile);
  22.         FileWriter write = new FileWriter(outFile);
  23.         BufferedReader buffer = new BufferedReader(file);
  24.        
  25.         line = buffer.readLine();
  26.        
  27.         while(line != null) {
  28.             if(line.charAt(0) != '#') {
  29.                 if(line.contains(",")) {
  30.                     name = line.split(",");
  31.                     lastname = name[0].replace(" ", "");
  32.                     firstname = name[1].replace(" ", "");
  33.                    
  34.                 }
  35.                 else if(line.contains("\\")) {
  36.                     firstname = line.replace(" ", "");
  37.                     lastname = buffer.readLine().replace(" ", "");
  38.                 }
  39.                 else {
  40.                     name = line.split(" ");
  41.                     firstname = name[0];
  42.                     lastname = name[1];
  43.                 }
  44.             }
  45.            
  46.             if(firstname.length() > 0 && lastname.length() > 0) {
  47.                 try {
  48.                     Person person = new Person(firstname, lastname);
  49.                     persons.add(person.getFirstName() + " " + person.getLastName());
  50.                 }
  51.                 catch(Exception e) {
  52.                 }
  53.             }
  54.            
  55.             line = buffer.readLine();
  56.            
  57.         }
  58.         Collections.sort(persons);
  59.         for(int i = 0; i < persons.size(); i++) {
  60.             write.write(persons.get(i).toString() + "\n");
  61.         }
  62.         write.close();
  63.     }
  64.    
  65.     public static String removeBlankSpace(String str)
  66.     {
  67.         return str.replaceAll(" ", "");
  68.     }  
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top