Created
December 7, 2017 16:10
-
-
Save chermehdi/8ac6a333b594730ce1ea918e94131da6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.OutputStreamWriter; | |
import java.io.PrintWriter; | |
import java.util.*; | |
public class Tirage { | |
private final String[] names = { | |
"Mehdi", "Houda", "Zouhair", "Salma", "Fatimazahra", "Hamza", "Yassir", "Ghita" | |
}; | |
private final String[] topics = { | |
"CLASS", "PAQUETAGE", "ETATS-TRANSITION", "OCL" | |
}; | |
public static void main(String[] args) { | |
new Tirage().start(); | |
} | |
public void start() { | |
List<String> nameList = new ArrayList<>(Arrays.asList(names)); | |
List<String> topicList = new ArrayList<>(Arrays.asList(topics)); | |
Random r = new Random(); | |
HashMap<String, List<String>> map = new HashMap<>(); | |
for (String topic : topics) map.put(topic, new ArrayList<>()); | |
while (!nameList.isEmpty()) { | |
int index = r.nextInt(nameList.size()); | |
int topicIndex = r.nextInt(topicList.size()); | |
if (map.get(topicList.get(topicIndex)).size() == 2) { | |
topicList.remove(topicIndex); | |
} else { | |
map.get(topicList.get(topicIndex)).add(nameList.get(index)); | |
nameList.remove(index); | |
} | |
} | |
printResult(map); | |
} | |
private void printResult(HashMap<String, List<String>> map) { | |
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); | |
for (String topicName : map.keySet()) { | |
out.print("The Diagramme " + topicName + " is Going to be handled by => "); | |
for (String name : map.get(topicName)) { | |
out.print(name + " "); | |
} | |
if (topicName.equalsIgnoreCase("OCL")) out.println("Houley"); | |
else out.println(); | |
} | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment