diff --git a/README.md b/README.md index d064d823cf5924a9ec5165bbd3172eddff6f1481..2c7e36d37217ab7d4e90c597f8d7d5633c7c93c3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # A22 +17/03/2021 : création dépot git \ No newline at end of file diff --git a/TD1/.classpath b/TD1/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..fb5011632c0ab8d6649a148c6fb5845a1b34c747 --- /dev/null +++ b/TD1/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/TD1/.gitignore b/TD1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ae3c1726048cd06b9a143e0376ed46dd9b9a8d53 --- /dev/null +++ b/TD1/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TD1/.project b/TD1/.project new file mode 100644 index 0000000000000000000000000000000000000000..1b02d005fa03d935fe0f95b376d08da06b3821e8 --- /dev/null +++ b/TD1/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>td_1</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/TD1/src/exo1/Gare.java b/TD1/src/exo1/Gare.java new file mode 100644 index 0000000000000000000000000000000000000000..2be2006524fa4d77abd8bf49cf8fcf6acba4f4ae --- /dev/null +++ b/TD1/src/exo1/Gare.java @@ -0,0 +1,9 @@ +package exo1; + +public class Gare { + private String nom; + + public String getNom() { + return nom; + } +} diff --git a/TD1/src/exo1/Heure.java b/TD1/src/exo1/Heure.java new file mode 100644 index 0000000000000000000000000000000000000000..e29f600d909b11225ba9dd289d2ac3bf8d49100d --- /dev/null +++ b/TD1/src/exo1/Heure.java @@ -0,0 +1,18 @@ +package exo1; + +public class Heure { + private int heures; + private int minutes; + public String toString() { + String time=""; + if (heures<10) { + time=time+"0"; + } + time=time+heures+"h"; + if (minutes<10) { + time=time+"0"; + } + time = time+minutes; + return time; + } +} diff --git a/TD1/src/exo1/Horaire.java b/TD1/src/exo1/Horaire.java new file mode 100644 index 0000000000000000000000000000000000000000..7576a50abe8c93e15be0822d1695fe639494058f --- /dev/null +++ b/TD1/src/exo1/Horaire.java @@ -0,0 +1,11 @@ +package exo1; + +import java.util.ArrayList; + +public class Horaire { + private ArrayList<Heure> heures; + + public Heure getHeure(int x) { + return heures.get(x); + } +} diff --git a/TD1/src/exo1/Train.java b/TD1/src/exo1/Train.java new file mode 100644 index 0000000000000000000000000000000000000000..3b7d0296c09df857547d090ba88ede7fdff69d50 --- /dev/null +++ b/TD1/src/exo1/Train.java @@ -0,0 +1,31 @@ +package exo1; + +public class Train { + private int numero; + private Horaire horaire; + private Trajet trajet; + + public String annoncerTrain(Gare g) { + int x = getTrajet().positionDansTrajet(g); // indice de la gare dans le trajet + String annonce; + if (x == -1) { + annonce = "Le train numéro "+this.getNumero()+" ne passe pas par la gare "+g.getNom(); + } + else { + annonce = "Le train numéro "+this.getNumero()+" partant de "+this.getTrajet().getGare(0)+" et en dirrection de "+this.getTrajet().getGare(this.getTrajet().getNbGares())+" partira de la gare "+g.getNom()+" à "+this.getHoraire().getHeure(x).toString(); + } + return annonce; + } + + public Horaire getHoraire() { + return horaire; + } + + public int getNumero() { + return numero; + } + + public Trajet getTrajet() { + return trajet; + } +} diff --git a/TD1/src/exo1/Trajet.java b/TD1/src/exo1/Trajet.java new file mode 100644 index 0000000000000000000000000000000000000000..fc067b77b84202105c0838fa94f0cef4a9bbd38d --- /dev/null +++ b/TD1/src/exo1/Trajet.java @@ -0,0 +1,33 @@ +package exo1; + +import java.util.ArrayList; + +public class Trajet { + private ArrayList<Gare> gares; + public int positionDansTrajet(Gare g) { + int x = 0; + if (this.getGares().contains(g)) { + boolean test = true; + for (int i=0;i<this.getNbGares() && test;i++) { + if (this.getGare(i) == g) { + x = i; + test = false; + } + } + } + else { + x = -1; + } + return x; + } + public Gare getGare(int i) { + return gares.get(i); + } + public int getNbGares() { + return gares.size(); + } + public ArrayList<Gare> getGares() { + + return gares; + } +}