コード例 #1
0
ファイル: Driver.java プロジェクト: trunkatedpig/hw
  public static void main(String[] args) {

    // Part 1
    Turtle t1, t2, t3;

    t1 = new Turtle();
    t2 = new Turtle("Larry");
    t3 = new Turtle("kevin", 100, 500);

    System.out.println("Turtle 1 is called" + " " + t1.getname());
    System.out.println("Turtle 1 is" + " " + t1.getage() + " " + "years old");
    System.out.println("Turtle 1 is going at" + " " + t1.getspeed() + " " + "mph");

    System.out.println("Turtle 2 is called" + " " + t2.getname());
    System.out.println("Turtle 2 is" + " " + t2.getage() + " " + "years old");
    System.out.println("Turtle 2 is going at" + " " + t2.getspeed() + " " + "mph");

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

    // Part 2
    Person p1;

    p1 = new Person("Vincent");

    p1.setTurtle(t1);

    System.out.println(p1.getPersonName() + "'s turtle's speed is" + " " + p1.getTurtleSpeed());
    System.out.println(p1.getPersonName() + "'s turtle's name is" + " " + p1.getPet());
  }
コード例 #2
0
ファイル: Runner.java プロジェクト: Pahan777/jmp_repo_group_1
  public static void main(String[] args) throws IOException {
    InputStream in =
        new PersonInputStream(new BufferedInputStream(new FileInputStream("d:/test.txt")));
    Person person = PersonInputStream.readPerson(in);
    System.out.println(person.getName());

    PersonOutputStream ou =
        new PersonOutputStream(new BufferedOutputStream(new FileOutputStream("d:/testout.txt")));
    ou.writePerson(person);
    ou.flush();
    ou.close();
  }
コード例 #3
0
  private void nameLengthStatistics() {
    Iterator i = Person.iterator();
    Person p;
    int l = Person.getMaxNameLength();
    int lengthTable[] = new int[l + 1];
    int j;

    System.out.println();
    // System.out.println("Name length: Number of persons");
    while (i.hasNext()) {
      p = (Person) i.next();
      lengthTable[p.getName().length()]++;
    }
    for (j = 1; j <= l; j++) {
      System.out.print(j + ": " + lengthTable[j] + "  ");
      if (j % 5 == 0) System.out.println();
    }
    System.out.println();
  }
コード例 #4
0
ファイル: Client3.java プロジェクト: yeanh16/java-workspace
  public static void main(String[] args) throws IOException {

    long start = System.currentTimeMillis();

    Socket s = new Socket("localhost", 4444);
    ObjectOutputStream toServer = new ObjectOutputStream(s.getOutputStream());

    Person p = new Person("John", 0);

    for (int id = 0; id < HowMany.times; id++) {
      p.setId(id);
      toServer.writeObject(p);

      toServer.reset();
    }

    long end = System.currentTimeMillis();
    System.out.println("Total time " + (end - start) / 1000 + "s");
  }
コード例 #5
0
    public void endElement(String namespaceURI, String localName, String rawName)
        throws SAXException {
      if (rawName.equals("author") || rawName.equals("editor")) {
        // System.out.println("End of author");

        Person p;
        if ((p = Person.searchPerson(Value)) == null) {
          p = new Person(Value);
        }
        p.increment();
        if (numberOfPersons < maxAuthorsPerPaper) persons[numberOfPersons++] = p;
        return;
      }
      if (rawName.equals("booktitle") || rawName.equals("journal")) {
        conference c;
        if ((c = conference.searchConference(Value)) == null) {
          c = new conference(Value.replaceAll("[0-9]*", ""));
        }
        c.increment();
        System.out.println("conference");
        System.out.println(c.getNumberId());
        // conference[numberOfConferences++] = c;
      }
      if (rawName.equals(recordTag)) {

        // System.out.println("End of paper");
        if (numberOfPersons == 0) return;
        Person pa[] = new Person[numberOfPersons];
        // System.out.println();
        System.out.println("author");
        for (int i = 0; i < numberOfPersons; i++) {
          pa[i] = persons[i];
          System.out.print(persons[i].getNumberId() + " ");
          persons[i] = null;
        }
        System.out.println();
        System.out.println("cutting line");
        Publication p = new Publication(key, pa, s_conference);
        numberOfPersons = 0;
      }
    }
コード例 #6
0
ファイル: Main.java プロジェクト: mohitpunjabi/spoj
  public static void main(String args[]) throws Exception {
    int testCases = Integer.parseInt(in.readLine());
    for (int i = 0; i < testCases; i++) {
      StringTokenizer tokenizer = new StringTokenizer(in.readLine());
      int n = Integer.parseInt(tokenizer.nextToken());

      Party party = new Party();
      for (int j = 0; j < n; j++) {
        Person person = new Person(j);
        tokenizer = new StringTokenizer(in.readLine());
        while (tokenizer.hasMoreTokens()) person.add(Integer.parseInt(tokenizer.nextToken()));

        party.invite(person);
      }

      output(party);
      out.println();
    }

    out.flush();
  }
コード例 #7
0
  private void publicationCountStatistics() {
    Iterator i = Person.iterator();
    Person p;
    int l = Person.getMaxPublCount();
    int countTable[] = new int[l + 1];
    int j, n;

    System.out.println();
    System.out.println("Number of publications: Number of persons");
    while (i.hasNext()) {
      p = (Person) i.next();
      countTable[p.getCount()]++;
    }
    n = 0;
    for (j = 1; j <= l; j++) {
      if (countTable[j] == 0) continue;
      n++;
      System.out.print(j + ": " + countTable[j] + "  ");
      if (n % 5 == 0) System.out.println();
    }
    System.out.println();
  }
コード例 #8
0
 public static void main(String[] args) {
   Person me = new Person("Rami", "Malek", Gender.MALE, false, true);
   List<Person> persons = new ArrayList<Person>();
   persons.add(me);
   Movie favMovie = new Movie("Mr Robot", Genre.THRILLER, 45, 9.8, persons);
   List<Movie> movies = new ArrayList<Movie>();
   movies.add(favMovie);
   try {
     BufferedWriter writeToXML = new BufferedWriter(new FileWriter(new File(filePath)));
     StringBuffer concatenateText = new StringBuffer();
     concatenateText.append("<movies>");
     concatenateText.append(favMovie.toXMLString());
     concatenateText.append(me.toXMLString());
     concatenateText.append("</movies>");
     writeToXML.write(concatenateText.toString());
     writeToXML.flush();
     writeToXML.close();
     System.out.println("Success!");
   } catch (IOException e) {
     System.out.println(e.toString());
   }
 }
コード例 #9
0
ファイル: GetOrg.java プロジェクト: dcfrancisco/orgchart
  public static void main(String args[]) throws Exception {
    String root_id = null;
    String root_name = null;
    String out_filename = null;
    int max_depth = Integer.MAX_VALUE;
    boolean print_tree = false;
    Collection all_people = new HashSet();

    Person.init();

    try {
      for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-output")) out_filename = args[++i];
        else if (args[i].equals("-depth")) max_depth = Integer.parseInt(args[++i]);
        else if (args[i].equals("-name")) root_name = args[++i];
        else if (args[i].equals("-print")) print_tree = true;
        else print_usage_and_die();
      }
    } catch (Exception e) {
      print_usage_and_die();
    }

    if (root_id == null && root_name == null) print_usage_and_die();
    if ((print_tree == false) && (out_filename == null))
      print_tree = true; // if no -p and no outfile, just print

    Person x;
    if (root_id != null) {
      x = new Person(root_id, true, 0);
    } else {
      x = new Person(root_name, false, 0);
    }
    int blanki = root_name.indexOf(" ");
    String firstName = (blanki != -1) ? root_name.substring(0, blanki) : root_name;
    Person.XMLFilename = OrgViewer.getNameByDate(new Date(), firstName);

    x.fill_reports(max_depth - 1);
    System.out.println();

    Person.add_person_and_reports_to_collection(all_people, x);
    x.find_total_reports();

    if (print_tree) {
      x.print_tree_downward(max_depth);
      x.print_XML_tree_downward(max_depth);
    }

    if (out_filename != null) {
      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out_filename));
      oos.writeObject(all_people);
    }
  }
コード例 #10
0
 public static void main(String[] args) {
   ObjectOutputStream oos = null;
   ObjectInputStream ois = null;
   try {
     // 创建一个ObjectOutputStream输入流
     oos = new ObjectOutputStream(new FileOutputStream("custom.txt"));
     Person per = new Person("孙悟空", 500);
     // 系统会per对象转换字节序列并输出
     oos.writeObject(per);
     // 创建一个ObjectInputStream输入流
     ois = new ObjectInputStream(new FileInputStream("custom.txt"));
     Person p = (Person) ois.readObject();
     System.out.println(p.getName());
   } catch (Exception ex) {
     ex.printStackTrace();
   } finally {
     try {
       if (ois != null) ois.close();
       if (oos != null) oos.close();
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
 }
コード例 #11
0
  public static void main(String[] args) {

    try (
    // 创建一个ObjectOutputStream输入流
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("mutable.txt"));
        // 创建一个ObjectInputStream输入流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("mutable.txt"))) {
      Person per = new Person("孙悟空", 500);
      // 系统会per对象转换字节序列并输出
      oos.writeObject(per);
      // 改变per对象的name实例变量
      per.setName("猪八戒");
      // 系统只是输出序列化编号,所以改变后的name不会被序列化
      oos.writeObject(per);
      Person p1 = (Person) ois.readObject(); // ①
      Person p2 = (Person) ois.readObject(); // ②
      // 下面输出true,即反序列化后p1等于p2
      System.out.println(p1 == p2);
      // 下面依然看到输出"孙悟空",即改变后的实例变量没有被序列化
      System.out.println(p2.getName());
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
コード例 #12
0
ファイル: Main.java プロジェクト: mohitpunjabi/spoj
  public void invite(Person person) {
    if (peopleInvited == 0) for (int tshirt : person.getAllTshirts()) waysBuffer[tshirt] = 1;
    else {
      for (int tshirt = 1; tshirt < Person.TSHIRT_LIMIT; tshirt++) {
        // waysToPartyWithT = ways[tshirt];
        // waysToPartyWithout = waysToParty - waysToPartyWithT;
        // ways[tshirt] = waysWithoutT * 1 + waysWithT * (totalTshirts - 1);

        if (person.has(tshirt))
          waysBuffer[tshirt] =
              ModMath.add(
                  waysToParty, ModMath.mul((long) (person.getTshirtCount() - 2), ways[tshirt]));
        else waysBuffer[tshirt] = ModMath.mul(ways[tshirt], (long) person.getTshirtCount());
      }
    }

    peopleInvited++;
    waysToParty = getNewWaysToParty(person, waysToParty);
    for (int i = 0; i < ways.length; i++) ways[i] = waysBuffer[i];

    System.err.println("Invited " + person.toString());
    for (int i = 0; i < 20; i++) System.err.print(ways[i] + " ");
    System.err.println("| " + waysToParty);
  }
コード例 #13
0
ファイル: Turtle.java プロジェクト: xgfd/SSBLD
  /*
   * Converts the Person Object into an TriG String
   * representation.
   */
  private String convertPerson(Person person, ObjectBundle bundle) {
    StringBuffer result = new StringBuffer();
    // First the uriref for the subject

    result.append(Person.getPrefixed(person.getNr(), bundle.getPublisherNum()));
    result.append("\n");

    // rdf:type
    result.append(createTriplePO(RDF.prefixed("type"), FOAF.prefixed("Person")));

    // foaf:name
    result.append(createTriplePO(FOAF.prefixed("name"), createLiteral(person.getName())));

    // foaf:mbox_sha1sum
    result.append(
        createTriplePO(FOAF.prefixed("mbox_sha1sum"), createLiteral(person.getMbox_sha1sum())));

    // bsbm:country
    result.append(
        createTriplePO(
            BSBM.prefixed("country"), createURIref(ISO3166.find(person.getCountryCode()))));

    // dc:publisher
    result.append(
        createTriplePO(DC.prefixed("publisher"), RatingSite.getPrefixed(person.getPublisher())));

    // dc:date
    GregorianCalendar date = new GregorianCalendar();
    date.setTimeInMillis(person.getPublishDate());
    String dateString = DateGenerator.formatDate(date);
    result.append(
        createTriplePOEnd(
            DC.prefixed("date"), createDataTypeLiteral(dateString, XSD.prefixed("date"))));

    return result.toString();
  }
コード例 #14
0
 public String getMotherName() {
   return mother.toString();
 }
コード例 #15
0
ファイル: Main.java プロジェクト: mohitpunjabi/spoj
 private long getNewWaysToParty(Person person, long oldWaysToParty) {
   long newWaysToParty = 0;
   for (int tshirt : person.getAllTshirts())
     newWaysToParty = ModMath.add(newWaysToParty, oldWaysToParty, -ways[tshirt]);
   return newWaysToParty;
 }
コード例 #16
0
ファイル: Turtle.java プロジェクト: xgfd/SSBLD
  /*
   * Converts the Review Object into an TriG String
   * representation.
   */
  private String convertReview(Review review, ObjectBundle bundle) {
    StringBuffer result = new StringBuffer();
    // First the uriref for the subject

    result.append(Review.getPrefixed(review.getNr(), bundle.getPublisherNum()));
    result.append("\n");

    // rdf:type
    result.append(createTriplePO(RDF.prefixed("type"), BSBM.prefixed("Review")));

    // bsbm:reviewFor
    result.append(
        createTriplePO(
            BSBM.prefixed("reviewFor"),
            Product.getPrefixed(review.getProduct(), review.getProducerOfProduct())));

    // rev:reviewer
    result.append(
        createTriplePO(
            REV.prefixed("reviewer"),
            Person.getPrefixed(review.getPerson(), review.getPublisher())));

    // dc:title
    result.append(createTriplePO(DC.prefixed("title"), createLiteral(review.getTitle())));

    // rev:text
    result.append(
        createTriplePO(
            REV.prefixed("text"),
            createLanguageLiteral(review.getText(), ISO3166.language[review.getLanguage()])));

    // bsbm:ratingX
    Integer[] ratings = review.getRatings();
    for (int i = 0, j = 1; i < ratings.length; i++, j++) {
      Integer value = ratings[i];
      if (value != null)
        result.append(
            createTriplePO(
                BSBM.getRatingPrefix(j),
                //                        createDataTypeLiteral(value.toString(),
                // XSD.prefixed("integer"))
                value.toString()));
    }

    // bsbm:reviewDate
    GregorianCalendar reviewDate = new GregorianCalendar();
    reviewDate.setTimeInMillis(review.getReviewDate());
    String reviewDateString = DateGenerator.formatDateTime(reviewDate);
    result.append(
        createTriplePO(
            BSBM.prefixed("reviewDate"),
            createDataTypeLiteral(reviewDateString, XSD.prefixed("dateTime"))));

    // dc:publisher
    result.append(
        createTriplePO(DC.prefixed("publisher"), RatingSite.getPrefixed(review.getPublisher())));

    // dc:date
    GregorianCalendar date = new GregorianCalendar();
    date.setTimeInMillis(review.getPublishDate());
    String dateString = DateGenerator.formatDate(date);
    result.append(
        createTriplePOEnd(
            DC.prefixed("date"), createDataTypeLiteral(dateString, XSD.prefixed("date"))));

    return result.toString();
  }