Bonjour , j'ai créer la classe Roue , classe BanditMachot ,classe TestBanditMachot
mais après l'exécution le programme n'a pas lancé
et une exception s'est levée
Je veux savoir comment mettre ce programme marche correctement
j'ai crée la classe Roue , ensuite j'ai crée la classe BanditMachot , enfin la classe TestBanditMachot
***********************************************
voici l'énoncé de l'exercice
aidez moi s'il vous plait
voici mon travail
la classe Roue :
package pack8;
public class Roue {
int aleatoire;
public void lance()
{
aleatoire= 0 + (int)(Math.random() * ((4 - 0) + 1));
}
public int get()
{
return this.aleatoire;
}
}
la classe Bandit Machot :
package pack8;
public class BanditMachot {
static Roue [] tab;
static int gain;
public BanditMachot()
{
Roue [] tab =new Roue [4];
}
public static int joue()
{
//declaration variables
int[] numberofoccurance=new int [4];
int [] elements=new int[4];
int forElements=0;
boolean trouve;
int j=0;
gain=0;
//traitement
numberofoccurance[0]=1;
elements[0]=tab[0].get();
for (int i=1;i<4;i++)
{
trouve=false;
j=0;
while((j<i)&&(trouve==false))
{
if((tab[i].get()==elements[j]))
{
trouve=true;
numberofoccurance[i]+=1;
}
else
{
j=j+1;
}
if(trouve==false)
{
forElements=forElements+1;
elements[forElements]=tab[i].get();
numberofoccurance[forElements]+=1;
}
}
}
for(int c=0;c<forElements;c++)
{
if(numberofoccurance[c]==2)
{
gain=10;
}
else
if(numberofoccurance[c]==3)
{
gain=100;
}
else
if(numberofoccurance[c]==4)
{
gain=1000;
}
else
{
gain=0;
}
}
return gain;
}
}
la classe TestBanditMachot
package pack8;
public class TestBanditMachot {
public static void main(String[] args) {
// TODO Auto-generated method stub
BanditMachot bm=new BanditMachot();
BanditMachot.joue();
}
}
package pack8;
public class TestBanditMachot {
public static void main(String[] args) {
// TODO Auto-generated method stub
BanditMachot bm=new BanditMachot();
bm.joue();
}
}
la classe Roue
package pack8;
public class Roue {
int aleatoire;
public void lance()
{
aleatoire= 0 + (int)(Math.random() * ((4 - 0) + 1));
}
public int get()
{
return this.aleatoire;
}
}
la classe BanditMachot
package pack8;
public class BanditMachot {
Roue [] tab;
int gain;
public BanditMachot()
{
Roue [] tab =new Roue [4];
}
public int joue()
{
//declaration variables
int[] numberofoccurance=new int [4];
int [] elements=new int[4];
int forElements=0;
boolean trouve;
int j=0;
gain=0;
//traitement
numberofoccurance[0]=1;
elements[0]=tab[0].get();
for (int i=1;i<4;i++)
{
trouve=false;
j=0;
while((j<i)&&(trouve==false))
{
if((tab[i].get()==elements[j]))
{
trouve=true;
numberofoccurance[i]+=1;
}
else
{
j=j+1;
}
if(trouve==false)
{
forElements=forElements+1;
elements[forElements]=tab[i].get();
numberofoccurance[forElements]+=1;
}
}
}
for(int c=0;c<forElements;c++)
{
if(numberofoccurance[c]==2)
{
gain=10;
}
else
if(numberofoccurance[c]==3)
{
gain=100;
}
else
if(numberofoccurance[c]==4)
{
gain=1000;
}
else
{
gain=0;
}
}
return gain;
}
}
Merci beaucoup Monsieur , je veux le tester maintenant
Bandit machot ne fonctionne pas
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Tu vois rien ici ... ? hint : classe vs instance.