Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- class Personne {
- int age;
- String nom, prenom;
- int nbQ2;
- public ArrayList<Concours> succes;
- public ArrayList<Concours> defaites;
- private static String[] nn= {"Lina", "Inaya", "Yasmine", "Maïssa", "Maya", "Sofia", "Kenza", "Sara", "Aya", "Assia", "Lila", "Nour", "Marwa", "Selma", "Nora", "Sirine", "Leïla", "Amina", "Farah", "Salma", "Adam", "Mohamed", "Rayan", "Naël", "Ilyes", "Soan", "Amine", "Kenzo", "Kaïs", "Noam", "Mehdi", "Ayoub", "Younès", "Wassim", "Amir", "Sohan", "Ibrahim", "Youssef", "Naïm", "Yassine"};
- private static String[] nm= {"Smith", "Backer", "Di Caprio", "Burns", "Brown", "Simpson", "Electra", "Morgan", "De Buaala", "Robinsky", "De gaulle", "Obama", "De borbon y borbon", "Sanchez", "Mosby", "Scherbatsky", "Aldrins", "Eriksen", "Stinson"};
- public Personne(String n, String p) {
- nom = n;
- prenom = p;
- age = (int) (Math.random()*91)+8;
- succes = new ArrayList<Concours>();
- defaites = new ArrayList<Concours>();
- }
- public Personne() {
- this(nm[(int)(Math.random()*nm.length)] , nn[(int)(Math.random()*nn.length)]);
- }
- public void addDefaite(Concours c) {
- defaites.add(c);
- }
- public void addSucces(Concours c) {
- succes.add(c);
- }
- public String toString() {
- return prenom + " " + nom.toUpperCase() + "("+age+" ans)";
- }
- public void setQ2(int q) {
- nbQ2 = q;
- }
- public int getQ2() {
- return nbQ2;
- }
- public int nbVict() {
- return succes.size();
- }
- }
- class Concours {
- private int qId;
- private Personne[] assemblee;
- private ArrayList<Personne> gagnants;
- double diff;
- public static final int NB_PARTICIPANTS = 20;
- public static final String[] questions = {"Quel est le sens de la vie?", "Comment se danse la macarena?", "De quel couleur est le cheval violet d'Henri IV?", "Qui est le président d'Angleterre?", "2x7 - 7 = ?", "Comment fait on les bébés?", "Qu'est-ce qui est mieux : Granola ou BN?", "Quel animal figure sur les paquets de céréales Lion?", "Apple est il l'incarnation de Satan?", "Quel est le site internet le plus visité au monde?", "C++, Java, ou Python?"};
- public static final String[][] reponses = {{"42", "Obiwan Kenobi", "Les femmes", "La réponse D"},
- {"Avec émotion", "Tout nu", "En étant manchot", "Ce n'est pas une danse"},
- {"Violet", "Rose", "Mort", "Arc en ciel"},
- {"Il n'y en a pas", "Marie Antoinette, reine d'autriche", "Joséphine ange gardien", "George W. Hollande"},
- {"7", "42", "0", "12"},
- {"Avec une éprouvette", "En dansant la macarena", "sudo mkbébé", "A l'aide de logarithmes népériens"},
- {"Granola", "BN", "Pepito", "J'aime pas les gateaux"},
- {"Un lion", "Un enfant", "Un oiseau", "Une chèvre"},
- {"Oui, assurément", "C'est pas impossible", "C'est envisageable", "Non, j'aime me faire pigeonner"},
- {"Google.com", "xkcd.com", "lesjoiesducode.fr", "commitstrip.com"},
- {"C++", "Java", "Python", "Assembleur, what else?"}
- };
- public Concours(Personne[] p) {
- qId = (int)(Math.random()*questions.length);
- assemblee = p;
- diff = Math.random();
- }
- public void faireQA() {
- System.out.println("\nQuestion du concours : " + questions[qId]);
- ArrayList<Personne> g = new ArrayList<Personne>();
- for(Personne p : assemblee) {
- if(Math.random() > diff) { // reponse OK
- g.add(p);
- p.setQ2((int) (Math.random()*NB_PARTICIPANTS - 1) +1);
- }
- else { // mauvaise réponse
- System.out.println(p+ " est éliminé après avoir répondu : " + reponses[qId][(int) (Math.random()*3)+1]);
- p.addDefaite(this);
- }
- }
- int nbG = g.size(), min = NB_PARTICIPANTS;
- StringBuilder sb = new StringBuilder("\nPersonnes ayant bien répondu : ");
- for(Personne p : g) {
- sb.append(p + ", ");
- if(Math.abs(p.getQ2() - nbG) < min) {
- min = Math.abs(p.getQ2() - nbG);
- }
- }
- System.out.println(sb);
- ArrayList<Personne> pure_winners = new ArrayList<Personne>();
- for(Personne p : g) {
- if(Math.abs(p.getQ2() - nbG) == min) {
- p.addSucces(this);
- pure_winners.add(p);
- } else {
- p.addDefaite(this);
- }
- }
- gagnants = pure_winners;
- if(g.size() == 0){
- System.out.println("\nQuel dommage, il n'y a aucun gagnant!");
- } else {
- sb = new StringBuilder("\nListe des gagnants : ");
- for(Personne p : pure_winners) {
- sb.append(p + ", ");
- }
- System.out.println(sb);
- }
- System.out.println("_____________________________________________________________________________");
- }
- }
- public class TestConcours {
- public static void main(String[] args) {
- Personne[] assemblee = new Personne[Concours.NB_PARTICIPANTS];
- for(int i = 0; i < assemblee.length; i++) {
- assemblee[i] = new Personne();
- }
- Concours[] cs = new Concours[10];
- for(int i=0; i < cs.length; i++) {
- cs[i] = new Concours(assemblee);
- cs[i].faireQA();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment