27 Avril
This commit is contained in:
BIN
ControleMachineJava/Exercice3/MainExo3.class
Normal file
BIN
ControleMachineJava/Exercice3/MainExo3.class
Normal file
Binary file not shown.
52
ControleMachineJava/Exercice3/MainExo3.java
Normal file
52
ControleMachineJava/Exercice3/MainExo3.java
Normal file
@@ -0,0 +1,52 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MainExo3 {
|
||||
|
||||
public static ObjetAleatoire genererOA(){
|
||||
ObjetAleatoire p;
|
||||
Random r = new Random();
|
||||
if((r.nextInt()%2)==0){
|
||||
p = new Piece();
|
||||
}else{
|
||||
p = new PiecePipee();
|
||||
} return p;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ObjetAleatoire o;
|
||||
int f;
|
||||
int nbrf=0;
|
||||
int nbrp=0;
|
||||
int truquer=0;
|
||||
o=genererOA();
|
||||
o.lancer();
|
||||
f=o.lire();
|
||||
if(f==1||f==-1){
|
||||
System.out.println("Vous avez fait face.");
|
||||
}else{
|
||||
System.out.println("Vous avez fait pile.");
|
||||
} for(int j=0; j<10 ;j++){
|
||||
nbrf=0;
|
||||
nbrp=0;
|
||||
for(int i=0;i<100;i++){
|
||||
o.lancer();
|
||||
f=o.lire();
|
||||
if(f==1||f==-1){
|
||||
nbrf++;
|
||||
}else{
|
||||
nbrp++;
|
||||
}
|
||||
} if (nbrp<=nbrf){
|
||||
truquer++;
|
||||
}else{
|
||||
truquer--;
|
||||
}
|
||||
} if (truquer>=-7){
|
||||
System.out.println("Piece non truquer");
|
||||
}else{
|
||||
System.out.println("Piece truquer");
|
||||
}
|
||||
}
|
||||
}
|
BIN
ControleMachineJava/Exercice3/ObjetAleatoire.class
Normal file
BIN
ControleMachineJava/Exercice3/ObjetAleatoire.class
Normal file
Binary file not shown.
4
ControleMachineJava/Exercice3/ObjetAleatoire.java
Normal file
4
ControleMachineJava/Exercice3/ObjetAleatoire.java
Normal file
@@ -0,0 +1,4 @@
|
||||
public interface ObjetAleatoire{
|
||||
void lancer();
|
||||
int lire();
|
||||
}
|
BIN
ControleMachineJava/Exercice3/Piece.class
Normal file
BIN
ControleMachineJava/Exercice3/Piece.class
Normal file
Binary file not shown.
21
ControleMachineJava/Exercice3/Piece.java
Normal file
21
ControleMachineJava/Exercice3/Piece.java
Normal file
@@ -0,0 +1,21 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Piece implements ObjetAleatoire {
|
||||
|
||||
private int faceVisible; // 0 = pile; 1 = face.
|
||||
|
||||
public Piece(){
|
||||
this.faceVisible=faceVisible;
|
||||
}
|
||||
|
||||
public void lancer(){
|
||||
Random r = new Random();
|
||||
this.faceVisible=(r.nextInt()%2);
|
||||
}
|
||||
|
||||
public int lire(){
|
||||
return faceVisible;
|
||||
}
|
||||
}
|
BIN
ControleMachineJava/Exercice3/PiecePipee.class
Normal file
BIN
ControleMachineJava/Exercice3/PiecePipee.class
Normal file
Binary file not shown.
25
ControleMachineJava/Exercice3/PiecePipee.java
Normal file
25
ControleMachineJava/Exercice3/PiecePipee.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class PiecePipee implements ObjetAleatoire {
|
||||
|
||||
private int faceVisible; // 0 = pile; 1 = face.
|
||||
|
||||
public PiecePipee(){
|
||||
this.faceVisible=faceVisible;
|
||||
}
|
||||
|
||||
public void lancer(){
|
||||
Random r = new Random();
|
||||
if(r.nextInt()%10<7&&r.nextInt()%10>-7){
|
||||
this.faceVisible=0;
|
||||
}else{
|
||||
this.faceVisible=1;
|
||||
}
|
||||
}
|
||||
|
||||
public int lire(){
|
||||
return faceVisible;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user