Skip to content
Snippets Groups Projects
Commit 06161f69 authored by Sean THEISS's avatar Sean THEISS
Browse files

add

parent 2beb0e27
No related merge requests found
# A22
17/03/2021 : création dépot git
\ No newline at end of file
<?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>
/bin/
<?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>
package exo1;
public class Gare {
private String nom;
public String getNom() {
return nom;
}
}
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;
}
}
package exo1;
import java.util.ArrayList;
public class Horaire {
private ArrayList<Heure> heures;
public Heure getHeure(int x) {
return heures.get(x);
}
}
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 numro "+this.getNumero()+" ne passe pas par la gare "+g.getNom();
}
else {
annonce = "Le train numro "+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;
}
}
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;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment