Exemple #1
0
  public static LinkedList<profile> importer() throws IOException {

    LinkedList<profile> people = new LinkedList<profile>();
    Scanner sFile;
    profile entry;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/users.dat"));
      sFile.nextLine();
      while (sFile.hasNext()) {

        String profile = sFile.nextLine();
        // System.out.println(profile);

        Scanner profScan = new Scanner(profile);
        profScan.useDelimiter(",");

        while (profScan.hasNext()) {

          Long id = profScan.nextLong();
          String ident = String.valueOf(id);
          String rot_Id = rot13.encrypt(ident);
          Long rot_IntId = Long.parseLong(rot_Id);

          String fname = profScan.next();
          String rot_Name = rot13.encrypt(fname);
          // String sname = profScan.next();
          // int age = profScan.nextInt();
          String gender = profScan.next();
          String nat = profScan.next();

          entry = new profile(id, fname, gender, nat);
          // System.out.println("id: "+id+" name: "+fname+" gender: "+gender+" nationality: "+nat);
          // System.out.println("id: "+rot_IntId+" name: "+rot_Name+" gender: "+gender+"
          // nationality: "+nat);
          people.add(entry);
        }
      }

    } catch (IOException ex) {
      // return people;

      System.out.println("(No System File profile.txt)" + ex);
    }
    return people;
  }
Exemple #2
0
 public static void main(String[] args) throws IOException {
   Scanner scanner = new Scanner(new BufferedInputStream(System.in));
   while (scanner.hasNextLine()) {
     String str = scanner.nextLine();
     if (str.equals("0")) break;
     String s[] = str.split(" ");
     int sum = 1;
     for (int i = 0; i < s.length; i += 2)
       sum = sum * (int) Math.pow(Integer.parseInt(s[i]), Integer.parseInt(s[i + 1]));
     Factorization f = new Factorization();
     System.out.println(f.answer(sum - 1));
   }
 }
Exemple #3
0
  public static void main(String[] args) throws java.lang.Exception {
    Scanner cin = new Scanner(System.in);
    while (cin.hasNext()) {
      int input = cin.nextInt();
      for (int a = 0; a < input + 1; a++) {
        if (a > 0) {
          String number = cin.nextLine();
          String[] numberArray = number.split(" ");
          int max = 0;

          for (int b = 0; b < numberArray.length; b++) {
            if (Integer.valueOf(numberArray[b]) > max) {
              max = Integer.valueOf(numberArray[b]);
            }
          }

          System.out.println("Case " + a + ": " + max);
        } else {
          String data = cin.nextLine();
        }
      }
    }
  }
Exemple #4
0
  public static void main(String[] args) {

    //// I shall master R programming
    Scanner s = new Scanner(System.in);
    System.out.println("Enter no of transactions");
    int p = s.nextInt();

    String[] data = new String[p + 1];

    int arr[] = new int[10];

    for (int i = 0; i <= 9; i++) {
      arr[i] = 0;
    }
    // s.delimiter();
    for (int i = 1; i <= p; i++) {
      String gh;
      gh = s.nextLine();
      data[i] = gh;
      char[] buff = new char[10];
      buff = gh.toCharArray();

      for (int j = 0; j < buff.length; j++) {
        int fg = (int) buff[j] - 48;
        arr[fg]++;
      }
    }
    System.out.println("Enter Min_support");
    int minsup = s.nextInt();
    for (int j = 1; j <= 9; j++) {
      if (arr[j] < minsup) {
        arr[j] = -1;
      }
    }

    for (int j = 1; j <= p; j++) {
      char[] buff = new char[10];
      buff = data[j].toCharArray();
      String fin = "";
      for (int h = 0; h < buff.length; h++) {
        int fg = ((int) buff[h]) - 48;
        if (arr[fg] != -1) {
          fin += buff[h];
        }
      }
      data[j] = fin;
      data[j] = sort(data[j], arr);
    }

    /////////// BAsic Stuff done////////////////////////////////////

    ///// FP TREE CONSTRUCTION
    trie tr = new trie();

    for (int j = 1; j <= p; j++) {
      tr.insert(data[j]);
    }
    tr.show(minsup);

    //// FP TREE Construction Done\\\\\\

    //// Now FP TREE Itemset Generation\\\\

    // trie x=new trie();

    int max = 5;
    int[] mark = new int[max + 1];
    int[] yoyo = new int[max + 1];
    for (int i = 0; i <= max; i++) {
      yoyo[i] = i + 1;
      mark[i] = 0;
    }

    int end = (int) Math.pow(2, max);
    for (int i = 1; i < end; i++) {
      mark = bringme(i, max);

      String up = "", down = "";

      for (int j = 0; j < max; j++) {

        if (mark[j] == 1) down += yoyo[j];
      }

      makeCondFP(tr, down, data, p, minsup);
    }
  }
Exemple #5
0
  public Stock(String StockSymbol) throws IOException {

    symbol = StockSymbol;

    String date = "2014-04-13";

    String url =
        "https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yql.query.multi%20WHERE%20queries%3D%27%0A%20%20%20%20"
            + "SELECT%20*%20FROM%20csv%20WHERE%20url%3D%22http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D"
            + symbol
            + "%26f%3Dl1ohgvc6a2p2m4m3%26e%3D.csv%22%0A%20%20%20%20AND%20"
            + "columns%3D%22lastPrice%2Copen%2Chigh%2Clow%2Cvolumen%2Cchange%2CavgVolumen%2CchangePer%2CMA200%2CMA50%22%3B%0A%20%20%20%20"
            + "SELECT%20Symbol%2CDate%2CClose%20FROM%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22"
            + symbol
            + "%22%20and%20startDate%20%3D%20%22"
            + date
            + "%22%20and%20endDate%20%3D%20%22now%22%0A%27%3B&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
    try {
      URL pageLocation = new URL(url);

      Scanner input = new Scanner(pageLocation.openStream());
      String webData = input.nextLine() + "\n";

      while (input.hasNextLine()) {
        webData += input.nextLine() + "\n";
      }
    } catch (MalformedURLException e) {
      System.out.printf("Error");
    }

    int startIndex, endIndex; // Here we initialize the two int variables to be used to get the data

    // Here we grab the lastest price from the xml
    startIndex = webData.indexOf("<lastPrice>");
    endIndex = webData.indexOf("</lastPrice>", startIndex);
    lastPrice = Float.parseFloat(webData.substring(startIndex + 11, endIndex));

    if (lastPrice == 0.00) {
      /* Udvikle error da aktien ikke findes */
    }

    // Here we grab the open price from the xml
    startIndex = webData.indexOf("<open>");
    endIndex = webData.indexOf("</open>", startIndex);
    open = Float.parseFloat(webData.substring(startIndex + 6, endIndex));

    // Here we grab the High price of the day from the xml
    startIndex = webData.indexOf("<high>");
    endIndex = webData.indexOf("</high>", startIndex);
    high = Float.parseFloat(webData.substring(startIndex + 6, endIndex));

    // Here we grab the Low price of the day from the xml
    startIndex = webData.indexOf("<low>");
    endIndex = webData.indexOf("</low>", startIndex);
    low = Float.parseFloat(webData.substring(startIndex + 5, endIndex));

    // Here we grab the volume
    startIndex = webData.indexOf("<volumen>");
    endIndex = webData.indexOf("</volumen>", startIndex);
    volumen = Integer.parseInt(webData.substring(startIndex + 9, endIndex));

    // Here we grab the average volume
    startIndex = webData.indexOf("<avgVolumen>");
    endIndex = webData.indexOf("</avgVolumen>", startIndex);
    avgVolumen = Integer.parseInt(webData.substring(startIndex + 12, endIndex));

    // Here we grab the change of price
    startIndex = webData.indexOf("<change>");
    endIndex = webData.indexOf("</change>", startIndex);
    change = Float.parseFloat(webData.substring(startIndex + 8, endIndex));

    // Here we grab the change of price in percent
    startIndex = webData.indexOf("<changePer>");
    endIndex = webData.indexOf("</changePer>", startIndex);
    changeInPer = Float.parseFloat(webData.substring(startIndex + 11, endIndex - 1));

    // Here we grab the 200 Moving Average
    startIndex = webData.indexOf("<MA200>");
    endIndex = webData.indexOf("</MA200>", startIndex);
    MA200 = Float.parseFloat(webData.substring(startIndex + 7, endIndex));

    // Here we grab the 200 Moving Average
    startIndex = webData.indexOf("<MA50>");
    endIndex = webData.indexOf("</MA50>", startIndex);
    MA50 = Float.parseFloat(webData.substring(startIndex + 6, endIndex));

    rsi = rsiCalculate(pastPrices);

    emas = emaCalculate(pastPrices);
  }
Exemple #6
0
  public static LinkedList<edge> importer(MatlabProxy proxy)
      throws IOException, MatlabConnectionException, MatlabInvocationException {

    Scanner sFile;
    edge entry;
    LinkedList<edge> tie = new LinkedList<edge>();
    Long k, p;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/edges.dat"));

      System.out.println(sFile.nextLine());

      while (sFile.hasNext()) {

        String edge = sFile.nextLine();
        // System.out.println(edge);

        Scanner edgeScan = new Scanner(edge);
        edgeScan.useDelimiter(",");

        while (edgeScan.hasNext()) {

          k = edgeScan.nextLong();
          System.out.print(k + " ");

          String ident_k = String.valueOf(k);
          String rot_Id_k = rot13.encrypt(ident_k);
          Long rot_k = Long.parseLong(rot_Id_k);

          p = edgeScan.nextLong();
          System.out.print(p);

          String ident_p = String.valueOf(p);
          String rot_Id_p = rot13.encrypt(ident_p);
          Long rot_p = Long.parseLong(rot_Id_p);

          // System.out.println(rot_k+" : "+rot_p);
          entry = new edge(k, p);

          int n = search.search(k);
          int m = search.search(p);
          System.out.print(
              " : "
                  + Typ_MatlabGraph.people.get(n).idProf
                  + " "
                  + Typ_MatlabGraph.people.get(m).idProf);
          System.out.println("");
          n++;
          m++;

          proxy.eval("adjMatrix(" + n + "," + m + ") = 1");

          tie.add(entry);
        }
      }

    } catch (IOException ex) {

      System.out.println("(No System File profile.txt)" + ex);
    }

    return tie;
  }
Exemple #7
0
 public void select() {
   Scanner keyboard = new Scanner(System.in);
   String user = keyboard.nextLine();
   user.toLowerCase();
   set_user(user);
 }