fin du cotrole blanc dev32
This commit is contained in:
parent
1fc92e50c3
commit
b1a83ffc24
@ -1,15 +0,0 @@
|
|||||||
import javax.swing.JCheckBox;
|
|
||||||
|
|
||||||
public class Coche extends JCheckBox{
|
|
||||||
|
|
||||||
private Ingredient valeur;
|
|
||||||
|
|
||||||
public Coche(Ingredient valeur){
|
|
||||||
super(valeur.name());
|
|
||||||
this.valeur = valeur;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ingredient getValeur(){
|
|
||||||
return this.valeur;
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
@ -1,21 +1,22 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.util.Deque;
|
||||||
|
|
||||||
public class EvenementIngredient implements ItemListener{
|
public class EvenementIngredient implements ItemListener{
|
||||||
|
|
||||||
private PileIngredient historiqueChoix;
|
private Deque<JCheckBox> historiqueChoix;
|
||||||
private JButton boutonRetour;
|
private JButton boutonRetour;
|
||||||
|
|
||||||
public EvenementIngredient(PileIngredient historiqueChoix, JButton boutonRetour){
|
public EvenementIngredient(Deque<JCheckBox> historiqueChoix, JButton boutonRetour){
|
||||||
this.historiqueChoix = historiqueChoix;
|
this.historiqueChoix = historiqueChoix;
|
||||||
this.boutonRetour = boutonRetour;
|
this.boutonRetour = boutonRetour;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void itemStateChanged(ItemEvent e){
|
public void itemStateChanged(ItemEvent e){
|
||||||
Coche coche = (Coche) e.getSource();
|
JCheckBox coche = (JCheckBox) e.getSource();
|
||||||
this.historiqueChoix.push(coche.getValeur());
|
this.historiqueChoix.push(coche);
|
||||||
this.boutonRetour.setEnabled(true);
|
this.boutonRetour.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -1,33 +1,25 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.util.Deque;
|
||||||
|
|
||||||
public class EvenementRetour implements ActionListener{
|
public class EvenementRetour implements ActionListener{
|
||||||
|
|
||||||
private PileIngredient historique;
|
private Deque<JCheckBox> historique;
|
||||||
private Coche[] listeCoche;
|
|
||||||
private EvenementIngredient evenementIngredient;
|
|
||||||
|
|
||||||
|
|
||||||
public EvenementRetour(PileIngredient historique, Coche[] listeCoche, EvenementIngredient evenementIngredient){
|
public EvenementRetour(Deque<JCheckBox> historique){
|
||||||
this.historique = historique;
|
this.historique = historique;
|
||||||
this.listeCoche = listeCoche;
|
|
||||||
this.evenementIngredient = evenementIngredient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
Ingredient dernierChoisis = this.historique.pop();
|
JCheckBox dernierChoisis = this.historique.pop();
|
||||||
JButton boutonRetour = (JButton) e.getSource();
|
JButton boutonRetour = (JButton) e.getSource();
|
||||||
for (Coche coche : this.listeCoche){
|
dernierChoisis.setSelected(!dernierChoisis.isSelected()); // cette ligne declenche l'evenementIngredient
|
||||||
if (coche.getValeur() == dernierChoisis){
|
this.historique.pop(); // il faut donc retirer le dernier ingredient ajouter malencontreusement
|
||||||
coche.removeItemListener(evenementIngredient);
|
|
||||||
coche.setSelected(!coche.isSelected());
|
|
||||||
coche.addItemListener(evenementIngredient);
|
|
||||||
if (historique.isEmpty()){
|
if (historique.isEmpty()){
|
||||||
boutonRetour.setEnabled(false);
|
boutonRetour.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Fenetre.class
Normal file
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Fenetre.class
Normal file
Binary file not shown.
@ -1,9 +1,11 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
|
||||||
public class Fenetre extends JFrame{
|
public class Fenetre extends JFrame{
|
||||||
|
|
||||||
private PileIngredient historique;
|
private Deque<JCheckBox> historique;
|
||||||
|
|
||||||
public Fenetre(){
|
public Fenetre(){
|
||||||
super();
|
super();
|
||||||
@ -11,7 +13,7 @@ public class Fenetre extends JFrame{
|
|||||||
this.setSize(500, 300);
|
this.setSize(500, 300);
|
||||||
this.setLocation(0, 0);
|
this.setLocation(0, 0);
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
this.historique = new PileIngredient();
|
this.historique = new ArrayDeque<>();
|
||||||
this.addIngredient();
|
this.addIngredient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,17 +22,17 @@ public class Fenetre extends JFrame{
|
|||||||
EvenementIngredient evenementIngredient = new EvenementIngredient(this.historique, retour);
|
EvenementIngredient evenementIngredient = new EvenementIngredient(this.historique, retour);
|
||||||
Ingredient[] listeIngredient = Ingredient.values();
|
Ingredient[] listeIngredient = Ingredient.values();
|
||||||
int nbIngredient = listeIngredient.length;
|
int nbIngredient = listeIngredient.length;
|
||||||
Coche[] listeCoche = new Coche[nbIngredient];
|
JCheckBox[] listeCoche = new JCheckBox[nbIngredient];
|
||||||
int i;
|
int i;
|
||||||
this.setLayout(new GridLayout(1,nbIngredient+1));
|
this.setLayout(new GridLayout(nbIngredient+1,1));
|
||||||
|
|
||||||
for (i=0; i<nbIngredient; i++){
|
for (i=0; i<nbIngredient; i++){
|
||||||
listeCoche[i] = new Coche(listeIngredient[i]);
|
listeCoche[i] = new JCheckBox(listeIngredient[i].name());
|
||||||
listeCoche[i].addItemListener(evenementIngredient);
|
listeCoche[i].addItemListener(evenementIngredient);
|
||||||
this.add(listeCoche[i]);
|
this.add(listeCoche[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
EvenementRetour evenementRetour = new EvenementRetour(this.historique, listeCoche, evenementIngredient);
|
EvenementRetour evenementRetour = new EvenementRetour(this.historique);
|
||||||
retour.setEnabled(false);
|
retour.setEnabled(false);
|
||||||
retour.addActionListener(evenementRetour);
|
retour.addActionListener(evenementRetour);
|
||||||
this.add(retour);
|
this.add(retour);
|
||||||
|
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Ingredient.class
Normal file
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Ingredient.class
Normal file
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
enum Ingredient{
|
enum Ingredient{
|
||||||
SALADE,
|
SALADE,
|
||||||
TOMATES,
|
TOMATES,
|
||||||
OIGNONS
|
OIGNONS,
|
||||||
}
|
}
|
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Main.class
Normal file
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Main.class
Normal file
Binary file not shown.
@ -2,7 +2,7 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
public class Q4Main{
|
public class Main{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Fenetre fenetre = new Fenetre();
|
Fenetre fenetre = new Fenetre();
|
@ -1,23 +0,0 @@
|
|||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class PileIngredient{
|
|
||||||
|
|
||||||
private Deque<Ingredient> pile;
|
|
||||||
|
|
||||||
public PileIngredient(){
|
|
||||||
this.pile = new ArrayDeque<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void push(Ingredient valeur){
|
|
||||||
this.pile.push(valeur);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ingredient pop(){
|
|
||||||
return this.pile.pop();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty(){
|
|
||||||
return this.pile.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
55
DEV/DEV3.2/Controle_Machine_Blanc/Q2_Perfection/Arbre.java
Normal file
55
DEV/DEV3.2/Controle_Machine_Blanc/Q2_Perfection/Arbre.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Arbre{
|
||||||
|
|
||||||
|
private Noeud racine = null;
|
||||||
|
private int nbNoeud = 0;
|
||||||
|
|
||||||
|
public Arbre(int[] tableau){
|
||||||
|
for (int valeur : tableau){
|
||||||
|
this.add(valeur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int valeur){
|
||||||
|
this.nbNoeud ++;
|
||||||
|
if (racine == null){
|
||||||
|
this.racine = new Noeud(valeur);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Queue<Noeud> parcours = new LinkedList<>();
|
||||||
|
Noeud noeudActuel;
|
||||||
|
parcours.offer(this.racine);
|
||||||
|
do{
|
||||||
|
noeudActuel = parcours.poll();
|
||||||
|
} while(noeudActuel.add(valeur, parcours) == false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] toArray(){
|
||||||
|
if (racine == null){
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] resultat = new int[this.nbNoeud];
|
||||||
|
Queue<Noeud> parcours = new LinkedList<>();
|
||||||
|
int i;
|
||||||
|
|
||||||
|
parcours.offer(this.racine);
|
||||||
|
|
||||||
|
for (i=0; i<this.nbNoeud; i++){
|
||||||
|
Noeud noeud = parcours.poll();
|
||||||
|
int valeur;
|
||||||
|
if (noeud == null){
|
||||||
|
valeur = -1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
valeur = noeud.getValeur(parcours);
|
||||||
|
}
|
||||||
|
resultat[i] = valeur;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultat;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
24
DEV/DEV3.2/Controle_Machine_Blanc/Q2_Perfection/Main.java
Normal file
24
DEV/DEV3.2/Controle_Machine_Blanc/Q2_Perfection/Main.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
public class Main{
|
||||||
|
public static void main(String[] args){
|
||||||
|
int[] tableauEntier = new int[args.length];
|
||||||
|
int i;
|
||||||
|
try{
|
||||||
|
for (i=0; i<args.length; i++){
|
||||||
|
tableauEntier[i] = Integer.parseInt(args[i]);
|
||||||
|
if (tableauEntier[i] < 0){
|
||||||
|
throw new NumberFormatException("Erreur : l'entier naturel saisis est negatif "+tableauEntier[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Arbre arbre = new Arbre(tableauEntier);
|
||||||
|
|
||||||
|
int[] tableauArbre = arbre.toArray();
|
||||||
|
for (i=0; i<tableauArbre.length; i++){
|
||||||
|
System.out.print(tableauArbre[i] + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
catch(NumberFormatException e){
|
||||||
|
System.out.println("argument invalide");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
DEV/DEV3.2/Controle_Machine_Blanc/Q2_Perfection/Noeud.java
Normal file
31
DEV/DEV3.2/Controle_Machine_Blanc/Q2_Perfection/Noeud.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Noeud{
|
||||||
|
private Noeud gauche = null;
|
||||||
|
private Noeud droite = null;
|
||||||
|
private int valeur;
|
||||||
|
|
||||||
|
public Noeud(int valeur){
|
||||||
|
this.valeur = valeur;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean add(int valeur, Queue<Noeud> parcours){
|
||||||
|
if (this.gauche == null){
|
||||||
|
this.gauche = new Noeud(valeur);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (this.droite == null){
|
||||||
|
this.droite = new Noeud(valeur);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
parcours.offer(this.gauche);
|
||||||
|
parcours.offer(this.droite);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValeur(Queue<Noeud> parcours){
|
||||||
|
parcours.offer(this.gauche);
|
||||||
|
parcours.offer(this.droite);
|
||||||
|
return this.valeur;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user