- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
183 lines (151 loc) · 5.01 KB
/
Copy pathMain.java
File metadata and controls
183 lines (151 loc) · 5.01 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
importjava.util.Scanner;
classMain {
/**
* Asks an integer in the range [from, to]
*/
publicstaticintaskIntBtw(intfrom, intto) {
Scannerscan = newScanner(System.in);
intanswer = -1;
while (answer == -1) {
System.out.print("Votre reponse : ");
try {
answer = scan.nextInt();
if (answer < from || answer > to) {
System.out.println("Veuillez entrer un nombre entre " + from + " et " + to + ".");
answer = -1;
}
} catch (RuntimeExceptione) {
System.out.println("Veuillez entrer un nombre.");
scan.nextLine(); // Makes the buffer empty
answer = -1;
}
}
System.out.println(); // Break line before results
returnanswer;
}
/**
* Displays menu and asks for an action
*/
publicstaticintmenuMetro() {
System.out.println("-------------------------------------------------");
System.out.println("Menu :");
System.out.println("\t0- Quitter.");
System.out.println("\t1- Trouver les 10 elements les plus connectes.");
System.out.println("\t2- Trouver le plus court chemin d'un element a un autre.");
System.out.println("\t3- Trouver le plus court chemin d'un element a un autre en passant par tous les groupes/composantes.");
System.out.println("Que voulez-vous faire ?");
returnMain.askIntBtw(0, 3);
}
publicstaticintmenuPerson() {
System.out.println("-------------------------------------------------");
System.out.println("Menu :");
System.out.println("\t0- Quitter.");
System.out.println("\t1- Trouver les 10 elements les plus connectes.");
System.out.println("\t2- Trouver le plus court chemin d'un element a un autre.");
System.out.println("\t3- Verifier les six degrees de separation.");
System.out.println("Que voulez-vous faire ?");
returnMain.askIntBtw(0, 3);
}
/**
* Ask the user to enter a node name.
*/
publicstatic <TextendsLinkable> StringaskName(Network<T> net) {
Scannerscan = newScanner(System.in);
Stringanswer = null;
LinkableelementFound = null;
while (elementFound == null) {
System.out.print("Entrer un nom : ");
answer = scan.nextLine().trim();
elementFound = net.get(answer);
}
System.out.println("La reponse \"" + answer + "\" a ete enregistree.");
returnanswer;
}
/**
* Showcase for metro
*/
publicstaticvoidshowMetroCase(StringfileMetro) {
booleanwantToContinue = true;
StringstartName;
StringendName;
Nodeitinerary;
// Loading the network with the given file
Network<Station> net = newNetwork<>(newStation());
if (!net.fill(fileMetro)) return;
System.out.println("Les donnees sont chargees.");
// Interaction with the user
while (wantToContinue) {
intchoice = Main.menuMetro();
switch(choice) {
case0: // Quit
wantToContinue = false;
break;
case1: // Showing the 10 most connected Linkables
net.showTop10();
break;
case2: // Ask for two names to find the shortest path
startName = Main.<Station>askName(net);
endName = Main.<Station>askName(net);
System.out.println(net.getItinerary(startName, endName));
break;
case3: // Ask for two names to find the shortest path
startName = Main.<Station>askName(net);
endName = Main.<Station>askName(net);
itinerary = net.getBestItineraryWithAllComponents(startName, endName);
System.out.println(itinerary + "\nLongueur : " + itinerary.size());
break;
}
}
}
/**
* Showcase for social network
*/
publicstaticvoidshowSocialNetCase(StringfilePerson) {
booleanwantToContinue = true;
StringstartName;
StringendName;
Nodeitinerary;
// Loading the network with the given file
Network<Person> net = newNetwork<>(newPerson());
if (!net.fill(filePerson)) return;
System.out.println("Les donnees sont chargees.");
// Interaction with the user
while (wantToContinue) {
intchoice = Main.menuPerson();
switch(choice) {
case0: // Quit
wantToContinue = false;
break;
case1: // Showing the 10 most connected Linkables
net.showTop10();
break;
case2: // Ask for two names to find the shortest path
startName = Main.<Person>askName(net);
endName = Main.<Person>askName(net);
System.out.println(net.getItinerary(startName, endName));
break;
case3: // Ask for two names to find the shortest path
net.checkSeparationDegree();
break;
}
}
}
publicstaticvoidmain(String [] args) {
System.out.println("Selectionnez :");
System.out.println("\t0- metro-wl.txt");
System.out.println("\t1- sonet-200.txt");
System.out.println("\t2- sonet-1000.txt");
intmode = Main.askIntBtw(0, 2);
switch (mode) {
case0:
Main.showMetroCase("metro-wl.txt");
break;
case1:
Main.showSocialNetCase("sonet-200.txt");
break;
case2:
Main.showSocialNetCase("sonet-1000.txt"); // Can change the filename for social network case
break;
}
}
}