Advertisement
markgrenader

Client.java

Aug 5th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Random;
  7.  
  8.  
  9.  
  10.  
  11. public class Client {
  12.  
  13.     static String txt = "";
  14.     private static ArrayList<String> status = new ArrayList<String>();
  15.    
  16.     @SuppressWarnings("static-access")
  17.     public static void main(String []args) throws IOException{
  18.        
  19.         Algorithms algo = new Algorithms();
  20.        
  21.         //create();
  22.         ArrayList<String> x = algo.readFile("Category.txt");
  23.         //p(x);
  24.        
  25.         ArrayList<ArrayList<String>> categories = (Algorithms.breakFile(x));
  26.         //p("Coolness: " + (temp / 1.50) + "%");
  27.        
  28.         txt = readFiles("markstatus.txt");
  29.         sort(txt);
  30.         status.remove(status.size() - 1);
  31. //      for (int i = 0; i < status.size(); i++){
  32. //          System.out.println(status.get(i));
  33. //      }
  34. //      System.out.println(status.size());
  35.        
  36.  
  37.         String name = findName(txt);
  38.        
  39.        
  40.         Person person = new Person(name, status);
  41.         ArrayList<String> words = (algo.breakDown(person));
  42.         person.setStatus(words);
  43.         //person.getStatus().add("\"Death\"");
  44.         //person.getStatus().add("\"Achieve\"");
  45.        
  46.         categories = Algorithms.removeQuotesAndToLowerCase(categories);
  47.         person = Algorithms.toLowerCase(person);
  48.         System.out.println(person.getStatus());
  49.         //person = Algorithms.algorithms(person, categories);
  50.     }
  51.    
  52.    
  53.    
  54.    
  55.    
  56.    
  57.     public ArrayList<String> getStatus(){
  58.         return status;
  59.        
  60.     }
  61.     public static String findName(String txt){
  62.         int temp = txt.indexOf("\"name\": ");
  63.         int l = "\"name\": ".length();
  64.         String name = txt.substring(temp + l, temp + 100);
  65.        
  66.         temp = name.substring(1).indexOf("\"");
  67.         temp += 1;
  68.         name = name.substring(1, temp);
  69.         return name;
  70.     }
  71.    
  72.    
  73.     public static void create(){
  74.         Random r = new Random();
  75.         p("Name: Shreyas Kalyan ");
  76.         for (int i = 0; i < 200; i++){
  77.             p(Math.abs(r.nextInt()));
  78.             p("Likes: " + r.nextInt(200) + " ");
  79.                    
  80.            
  81.         }  
  82.     }
  83.    
  84.    
  85.    
  86.    
  87.    
  88.     public static void p(Object o){
  89.         System.out.println(o);
  90.        
  91.     }
  92.    
  93.    
  94.    
  95.    
  96.     static int currindex = 0;
  97.  
  98.  
  99.     public static String readFiles(String fName) throws IOException{
  100.  
  101.         String stuff = " ";
  102.         File file = new File(fName);
  103.  
  104.         FileReader fr = new FileReader(file);
  105.         String a = new String();
  106.         @SuppressWarnings("resource")
  107.         BufferedReader read = new BufferedReader(fr);
  108.         while ((a = read.readLine()) != null){
  109.             stuff += a;
  110.  
  111.  
  112.         }
  113.  
  114.         return stuff;
  115.  
  116.  
  117.     }
  118.    
  119.     public static void sort(String txt){
  120.         int indexOfmessage = 0;
  121.         int indexOfquote1 = 0;
  122.         int indexOfquote2 = 0;
  123.        
  124.         while (indexOfmessage != 7){
  125.             indexOfmessage = txt.indexOf("message\"", currindex + 1) + 8;
  126.             indexOfquote1 = txt.indexOf("\"", indexOfmessage + 1) + 1;
  127.             indexOfquote2 = txt.indexOf("\"", indexOfquote1 + 1);
  128.            
  129.             status.add(txt.substring(indexOfquote1, indexOfquote2));
  130.            
  131.             currindex = indexOfquote2;
  132.         }
  133.     }
  134.    
  135.    
  136.    
  137.    
  138.    
  139.    
  140.    
  141.    
  142.    
  143.    
  144.    
  145.    
  146.    
  147.    
  148.    
  149.    
  150.    
  151.    
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement