Université de Bordeaux

Licence Sciences & Technologies - Semestre 4

J1IN4W01 : Programmation 2



TD2

Classe PolygonePoint2DCartesien

public class PolygonePoint2DCartesien {
  private Point2DCartesien[] points;
  private int nombrePoints;
  
  public PolygonePoint2DCartesien(Point2DCartesien[] points) {

  }

  public Point2DCartesien[] getSommets() {

  }

  public void setSommets(Point2DCartesien[] points) {

  }

  public boolean equals(PolygonePoint2DCartesien poly) {

  }

  public PolygonePoint2DCartesien clone() {

  }

  public String toString() {

  }

}


Classe TestRelation

public class TestRelation {
  private static final int N = 11;

  private static void resultatTest(boolean condition, String nomMethode) {
    if (condition)
      System.out.println("Test " + nomMethode + " passe avec succes");
    else
      System.out.println("Erreur test " + nomMethode);
  }

  public static void main(String[] arg) {

    boolean[][] tMultipleDe = new boolean[N][N];
    tMultipleDe[0][0] = true;
    for (int i = 1; i < N; ++i) {
      tMultipleDe[i][0] = false;
      for (int j = 1; j < N; ++j)
        tMultipleDe[i][j] = (i % j == 0);
    }

    Relation multipleDe = new Relation(tMultipleDe);

    resultatTest(multipleDe.reflexive(), "reflexive");

  }
}


Classe StringDemo

public class StringDemo {
  public static long badLongString(int n) {
    long start = System.currentTimeMillis();
    String result = "";
    for (int i = 0; i < n; ++i) {
      result += 'A';
    }
    long end = System.currentTimeMillis();
    return end - start;
  }

  public static long goodLongString(int n) {
    long start = System.currentTimeMillis();

    StringBuffer result = new StringBuffer();
    for (int i = 0; i < n; ++i) {
      result.append('A');
    }
    long end = System.currentTimeMillis();
    return end - start;
  }

  public static void main(String args[]) {
    for (int i = 1024; i <= 65536; i *= 2) {
      System.out.print(" i = " + i + "\t constructing goodLongString took ");
      System.out.println(goodLongString(i) + "ms");
    }
    for (int i = 1024; i <= 65536; i *= 2) {
      System.out.print(" i = " + i + "\t constructing badLongString took ");
      System.out.println(badLongString(i) + "ms");
    }
  }
}