ajout ex2 tp4

This commit is contained in:
Simoes Lukas
2025-09-27 17:38:27 +02:00
parent 3393bcafca
commit 33691f11fb
14 changed files with 171 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
### VARIABLES ###
JC = javac
JCFLAGS = -encoding UTF-8 -implicit:none -d build -cp build -sourcepath "src" src/
JVM = java
JVMFLAGS = -cp build
PACKAGE_NAME = fr.iutfbleau.Quiz.
### REGLES ESSENTIELLES ###
Question.class : Question.class
${JC} ${JCFLAGS}Question.java
SourceQuestions.class : SourceQuestions.class Question.class
${JC} ${JCFLAGS}SourceQuestions.java
AffichageQuestion.class : AffichageQuestion.class Question.class
${JC} ${JCFLAGS}AffichageQuestion.java
Main.class : Main.class AffichageQuestion.class SourceQuestions.class
${JC} ${JCFLAGS}Main.java
### REGLES OPTIONNELLES ###
run : Main.class
${JVM} ${JVMFLAGS} ${PACKAGE_NAME}Main
clean :
-rm -r build/fr/iutfbleau/Quiz/*.class
mrproper : clean Main.class
### BUTS FACTICES ###
.PHONY : run clean mrproper
### FIN ###

Binary file not shown.

View File

@@ -0,0 +1,56 @@
package fr.iutfbleau.Quiz;
import java.awt.*;
import javax.swing.*;
public class AffichageQuestion extends JFrame {
private Question questions;
private int compteur;
public AffichageQuestion(Question questions) {
this.questions = questions;
this.compteur = 1;
this.setSize(400, 700);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 4;
gbc.gridheight = 4;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(5, 5, 5, 5);
JLabel intitule = new JLabel(questions.getIntitule());
this.add(intitule);
JLabel compteur = new JLabel("" + this.compteur);
gbc.gridx = 5;
gbc.insets = new Insets(0, 0, 0, 0);
this.add(intitule);
gbc.gridy = 2;
gbc.gridx = 2;
gbc.gridwidth = 2;
for (int i = 0; i != this.questions.getOptions().length; i++) {
JButton option = new JButton(this.questions.getOptions()[i]);
this.add(option);
gbc.gridy++;
gbc.insets = new Insets(0, 0, 0, 5);
}
}
}

View File

View File

@@ -0,0 +1,8 @@
package fr.iutfbleau.Quiz;
public class Main {
public static void main(String[] args) {
AffichageQuestion fenetre = new AffichageQuestion(SourceQuestions.genererQuestion());
fenetre.setVisible(true);
}
}

View File

View File

@@ -0,0 +1,28 @@
package fr.iutfbleau.Quiz;
import java.awt.*;
public class Question {
private String intitule;
private String[] options;
private int indexBonneReponse;
public Question(String intitule, String[] options, int indexBonneReponse) {
this.intitule = intitule;
this.options = options;
this.indexBonneReponse = indexBonneReponse;
}
public String getIntitule() {
return this.intitule;
}
public String[] getOptions() {
return this.options;
}
public int getIndexBonneReponse() {
return this.indexBonneReponse;
}
}

View File

@@ -0,0 +1,39 @@
package fr.iutfbleau.Quiz;
import java.util.Arrays;
import java.util.Random;
public class SourceQuestions {
public static Question genererQuestion() {
Random r = new Random();
int x = r.nextInt(11);
int y = r.nextInt(11);
String intitule = x + " x " + y + " = ?";
int bonneReponse = x*y;
int[] mauvaisesReponses = new int[4];
for (int i = 0; i != mauvaisesReponses.length; i++) {
mauvaisesReponses[i] = r.nextInt(101);
}
int indexBonneReponse = r.nextInt(4);
String[] options = new String[4];
options[indexBonneReponse] = "" + bonneReponse;
for (int i = 0; i != 4; i++) {
if (i != indexBonneReponse) {
options[i] = "" + mauvaisesReponses[i];
}
}
return new Question(intitule, options, indexBonneReponse);
}
}