Пример #1
0
  public static void main(String args[]) {

    wmatrix wmatrix = new wmatrix();
    wmatrix.start();
    try {
      PrintWriter profilefout =
          new PrintWriter(
              new BufferedWriter(
                  new FileWriter(
                      "profile_"
                          + Data.kinease
                          + "_"
                          + Data.code
                          + "_"
                          + Data.windows_size
                          + ".csv")));

      profilefout.print("Position=");
      for (int j = 0; j < Data.windows_size; j++) {
        profilefout.print("," + (j - Data.windows_size / 2));
      }
      profilefout.println();

      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < Data.windows_size; j++) {
          profilefout.print("," + wm[i][j]);
        }
        profilefout.println();
      }
      profilefout.close();

    } catch (IOException ex) {

    }
  }
Пример #2
0
 public static void make_output(float Sk[])
     throws FileNotFoundException, UnsupportedEncodingException {
   PrintWriter writer = new PrintWriter("output.txt", "UTF-8");
   float temp = (float) 10.0;
   for (int i = 0; i < Sk.length; i++) {
     writer.println(String.valueOf(Sk[i]));
   }
   writer.close();
 }
Пример #3
0
  public Duder(String args[]) {

    getConnected(args);

    play();

    try {
      sin.close();
      sout.close();
      s.close();
    } catch (IOException e) {
      System.out.println(e);
    }
  }
  void run() throws Exception {
    // for this PS3, you can alter this method as you see fit

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    int TC = Integer.parseInt(br.readLine()); // there will be several test cases
    while (TC-- > 0) {
      br.readLine(); // ignore dummy blank line
      V = Integer.parseInt(br.readLine());

      StringTokenizer st = new StringTokenizer(br.readLine());
      // read rating scores, A (index 0), B (index 1), C (index 2), ..., until the V-th index
      RatingScore = new int[V];
      for (int i = 0; i < V; i++) {
        RatingScore[i] = Integer.parseInt(st.nextToken());
      }

      // clear the graph and read in a new graph as Adjacency Matrix
      AdjMatrix = new TreeMap<Integer, TreeMap<Integer, Boolean>>();
      for (int i = 0; i < V; i++) {
        st = new StringTokenizer(br.readLine());
        int k = Integer.parseInt(st.nextToken());

        TreeMap<Integer, Boolean> g = AdjMatrix.get(i);
        if (g == null) {
          g = new TreeMap<Integer, Boolean>();
          AdjMatrix.put(i, g);
        }

        while (k-- > 0) {
          int j = Integer.parseInt(st.nextToken());

          g.put(j, true);
          TreeMap<Integer, Boolean> gCon = AdjMatrix.get(j);
          if (gCon == null) {
            gCon = new TreeMap<Integer, Boolean>();
            AdjMatrix.put(j, gCon);
          }

          gCon.put(i, true);
        }
      }

      pr.println(Query());
    }
    pr.close();
  }
Пример #5
0
  /**
   * Prints the population into the specified file.
   *
   * @param fileName is the file name where the classifiers have to be printed.
   */
  public void printPopulationToFile(String fileName) {

    try {
      PrintWriter fout = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
      fout.println(macroClSum); // We write the number of macro classifiers.
      fout.println(microClSum); // We write the number of micro classifiers.
      fout.println(
          "Cond - Action  - prediction - predError - fitness - Numerosity - Experience - aSetSize - Generality - timeStamp");
      for (int i = 0; i < macroClSum; i++) {
        set[i].print(fout);
        fout.println("");
      }
      fout.close();
    } catch (IOException eio) {
      System.out.println("ERROR when writing the population to a out file. ");
    }
  } // end printPopulationToFile
Пример #6
0
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader("numtri.in"));
    PrintWriter out = new PrintWriter(new FileWriter("numtri.out"));

    int r = Integer.parseInt(in.readLine());
    final int LEN = r;
    int[] weights = new int[LEN];

    weights[0] = Integer.parseInt(in.readLine());

    search(weights, in, 1);
    insertionSort(weights, r);

    out.println(weights[r - 1]);
    in.close();
    out.close();
    System.exit(0);
  }
Пример #7
0
 public static void main(String[] args) throws IOException {
   BufferedReader f = new BufferedReader(new FileReader("treasure.in"));
   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("treasure.out")));
   StringTokenizer st = new StringTokenizer(f.readLine());
   int N = Integer.parseInt(st.nextToken());
   int[] coins = new int[N];
   for (int i = 0; i < N; i++) {
     st = new StringTokenizer(f.readLine());
     coins[i] = Integer.parseInt(st.nextToken());
   }
   int min = 0;
   int max = N - 1;
   int ans = 0;
   int other = 0;
   int counter = 0;
   while (min < max) {
     if (coins[min] > coins[max]) {
       if (counter % 2 == 0) {
         ans += coins[min];
       } else {
         other += coins[min];
       }
       min++;
     } else {
       if (counter % 2 == 0) {
         ans += coins[max];
       } else {
         other += coins[max];
       }
       max--;
     }
     counter++;
   }
   out.println(ans);
   out.close();
   System.exit(0);
 }
Пример #8
0
  /**
   * Log all test case results to file. Depend on 'log' configuration details will be log or not.
   *
   * @throws IOException
   */
  public void logToFile() throws IOException {
    /*
    // Generate file name
    String DATE_FORMAT_NOW = "yyyyMMddHHmmssmm";
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);

    //String fileName = "report-" + sdf.format(cal.getTime())+ "-" + ran.nextInt(100);
    //System.out.println("File Name is : " + oi.reportFilePath + fileName);
     *
     */

    String fileName = init.defaultReportFileName;

    // Create new file
    File reportFile = new File("C:\\" + fileName + ".csv");
    if (reportFile.exists() == false) {
      reportFile.createNewFile();
    }

    // Write log to reportFile
    FileWriter outFile = new FileWriter(reportFile, true);
    PrintWriter out = new PrintWriter(outFile, true);

    Iterator<?> stepper = oi.logList.iterator();

    while (stepper.hasNext()) {
      out.println(stepper.next());
    }

    out.close();

    System.out.println("File Name is : " + reportFile);

    // Clear logList
    oi.logList = new ArrayList<String>();
  }
Пример #9
0
  /**
   * Remove a quiz from a course. Also deletes all the quiz visualization files from the students'
   * folder who is registered in the course. Caution: vizualisation file will be deleted eventhough
   * it also relates to anther course if the student is also registered to that course. (FIX ME!)
   * Throws InvalidDBRequestException if the quiz is not registered in the course, error occured
   * during deletion, or other exception occured.
   *
   * @param quizName quiz name
   * @param courseID course id (course number + instructor name)
   * @throws InvalidDBRequestException
   */
  public void deleteQuiz(String quizName, String courseID)
      throws InvalidDBRequestException, FileFailureException {
    try {
      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      ResultSet rs;

      int count = 0;

      // check if quiz is used in the course
      rs =
          stmt.executeQuery(
              "select test_name from courseTest where test_name = '"
                  + quizName
                  + "' and course_id = '"
                  + courseID
                  + "'");
      if (!rs.next()) throw new InvalidDBRequestException("Quiz is not registered for the course");
      else {
        // remove quiz from course
        count =
            stmt.executeUpdate(
                "delete from courseTest where course_id = '"
                    + courseID
                    + "' and test_name = '"
                    + quizName
                    + "'");
        if (count != 1) throw new InvalidDBRequestException("Error occured during deletion");
        else {
          // delete quiz visualization files
          rs =
              stmt.executeQuery(
                  "select distinct unique_id, scores.user_login from scores, courseRoster "
                      + "where courseRoster.user_login = scores.user_login "
                      + "and course_id = '"
                      + courseID
                      + "' "
                      + "and test_name = '"
                      + quizName
                      + "'");
          while (rs.next()) {
            deleteVisualization(rs.getString(1), rs.getString(2), quizName);
            count =
                stmt.executeUpdate(
                    "delete from scores where unique_id = " + rs.getString(1).trim());
          }

          // rewrite the menu for the course
          rs =
              stmt.executeQuery(
                  "select distinct menu_text, name, script_type, visual_type from test t, courseTest c "
                      + "where t.name = c.test_name "
                      + "and course_id = '"
                      + courseID
                      + "'");
          PrintWriter fileOStream =
              new PrintWriter(new FileOutputStream("./html_root/cat/" + courseID + ".list"));
          while (rs.next()) {
            if (debug)
              System.out.println(
                  rs.getString(1).trim()
                      + "\n"
                      + rs.getString(2).trim()
                      + " "
                      + rs.getString(3).trim()
                      + " "
                      + rs.getString(4).trim().toLowerCase()
                      + "\n****\n");
            fileOStream.print(
                rs.getString(1).trim()
                    + "\n"
                    + rs.getString(2).trim()
                    + " "
                    + rs.getString(3).trim()
                    + " "
                    + rs.getString(4).trim().toLowerCase()
                    + "\n****\n");
          }
          fileOStream.flush();
          fileOStream.close();
        }
      }

      rs.close();
      stmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in addQuiz: " + e.getMessage());
      throw new InvalidDBRequestException("??? ");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Internal Server Error");
    } catch (Exception e) {
      System.err.println("Error in recreating menu for course: " + courseID);
      System.err.println(e.getMessage());
      throw new FileFailureException();
    }
  }
Пример #10
0
  /**
   * Add a quiz to a course if not already so. Also write the menu file for the course. Throws
   * InvalidDBRequestException if quiz already in the course, error occured during insertion, or
   * other exception occured. Throws FileFailureException if fail to append quiz to the menu.
   *
   * @param quizname the quiz name
   * @param courseID the course id (course number + instructor name)
   * @throws InvalidDBRequestException
   */
  public void addQuiz(String quizName, String courseID)
      throws InvalidDBRequestException, FileFailureException {
    try {
      Class.forName(GaigsServer.DBDRIVER);
      db =
          DriverManager.getConnection(GaigsServer.DBURL, GaigsServer.DBLOGIN, GaigsServer.DBPASSWD);

      Statement stmt = db.createStatement();
      Statement cstmt = db.createStatement();
      ResultSet rs, courseRS;

      int count = 0;

      // get quiz info
      courseRS =
          cstmt.executeQuery(
              "select menu_text, script_type, visual_type from test where name = '"
                  + quizName
                  + "'");

      // check if quiz in the database
      if (!courseRS.next())
        throw new InvalidDBRequestException("Quiz is not registered in the database");
      else {
        // check if quiz already in the course
        rs =
            stmt.executeQuery(
                "select test_name from courseTest where test_name = '"
                    + quizName
                    + "' and course_id = '"
                    + courseID
                    + "'");
        if (rs.next()) throw new InvalidDBRequestException("Quiz is already added for the course");
        else {
          count =
              stmt.executeUpdate(
                  "insert into courseTest (course_id, test_name) values ('"
                      + courseID
                      + "', '"
                      + quizName
                      + "')");
          if (count != 1) throw new InvalidDBRequestException("Error occured during insertion");
          else {
            // append quiz info to the course menu
            try {
              PrintWriter fileOStream =
                  new PrintWriter(
                      new FileOutputStream("./html_root/cat/" + courseID + ".list", true));
              if (debug)
                System.out.println(
                    courseRS.getString(1).trim()
                        + "\n"
                        + quizName
                        + " "
                        + courseRS.getString(2).trim()
                        + " "
                        + courseRS.getString(3).trim().toLowerCase()
                        + "\n****\n");
              fileOStream.print(
                  courseRS.getString(1).trim()
                      + "\n"
                      + quizName
                      + " "
                      + courseRS.getString(2).trim()
                      + " "
                      + courseRS.getString(3).trim().toLowerCase()
                      + "\n****\n");
              fileOStream.flush();
              fileOStream.close();
            } catch (Exception e) {
              System.err.println("Error in creating the menu: " + e.getMessage());
              throw new FileFailureException("Error in creating the menu: " + e.getMessage());
            }
          }
        }
      }

      courseRS.close();
      rs.close();
      stmt.close();
      cstmt.close();
      db.close();
    } catch (SQLException e) {
      System.err.println("Invalid SQL in addQuiz: " + e.getMessage());
      throw new InvalidDBRequestException("??? ");
    } catch (ClassNotFoundException e) {
      System.err.println("Driver Not Loaded");
      throw new InvalidDBRequestException("Internal Server Error");
    }
  }
Пример #11
0
  public static void exporter(LinkedList<profile> usr, MatlabProxy proxy)
      throws MatlabConnectionException, MatlabInvocationException {

    String file = "/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/rotCmp_2012.txt";
    int i = 0;

    try {

      double result;
      int index_a = 0;
      int index_b = 0;
      int item;

      FileWriter fw = new FileWriter(file);
      BufferedWriter bw = new BufferedWriter(fw);
      PrintWriter outFile = new PrintWriter(bw);

      outFile.println("nodedef>name VARCHAR,label VARCHAR,sex VARCHAR,locale VARCHAR");

      for (i = 0; i < usr.size(); i++) {

        outFile.println(
            usr.get(i).idProf
                + ","
                + usr.get(i).firstName
                + ","
                + usr.get(i).gender
                + ","
                + usr.get(i).nat);
      }

      outFile.println("edgedef>node1 VARCHAR,node2 VARCHAR");

      for (i = 0; i < usr.size(); i++) {

        System.out.println(usr.get(i).firstName + ": ");

        for (int j = 0; j < usr.size(); j++) {

          index_a = i + 1;
          index_b = j + 1;

          // result = proxy.getVariable("adjMatrix("+index_a+","+index_b+");");

          result = ((double[]) proxy.getVariable("adjMatrix(" + index_a + "," + index_b + ");"))[0];

          item = (int) result;

          // item = ((Integer)result).intValue();
          // System.out.println(result);
          if (item == 1) {

            System.out.print(" (" + usr.get(j).firstName + ") ");

            outFile.println(usr.get(i).idProf + "," + usr.get(j).idProf);
          }
        }

        System.out.println(" ");
        System.out.println(" ");
        System.out.println(" ");
        System.out.println(" ");
      }

      outFile.close();
    } catch (IOException ex) {
      System.out.println(" error : " + ex);
    }
  }
Пример #12
0
  public static void default_fn() throws IOException {
    // Declaring Socket for sending and receiving data
    DatagramSocket skt = null;
    // declaring the fields to be used
    String client_name, movie_name, time, cost, password, reply_string;
    int i, j;
    // assigning the socket a port number
    skt = new DatagramSocket(6789);
    // defining the buffer and its size
    byte[] buffer = new byte[1000];
    while (true) {
      // defining the packet to be received from client
      DatagramPacket request = new DatagramPacket(buffer, buffer.length);

      // receiving the packet
      skt.receive(request);

      // comment on the console
      System.out.println("Data received from client");

      // Thread.sleep(5000);//for error check

      // converting the message to string and then splitting it into fields divided by newline
      // character
      String[] arrayMsg = (new String(request.getData())).split("\n");
      client_name = arrayMsg[1];
      movie_name = arrayMsg[2];
      time = arrayMsg[3];
      cost = "$12";
      password = "******";

      // Composing the reply message by appending start time,cost and password
      reply_string = client_name + "\n" + movie_name + "\n" + time + "\n" + cost + "\n" + password;
      System.out.println(reply_string);
      // Thread.sleep(5000); for error check

      // converting string message to byte
      byte[] sendMsg = (reply_string).getBytes();

      // composing the data packet and sending it to the client's address and the same port the
      // client used
      DatagramPacket reply =
          new DatagramPacket(sendMsg, sendMsg.length, request.getAddress(), request.getPort());

      System.out.println("sending confirmation");

      // Thread.sleep(5000);//for error check

      // writing server log file
      PrintWriter writer = new PrintWriter("server_log.txt", "UTF-8");
      writer.println(client_name);
      writer.println(movie_name);
      writer.println(time);
      writer.close();

      // sending the data packet
      skt.send(reply);
      // Closing the server socket
      skt.close();
    }
  }