"depot M213"

This commit is contained in:
JunkJumper
2020-05-03 14:24:13 +02:00
parent 1408744dbb
commit e5983242c6
136 changed files with 161184 additions and 0 deletions

64
TD3 src/segments/Segment.java Executable file
View File

@ -0,0 +1,64 @@
package segments;
import Coords.Coords;
public class Segment {
private Coords origine;
private Coords extremite;
public Segment(Coords debut, Coords fin) throws RuntimeException {
if (debut.equals(fin) == true)
throw new RuntimeException("Points confondus");
origine = new Coords(debut);
extremite = new Coords(fin);
}
public Coords getOrigine() {
return this.origine;
}
public Coords getExtremite() {
return this.extremite;
}
public double length() {
return this.origine.getDistance(this.extremite);
}
public Segment projX() {
Segment projetX = new Segment(this.origine.projx(), this.extremite.projx());
return projetX;
}
public Segment projY() {
Segment projetY = new Segment(this.origine.projY(), this.extremite.projY());
return projetY;
}
public boolean equals(Segment deux) {
if (this.origine.equals(deux.origine) && this.extremite.equals(deux.extremite)) {
return true;
} else if (this.origine.equals(deux.extremite) && this.extremite.equals(deux.origine)){
return true;
} else {
return false;
}
}
public Segment clone() {
Segment clonage = new Segment(this.origine, this.extremite);
return clonage;
}
public String toString() {
return "Le point d'origine à pour coordonnées "+this.origine.toString()+" et le point d'extremite à pour coordonnées "+this.extremite.toString();
}
}

View File

@ -0,0 +1,34 @@
package segments;
import Coords.Coords;
public class TestSegment {
public static void main(String[] args) {
Coords p11 = new Coords(12.2, 8.3);
Coords p12 = new Coords(21.1, 6.5);
Coords p32 = new Coords(45.5, 8.6);
Segment s1 = new Segment(p11, p12);
Segment s2 = s1.clone();
Segment s3 = null;
try {
s3 = new Segment(p11, new Coords(45.5, 8.6));
} catch (RuntimeException e) {
e.getMessage();
}
assert (s1.equals(s2) == true);
assert (s1.equals(s3) == false);
assert (s3.getExtremite().equals(p32) == true);
assert (s3.length() == 33.30135);
assert (s3.projX().equals(new Segment(p11.projx(), p32.projx())));
//Segment err = new Segment(p11, p11);
System.out.println("fin du programme");
}
}