TD2 ex3 ok
This commit is contained in:
parent
4998bff3f8
commit
625df08e47
77
src/TD2/jourDeLaSemaine/JourSemaine.java
Normal file
77
src/TD2/jourDeLaSemaine/JourSemaine.java
Normal file
@ -0,0 +1,77 @@
|
||||
package TD2.jourDeLaSemaine;
|
||||
|
||||
public class JourSemaine {
|
||||
|
||||
public final String[] JOURS = {"lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"};
|
||||
// 0 1 2 3 4 5 6
|
||||
public int jour;
|
||||
|
||||
public JourSemaine() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public JourSemaine(int j) {
|
||||
this.setJour(j);
|
||||
}
|
||||
|
||||
public JourSemaine(String s) {
|
||||
int j;
|
||||
switch (s.toLowerCase()) {
|
||||
case "mardi":
|
||||
j = 1;
|
||||
break;
|
||||
case "mercredi":
|
||||
j = 2;
|
||||
break;
|
||||
case "jeudi":
|
||||
j = 3;
|
||||
break;
|
||||
case "vendredi":
|
||||
j = 4;
|
||||
break;
|
||||
case "samedi":
|
||||
j = 5;
|
||||
break;
|
||||
case "dimanche":
|
||||
j = 6;
|
||||
break;
|
||||
default:
|
||||
j = 0;
|
||||
break;
|
||||
}
|
||||
this.setJour(j);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getJour(this.getNumero());
|
||||
}
|
||||
|
||||
public JourSemaine veille() {
|
||||
if(this.getNumero() == 0) {
|
||||
return new JourSemaine(6);
|
||||
} else {
|
||||
return new JourSemaine(this.getNumero()-1);
|
||||
}
|
||||
}
|
||||
|
||||
public JourSemaine lendemain() {
|
||||
if(this.getNumero() == 6) {
|
||||
return new JourSemaine(0);
|
||||
} else {
|
||||
return new JourSemaine(this.getNumero()+1);
|
||||
}
|
||||
}
|
||||
|
||||
public int getNumero() {
|
||||
return jour;
|
||||
}
|
||||
|
||||
public void setJour(int jour) {
|
||||
this.jour = jour;
|
||||
}
|
||||
|
||||
public String getJour(int i) {
|
||||
return this.JOURS[i];
|
||||
}
|
||||
|
||||
}
|
37
tests/TD2/jourDeLaSemaine/jourSemaineTest.java
Normal file
37
tests/TD2/jourDeLaSemaine/jourSemaineTest.java
Normal file
@ -0,0 +1,37 @@
|
||||
package TD2.jourDeLaSemaine;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class jourSemaineTest {
|
||||
|
||||
JourSemaine j1 = new JourSemaine();
|
||||
JourSemaine j2 = new JourSemaine(2);
|
||||
JourSemaine j3 = new JourSemaine("vendredi");
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("lundi", j1.toString());
|
||||
assertEquals("mercredi", j2.toString());
|
||||
assertEquals("vendredi", j3.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVeille() {
|
||||
JourSemaine j = j2.veille();
|
||||
assertEquals("mardi", j.toString());
|
||||
j = j1.veille();
|
||||
assertEquals("dimanche", j.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLendemain() {
|
||||
JourSemaine j = new JourSemaine(6);
|
||||
j = j.lendemain();
|
||||
assertEquals("lundi", j.toString());
|
||||
j = j3.lendemain();
|
||||
assertEquals("samedi", j.toString());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user