TD1 src fini
This commit is contained in:
parent
e675183ae8
commit
e847dce13a
@ -1,2 +1,4 @@
|
|||||||
# M213-Bases-de-la-programmation-oriente-objet
|
# M213-Bases-de-la-programmation-oriente-objet
|
||||||
M213-Bases-de-la-programmation-oriente-objet
|
|
||||||
|
Ce repo contient le contenu du module qui m'a appris à développer avec une approche objet.
|
||||||
|
Il a été initialisé avec mes codes originaux puis refait entièrement de manière plus propre et professionelle à partir du 20/05/2020.
|
||||||
|
@ -4,6 +4,6 @@ public class HelloWorld
|
|||||||
{
|
{
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
System.out.println("\nHelloWord ! :)");
|
System.out.println("HelloWord ! :)");
|
||||||
}
|
}
|
||||||
}
|
}
|
111
src/TD1/point/MainTestPoint.java
Normal file
111
src/TD1/point/MainTestPoint.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package TD1.point;
|
||||||
|
|
||||||
|
public class MainTestPoint {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Point O = new Point();
|
||||||
|
Point I = new Point(1.0, 0.0);
|
||||||
|
Point J = new Point(0.0, 1.0);
|
||||||
|
Point A = new Point(1.0, 3.5);
|
||||||
|
Point B = new Point(8.0, 20.0);
|
||||||
|
Point C = new Point(-2.0, 3.0);
|
||||||
|
Point D = new Point(1.0, 1.0);
|
||||||
|
|
||||||
|
Point A2 = new Point(A);
|
||||||
|
Point B2 = new Point(B);
|
||||||
|
Point C2 = new Point(C);
|
||||||
|
Point O2 = new Point(D);
|
||||||
|
|
||||||
|
Point A3 = new Point(A);
|
||||||
|
Point B3 = new Point(B);
|
||||||
|
Point C3 = new Point(C);
|
||||||
|
Point O3 = new Point(D);
|
||||||
|
|
||||||
|
System.out.println("\n===== Les toString() =====");
|
||||||
|
System.out.println(" O = " + O.toString());
|
||||||
|
System.out.println(" I = " + I.toString());
|
||||||
|
System.out.println(" J = " + J.toString());
|
||||||
|
System.out.println(" A = " + A.toString());
|
||||||
|
System.out.println(" B = " + B.toString());
|
||||||
|
System.out.println(" C = " + C.toString());
|
||||||
|
System.out.println(" D = " + D.toString());
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n===== Les getDistance() =====");
|
||||||
|
System.out.println("La distance O - I est de " + O.getDistance(I));
|
||||||
|
System.out.println("La distance O - J est de " + O.getDistance(J));
|
||||||
|
System.out.println("La distance J - I est de " + J.getDistance(I));
|
||||||
|
System.out.println("La distance A - B est de " + A.getDistance(B));
|
||||||
|
System.out.println("La distance B - A est de " + B.getDistance(A));
|
||||||
|
System.out.println("La distance A - C est de " + A.getDistance(C));
|
||||||
|
System.out.println("La distance C - A est de " + C.getDistance(A));
|
||||||
|
System.out.println("La distance O - D est de " + O.getDistance(D));
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n===== Les getX() et getY() =====");
|
||||||
|
System.out.println("Le getX de A est " + A.getX());
|
||||||
|
System.out.println("Le getY de A est " + A.getY());
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n===== Les ProjX() et ProjY() =====");
|
||||||
|
System.out.println("Le ProjX de A est " + A.projX());
|
||||||
|
System.out.println("Le ProjY de A est " + A.projY());
|
||||||
|
System.out.println("Le ProjX de B est " + B.projX());
|
||||||
|
System.out.println("Le ProjY de B est " + B.projY());
|
||||||
|
System.out.println("Le ProjX de O est " + O.projX());
|
||||||
|
System.out.println("Le ProjY de O est " + O.projY());
|
||||||
|
System.out.println("Le ProjX de I est " + I.projX());
|
||||||
|
System.out.println("Le ProjY de I est " + I.projY());
|
||||||
|
System.out.println("Le ProjX de J est " + J.projX());
|
||||||
|
System.out.println("Le ProjY de J est " + J.projY());
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n===== Les equals() =====");
|
||||||
|
System.out.println("A et A : " + A.equals(A));
|
||||||
|
System.out.println("O et O : " + O.equals(O));
|
||||||
|
System.out.println("I et J : " + I.equals(J));
|
||||||
|
System.out.println("J et I : " + J.equals(I));
|
||||||
|
System.out.println("B et B : " + B.equals(B));
|
||||||
|
System.out.println("C et C : " + C.equals(C));
|
||||||
|
|
||||||
|
|
||||||
|
A2.setLocation(5., 2.);
|
||||||
|
B2.setLocation(3., -2.);
|
||||||
|
C2.setLocation(6., 5.);
|
||||||
|
O2.setLocation(-5., 8.);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
A3.translate(5, 2);
|
||||||
|
B3.translate(3, -2);
|
||||||
|
C3.translate(6, 5);
|
||||||
|
O3.translate(-5, 8);
|
||||||
|
|
||||||
|
System.out.println("\nAffichage des points");
|
||||||
|
System.out.println("O : " + O.toString());
|
||||||
|
System.out.println("I : " + I.toString());
|
||||||
|
System.out.println("J : " + J.toString());
|
||||||
|
System.out.println("A : " + A.toString());
|
||||||
|
System.out.println("B : " + B.toString());
|
||||||
|
System.out.println("C : " + C.toString());
|
||||||
|
System.out.println("D : " + D.toString());
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("A2 : " + A2.toString());
|
||||||
|
System.out.println("B2 : " + B2.toString());
|
||||||
|
System.out.println("C2 : " + C2.toString());
|
||||||
|
System.out.println("O2 : " + O2.toString());
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("A3 : " + A3.toString());
|
||||||
|
System.out.println("B3 : " + B3.toString());
|
||||||
|
System.out.println("C3 : " + C3.toString());
|
||||||
|
System.out.println("O3 : " + O3.toString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -2,25 +2,34 @@ package TD1.point;
|
|||||||
|
|
||||||
public class Point
|
public class Point
|
||||||
{
|
{
|
||||||
//attributs
|
private double x;
|
||||||
public double x;
|
private double y;
|
||||||
public double y;
|
|
||||||
|
|
||||||
|
public Point() {
|
||||||
//constructeurs
|
this(0, 0);
|
||||||
public Point()
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point(double x, double y)
|
public Point(Point p) {
|
||||||
{
|
this(p.getX(), p.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point(int x, int y) {
|
||||||
|
this((double)x, (double)y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point(double x, double y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Point projX() {
|
||||||
|
return new Point(this.getX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point projY() {
|
||||||
|
return new Point(0, this.getY());
|
||||||
|
}
|
||||||
|
|
||||||
//methode d'instance
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "(X = " + this.x + " - Y = " + this.y + ")";
|
return "(X = " + this.x + " - Y = " + this.y + ")";
|
||||||
@ -28,73 +37,58 @@ public class Point
|
|||||||
|
|
||||||
public double getDistance(Point p)
|
public double getDistance(Point p)
|
||||||
{
|
{
|
||||||
double result;
|
return Math.sqrt(Math.pow(this.getX() - p.x, 2) + Math.pow(this.getY() - p.y, 2));
|
||||||
result = Math.sqrt(Math.pow(this.x - p.x, 2) + Math.pow(this.y - p.y, 2));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//accesseur en lecture
|
@Override
|
||||||
public double getX() {
|
public boolean equals(Object obj) {
|
||||||
|
Point p = (Point)obj;
|
||||||
|
if (this.x == p.x && this.y == p.y) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point clone() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void displayLocation() {
|
||||||
|
System.out.println("x = " + this.getX() + " , y = " + this.getY() + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getLocation() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Point p) {
|
||||||
|
this.setX(p.getX());
|
||||||
|
this.setY(p.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(double x, double y) {
|
||||||
|
this.setLocation(new Point(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void translate (int dx, int dy) {
|
||||||
|
this.setX(this.getX() + dx);
|
||||||
|
this.setY(this.getY() + dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setX(double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
public double getY() {
|
public double getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point projX()
|
public void setY(double y) {
|
||||||
{
|
this.y = y;
|
||||||
return new Point(this.x, 0.);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Point projY()
|
|
||||||
{
|
|
||||||
return new Point(0., this.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals (Object obj)
|
|
||||||
{
|
|
||||||
Point p = (Point)obj;
|
|
||||||
if (this.x == p.x && this.y == p.y)
|
|
||||||
return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point clone()
|
|
||||||
{
|
|
||||||
return new Point(this.x, this.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getLocation()
|
|
||||||
{
|
|
||||||
System.out.println("x = " + this.x + " , y = " + this.y + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocation(Point p)
|
|
||||||
{
|
|
||||||
p.x = this.x;
|
|
||||||
p.y = this.y;
|
|
||||||
}
|
|
||||||
public void setLocation(double x, double y)
|
|
||||||
{
|
|
||||||
x = this.x;
|
|
||||||
y = this.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void translate(int dx, int dy)
|
|
||||||
{
|
|
||||||
this.x = this.x+dx;
|
|
||||||
this.y = this.y+dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
//getters and setters
|
|
||||||
public void setX(double x) {
|
|
||||||
this.x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setY(double y) {
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package TD1.point;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class PointTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
package TD1.point;
|
|
||||||
|
|
||||||
public class TestPoint {
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
Point O = new Point();
|
|
||||||
Point I = new Point(1.0, 0.0);
|
|
||||||
Point J = new Point(0.0, 1.0);
|
|
||||||
Point A = new Point(1.0, 3.5);
|
|
||||||
Point B = new Point(8.0, 20.0);
|
|
||||||
Point C = new Point(-2.0, 3.0);
|
|
||||||
Point D = new Point(1.0, 1.0);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(" O = " + O.toString());
|
|
||||||
System.out.println(" I = " + I.toString());
|
|
||||||
System.out.println(" J = " + J.toString());
|
|
||||||
System.out.println(" A = " + A.toString());
|
|
||||||
System.out.println(" B = " + B.toString());
|
|
||||||
System.out.println(" C = " + C.toString());
|
|
||||||
System.out.println(" D = " + D.toString());
|
|
||||||
|
|
||||||
System.out.println("La distance O - I est de " + O.getDistance(I));
|
|
||||||
System.out.println("La distance O - J est de " + O.getDistance(J));
|
|
||||||
System.out.println("La distance J - I est de " + J.getDistance(I));
|
|
||||||
System.out.println("La distance A - B est de " + A.getDistance(B));
|
|
||||||
System.out.println("La distance B - A est de " + B.getDistance(A));
|
|
||||||
System.out.println("La distance A - C est de " + A.getDistance(C));
|
|
||||||
System.out.println("La distance C - A est de " + C.getDistance(A));
|
|
||||||
System.out.println("La distance O - D est de " + O.getDistance(D));
|
|
||||||
|
|
||||||
System.out.println("Le getX de A est " + A.getX());
|
|
||||||
System.out.println("Le getY de A est " + A.getY());
|
|
||||||
|
|
||||||
System.out.println("Le ProjX de A est " + A.projX());
|
|
||||||
System.out.println("Le ProjY de A est " + A.projY());
|
|
||||||
System.out.println("Le ProjX de B est " + B.projX());
|
|
||||||
System.out.println("Le ProjY de B est " + B.projY());
|
|
||||||
System.out.println("Le ProjX de O est " + O.projX());
|
|
||||||
System.out.println("Le ProjY de O est " + O.projY());
|
|
||||||
System.out.println("Le ProjX de I est " + I.projX());
|
|
||||||
System.out.println("Le ProjY de I est " + I.projY());
|
|
||||||
System.out.println("Le ProjX de J est " + J.projX());
|
|
||||||
System.out.println("Le ProjY de J est " + J.projY());
|
|
||||||
|
|
||||||
System.out.println(A.equals(A));
|
|
||||||
System.out.println(O.equals(O));
|
|
||||||
System.out.println(I.equals(J));
|
|
||||||
System.out.println(J.equals(I));
|
|
||||||
System.out.println(B.equals(B));
|
|
||||||
System.out.println(C.equals(C));
|
|
||||||
|
|
||||||
|
|
||||||
/*A.setLocation(5., 2.);
|
|
||||||
B.setLocation(3., -2.);
|
|
||||||
C.setLocation(6., 5.);
|
|
||||||
O.setLocation(-5., 8.);*/
|
|
||||||
|
|
||||||
A.translate(5, 2);
|
|
||||||
B.translate(3, -2);
|
|
||||||
C.translate(6, 5);
|
|
||||||
O.translate(-5, 8);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(A.toString());
|
|
||||||
System.out.println(B.toString());
|
|
||||||
System.out.println(C.toString());
|
|
||||||
System.out.println(O.toString());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -48,7 +48,7 @@ public class PointColore extends Point {
|
|||||||
public boolean equals (Object obj)
|
public boolean equals (Object obj)
|
||||||
{
|
{
|
||||||
Point p = (Point)obj;
|
Point p = (Point)obj;
|
||||||
if (super.x == p.x && super.y == p.y)
|
if (super.getX() == p.getX() && super.getY() == p.getY())
|
||||||
return true;
|
return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class PointColore extends Point {
|
|||||||
public boolean equals (Object obj)
|
public boolean equals (Object obj)
|
||||||
{
|
{
|
||||||
Point p = (Point)obj;
|
Point p = (Point)obj;
|
||||||
if (super.x == p.x && super.y == p.y)
|
if (super.getX() == p.getX() && super.getY() == p.getY())
|
||||||
return true;
|
return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
5
tests/TD1/TestPoint.java
Normal file
5
tests/TD1/TestPoint.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package TD1;
|
||||||
|
|
||||||
|
public class TestPoint {
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user