This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
2018_2019:s2:td:td_final [2019/02/17 00:22] blay [De la modélisation au code : FINALE] |
2018_2019:s2:td:td_final [2019/02/28 21:07] blay [La classe Journey (30mn)] |
||
---|---|---|---|
Line 2: | Line 2: | ||
Dans ce TD nous avons pour objectif de partir de la modélisation et d'arriver au codage en 4h ! | Dans ce TD nous avons pour objectif de partir de la modélisation et d'arriver au codage en 4h ! | ||
- | |||
- | comprendre la relation entre la modélisation et le code, et ceci en utilisant tous les éléments de modélisation. | ||
/* | /* | ||
Line 17: | Line 15: | ||
===== La classe "Journey" (30mn) ===== | ===== La classe "Journey" (30mn) ===== | ||
- | * On définit un ''Trajet'' comme une suite ordonnée de points. | + | * On définit un ''Trajet/Journey'' comme une suite ordonnée de points. |
* Un point a un intitulé (par exemple, "IUT, Fabron"). | * Un point a un intitulé (par exemple, "IUT, Fabron"). | ||
* Un point peut appartenir à plusieurs Trajets. | * Un point peut appartenir à plusieurs Trajets. | ||
Line 167: | Line 165: | ||
</code> | </code> | ||
+ | |||
+ | |||
+ | Autres exemples | ||
+ | |||
+ | <code java> | ||
+ | //To improve taking into account the displacement | ||
+ | public Date whenWasYouHere(Point point) { | ||
+ | DatedPoint closestPoint = points[0]; | ||
+ | double distanceMin = point.distance(closestPoint); | ||
+ | for (int i =1; i<nextPlace;i++) { | ||
+ | double distance = point.distance(points[i]); | ||
+ | if (distance < distanceMin) { | ||
+ | distanceMin = distance; | ||
+ | closestPoint = points[i]; | ||
+ | } | ||
+ | } | ||
+ | return closestPoint.getDate(); | ||
+ | } | ||
+ | |||
+ | |||
+ | //To improve taking into account the displacement | ||
+ | public DatedPoint whereWereYou(Date date) { | ||
+ | long time = date.getTime(); | ||
+ | DatedPoint closestPoint = points[0]; | ||
+ | long durationMin = Math.abs(closestPoint.getDate().getTime()-time); | ||
+ | for (int i =1; i<nextPlace;i++) { | ||
+ | long duration = Math.abs(points[i].getDate().getTime()-time); | ||
+ | if (duration < durationMin) { | ||
+ | durationMin = duration; | ||
+ | closestPoint = points[i]; | ||
+ | } | ||
+ | } | ||
+ | return closestPoint; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | Et des exemples de tests ... | ||
+ | |||
+ | <code java> | ||
+ | @Test | ||
+ | void testClosestPoint() throws InterruptedException { | ||
+ | Date currentDate1 = new Date(); | ||
+ | DatedPoint currentPoint1 = new DatedPoint(5,5,currentDate1) ; | ||
+ | Thread.sleep(1000); | ||
+ | Date currentDate2 = new Date(); | ||
+ | DatedPoint currentPoint2 = new DatedPoint(7,7,currentDate2) ; | ||
+ | Thread.sleep(1000); | ||
+ | DatedPoint currentPoint3 = new DatedPoint(10,10,new Date()) ; | ||
+ | Thread.sleep(1000); | ||
+ | Date currentDate3 = new Date(); | ||
+ | Journey path = new Journey(currentPoint1); | ||
+ | path.addPoint(currentPoint2); | ||
+ | path.addPoint(currentPoint3); | ||
+ | assertEquals(currentPoint1.getDate(), path.whenWasYouHere(currentPoint1)); | ||
+ | assertEquals(currentPoint2.getDate(), path.whenWasYouHere(currentPoint2)); | ||
+ | assertEquals(currentPoint3.getDate(), path.whenWasYouHere(currentPoint3)); | ||
+ | assertEquals(currentPoint3.getDate(), path.whenWasYouHere(new DatedPoint(12,12,new Date()))); | ||
+ | assertEquals(currentPoint1.getDate(), path.whenWasYouHere(new DatedPoint(4,4,new Date()))); | ||
+ | assertEquals(currentPoint2.getDate(), path.whenWasYouHere(new DatedPoint(8,8,new Date()))); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | @Test | ||
+ | void testWhereWereYou() throws InterruptedException { | ||
+ | Date currentDate1 = new Date(); | ||
+ | DatedPoint currentPoint1 = new DatedPoint(5,5,currentDate1) ; | ||
+ | Thread.sleep(1000); | ||
+ | Date currentDate2 = new Date(); | ||
+ | DatedPoint currentPoint2 = new DatedPoint(7,7,currentDate2) ; | ||
+ | Thread.sleep(1000); | ||
+ | DatedPoint currentPoint3 = new DatedPoint(10,10,new Date()) ; | ||
+ | Thread.sleep(1000); | ||
+ | Date currentDate3 = new Date(); | ||
+ | Journey path = new Journey(currentPoint1); | ||
+ | path.addPoint(currentPoint2); | ||
+ | path.addPoint(currentPoint3); | ||
+ | assertEquals(currentPoint1, path.whereWereYou(currentDate1)); | ||
+ | assertEquals(currentPoint2, path.whereWereYou(currentDate2)); | ||
+ | assertEquals(currentPoint3, path.whereWereYou(currentDate3)); | ||
+ | assertEquals(currentPoint3, path.whereWereYou(new Date())); | ||
+ | assertEquals(currentPoint1, path.whereWereYou(new Date(currentDate1.getTime()-1000)) ); | ||
+ | } | ||
+ | </code> | ||
+ | |||
</panel> | </panel> | ||
</accordion> | </accordion> | ||
+ | |||
+ | |||
+ | ==== Rendu pour ce devoir ==== | ||
+ | |||
+ | FIXME | ||
+ | |||
+ | - Les rendus se font sous [[http://jalon.unice.fr/cours/blay/Cours-blay-20160226085155/BoiteDepot-blay-20190217142915655329?mode_etudiant=true&tab=deposit|jalon]] avant <color red>A déterminer</color> | ||
+ | - Le rendu respecte ce qui suit : | ||
+ | - il se fait à 2 maximum | ||
+ | - le titre est composé de FIN<NumeroDuGroupe>_NomEtudiant__NomEtudiant //(e.g. DS1_Doe_Smith ou UC2_Harry)// | ||
+ | - Un document qui comprend : | ||
+ | - votre diagramme de cas d'utilisation | ||
+ | - votre diagramme de séquence | ||
+ | - votre diagramme de classes cohérent relativement à l'ensemble de l'étude de cas et donc complété relativement au diagramme de séquence | ||
+ | - les codes sources (là où vous en êtes) | ||
+ | - les tests si vous en avez, sinon le main de test | ||
+ | |||