Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- public class Algorithms {
- public int simpleCoolAlg(String str){
- String s = "Likes:";
- int i = s.length();
- int popularity = 0;
- int posts = 0;
- while(str.lastIndexOf(s) != -1){
- int k = str.indexOf(s);
- String string = str.substring(k + i);
- string = string.substring(1);
- String temp = (string.substring(0, string.indexOf(" ")));
- popularity += Integer.parseInt(temp);
- str = str.substring(str.indexOf(temp) + temp.length() + 1);
- posts++;
- }
- popularity /= posts;
- return popularity;
- }
- public static ArrayList<ArrayList<String>> breakFile(ArrayList<String> str){
- ArrayList<ArrayList<String>> obj = new ArrayList<ArrayList<String>>();
- char ch = '"';
- int i = 1;
- for (String s: str){
- int temp = s.indexOf(ch);
- ArrayList<String> stringTemp = new ArrayList<String>();
- int temp2 = s.substring(temp + 1).indexOf(ch);
- temp2 += temp + 1;
- String string = s.substring(temp, temp2 + 1);
- stringTemp.add(string);
- s = s.substring(temp2 + 1);
- temp = s.indexOf(" ");
- temp2 = s.substring(temp + 1).indexOf(" ");
- string = s.substring(temp + 1, temp2 + 1);
- stringTemp.add(string);
- s = s.substring(temp2 + 1);
- temp = s.indexOf(" ");
- temp2 = s.substring(temp + 1).indexOf(" ");
- string = s.substring(temp + 1, temp2 + 1);
- stringTemp.add(string);
- s = s.substring(temp2 + 1);
- temp = s.indexOf(" ");
- temp2 = s.substring(temp + 1).indexOf(" ");
- string = s.substring(temp + 1, temp2 + 1);
- stringTemp.add(string);
- s = s.substring(temp2 + 1);
- temp = s.indexOf(" ");
- temp2 = s.substring(temp + 1).indexOf(" ");
- string = s.substring(temp + 1, temp2 + 1);
- stringTemp.add(string);
- s = s.substring(temp2 + 1);
- stringTemp.add(s);
- obj.add(stringTemp);
- }
- return obj;
- }
- public ArrayList<String> readFile(String fName) throws IOException{
- String stuff = " ";
- File file = new File(fName);
- FileReader fr = new FileReader(file);
- ArrayList<String> s = new ArrayList<String>();
- @SuppressWarnings("resource")
- BufferedReader read = new BufferedReader(fr);
- while ((stuff = read.readLine()) != null){
- s.add(stuff);
- }
- return s;
- }
- public static ArrayList<String> breakDown(Person p){
- ArrayList<String > broken = new ArrayList<String>();
- ArrayList<String> person = p.getStatus();
- for (String s: person){
- while (s.indexOf(" ") != -1){
- int temp = s.indexOf(" ");
- broken.add(s.substring(0, temp));
- s = s.substring(temp + 1);
- }
- }
- return broken;
- }
- public static Person algorithms(Person p, ArrayList<ArrayList<String>> strList){
- for (int i = 0; i < p.getStatus().size(); i++){
- //System.out.println(p.getStatus().get(i));
- for (int j = 0; j < strList.size(); j++){
- //if status word == keyword
- //System.out.println(p.getStatus().get(i));
- //System.out.println(strList.get(j).get(0));
- if (p.getStatus().get(i).equals(strList.get(j).get(0))){
- ArrayList<Double> dList = new ArrayList<Double>();
- for (int a = 1; a <= 5; a++){
- //add the doubles into list
- dList.add((Double)Double.parseDouble(strList.get(j).get(a)));
- }
- //modify person
- p.addExtrav(dList.get(0));
- p.addNeuro(dList.get(1));
- p.addAgree(dList.get(2));
- p.addConsc(dList.get(3));
- p.addOpen(dList.get(4));
- for (int b = 0; b < 5; b++){
- System.out.println(dList.get(b));
- }
- }
- }
- }
- return p;
- }
- public static ArrayList<ArrayList<String>> removeQuotesAndToLowerCase(ArrayList<ArrayList<String>> str){
- for(ArrayList<String> string: str){
- for (String s: string){
- if (s.indexOf('"') != -1){
- s = s.substring(1, s.length() - 1);
- s = s.toLowerCase();
- }
- }
- }
- return str;
- }
- public static Person toLowerCase(Person p){
- ArrayList<String> str = p.getStatus();
- for (String s: str)
- s = s.toLowerCase();
- p.setStatus(str);
- return p;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement