This commit is contained in:
2023-04-27 11:27:11 +02:00
parent bfcbd64735
commit 93c00d1ed0
24 changed files with 483 additions and 0 deletions

Binary file not shown.

View 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");
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,4 @@
public interface ObjetAleatoire{
void lancer();
int lire();
}

Binary file not shown.

View 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;
}
}

Binary file not shown.

View 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;
}
}