Trajet/Journey
comme une suite ordonnée de points.1)On décide de produire une nouvelle application telle que :
Evidemment vous commencez par identifier les cas d'utilisation de haut niveau. Mais ensuite vous pouvez travailler comme bon vous semble.
* Partie 1 : Voici des exemples très simples de tests de “validation”, c'est à dire des tests qui mettent en exergue certaines des exigences client décrites ci-dessus.
Journey [points=[ [date=Thu Feb 28 21:39:15 CET 2019, Point [x=5, y=5, label=domicile]], [date=Thu Feb 28 21:39:16 CET 2019, Point [x=7, y=7, label=p1]], [date=Thu Feb 28 21:39:17 CET 2019, Point [x=10, y=10, label=p2]],..
date=Thu Feb 28 21:39:16 CET 2019
) ; date=Thu Feb 28 21:39:17 CET 2019
)Thu Feb 28 21:39:17 CET 2019
: le système renvoie (12,12) etc.Si vous voulez représenter la gestion du temps (mais vous pouvez vous en passer), voici une approche très simple :
try { Thread.sleep(10000);//1000 milliseconds is one second. } catch (InterruptedException e) { e.printStackTrace(); }
import java.util.Scanner; ..................... Scanner sc = new Scanner(System.in); int y = sc.nextInt(); boolean encore = sc.nextBoolean();
Attention, votre code ne correspond probablement pas à cela !!
Scanner sc = new Scanner(System.in); int interval = 1000; public Journey createJourney(Member m) throws InterruptedException{ System.out.println("Creating a journey "); DatedPoint currentPoint = enterDatedPoint(); ; Journey path = new Journey(currentPoint); boolean again = true; while (again){ currentPoint = enterDatedPoint(); path.addPoint(currentPoint); System.out.println("Distance : " + path.distance()); System.out.println("Duration since departure : " + path.duration() + " soit :" + path.duration()/1000 + " secondes" ); System.out.println("We continue ? (true or false)"); again = sc.nextBoolean(); Thread.sleep(interval); //1000 milliseconds is one second. } return path; } private DatedPoint enterDatedPoint() { DatedPoint currentPoint; int x; int y; System.out.println(" X "); x = sc.nextInt(); System.out.println(" Y "); y = sc.nextInt(); //obtenir la date courante Date date = new Date(); currentPoint = new DatedPoint(x,y,date); return currentPoint; }
Autres exemples
//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; }
Et des exemples de tests …
void testClosestPoint() throws InterruptedException { Date currentDate1 = new Date(); DatedPoint currentPoint1 = new DatedPoint(5,5,currentDate1,"domicile") ; Thread.sleep(1000); Date currentDate2 = new Date(); DatedPoint currentPoint2 = new DatedPoint(7,7,currentDate2,"p1") ; Thread.sleep(1000); DatedPoint currentPoint3 = new DatedPoint(10,10,new Date(),"p2") ; Thread.sleep(1000); Journey path = new Journey(currentPoint1); path.addPoint(currentPoint2); path.addPoint(currentPoint3); System.out.println(path); assertEquals(currentPoint1.getDate(), path.whenWasYouHere(currentPoint1)); assertEquals(currentPoint2.getDate(), path.whenWasYouHere(currentPoint2)); assertEquals(currentPoint3.getDate(), path.whenWasYouHere(currentPoint3)); assertEquals(currentPoint3.getDate(), path.whenWasYouHere(new Point(12,12))); assertEquals(currentPoint1.getDate(), path.whenWasYouHere(new Point(4,4))); assertEquals(currentPoint2.getDate(), path.whenWasYouHere(new Point(8,8))); } @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)) ); }