bonsoir,
dans la classe suivante est ce que vous trouvez comment un object Request peut il être crée avec comme attribut code : code = NONE ?
Parce que moi, je ne trouve pas
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 package shiptrafficcontrol; public class Request { private Ship ship; private int code; public static final int LEAVE=0, DOCK=1, SET_SAIL=2, ARRIVE=3, NONE=4; public Request(java.util.Random random, Cluster seaShips, Cluster waitingShips, Cluster dockShips){ int randCode; Cluster cluster; // pick a request with preference to docking from the queue if (!waitingShips.isEmpty() && random.nextFloat()>0.5){ randCode = NONE; ship = null; } else { randCode = random.nextInt(3); // if there's no ship to go with the request // then make the request be arrive with a new ship // else pick a ship that could have made the request cluster = workOutClusterFor(randCode, seaShips, dockShips); if (cluster.isEmpty()) { code = ARRIVE; ship = new Ship(); } else { code = randCode; ship = (Ship) cluster.pickOne(random); } } } public static Cluster workOutClusterFor(int randCode, Cluster seaShips, Cluster dockShips){ /* @ requires: randCode == LEAVE || randCode == DOCK || randCode == SET_SAIL; * @ ensures: \return != null */ if (randCode == LEAVE || randCode == DOCK) return seaShips; else return dockShips; } public String toString(){ String message; if (code==NONE) return "-- no message --"; else { switch (code){ case LEAVE: message = "Can I leave the area?"; break; case DOCK: message = "Can I dock?"; break; case SET_SAIL: message = "Can I set sail from the dock?"; break; case ARRIVE: message = "Can I enter the area?"; break; default: message = ""; break; } return "<"+ship.toString()+"> :"+message; } } public Ship getShip(){ return ship; } public int getCode(){ return code; } }![]()
Merci![]()
Partager