# Université de Bordeaux

## TD5

### Interface Point2D

```
public interface Point2D {
double getAbscisse();

void setAbscisse(double x);

double getOrdonnee();

void setOrdonnee(double y);

double getModule();

void setModule(double m);

double getArgument();

void setArgument(double a);

Point2D clone();

boolean equals(Point2D o);

String toString();

Point2D translation(double dx , double dy);

Point2D homothetie(double rapport);

Point2D rotation(double angle);
}
```

### Interface ShapeStack

```public interface ShapeStack {

public boolean isEmpty();
public void pop();
public void push(Shape s);
public Shape top();

public boolean equals(ShapeStack s);
ShapeStack clone();
public String toString();
}
```

### Classe Relation

```public class Relation {
public Relation(boolean[][] tRelation) {
int n = tRelation.length;
relation = new boolean[n][n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
relation[i][j] = tRelation[i][j];
}

public boolean inRelation(int i, int j) {
return relation[i][j];
}

public boolean isReflexive() {
for (int i = 0; i < relation.length; ++i)
if (!inRelation(i, i))
return false;
return true;
}

public boolean isSymetrique() {
for (int i = 1; i < relation.length; ++i)
for (int j = 0; j < i; ++j)
if (inRelation(i, j) != inRelation(j, i))
return false;
return true;
}

public boolean isTransitive() {
int n = relation.length;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (inRelation(i, j))
for (int k = 0; k < n; ++k)
if (inRelation(j, k) && !inRelation(i, k))
return false;
return true;
}

public static Relation composed(Relation r1, Relation r2) {
int n = r1.relation.length;
boolean[][] composed = new boolean[n][n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (r1.inRelation(i, j))
for (int k = 0; k < n; ++k)
if (r2.inRelation(j, k))
composed[i][k] = true;
return new Relation(composed);
}

public int[] image(int i) {
// on determine la taille de lâ€™image
int taille = 0;
int n = relation.length;
for (int j = 0; j < n; ++j)
if (inRelation(i, j))
taille++;
int tableImage[] = new int[taille];
for (int j = 0, k = 0; j < n; ++j)
if (inRelation(i, j))
tableImage[k++] = j;
return tableImage;
}

private boolean[][] relation;
}
```