# Thread: why the number will not increase?

1. Member Join Date
Mar 2009
Posts
7
Rep Power
0

## why the number will not increase?

Java Code:
```public class fermi
{
private int[] guess;
private int[] random;
private int total;
private int win;
private int lose;

public fermi(int[] gs, int[] rn)
{
guess=new int[gs.length];
for(int i=0;i<gs.length;i++)
guess[i]=gs[i];

random=new int[rn.length];
for(int j=0;j<rn.length;j++)
guess[j]=gs[j];
}

public fermi()
{
total=0;
win=0;
lose=0;
}

public int totalPlay()
{
}

public int totalWin()
{
return win+=1;
}

public int totalLose()
{
return lose+=1;
}
public String toString()
{
String str="Total play is "+total+"\nTotal win is "+win+"\nTotal lose is "+lose;
return str;
}

}```
Java Code:
```import javax.swing.JOptionPane;
import java.util.Random;

public class FermiGame
{
public static void main(String [] args)
{
JOptionPane.showMessageDialog(null,"Hello!!"+"\nWelcome to Fermi ^o^!");
JOptionPane.showMessageDialog(null,"There is only one simple rule: Guess 3 numbers in between 0-9"
+"\nand in the correct position to match with the three Secret Numbers"
+"\nYour aim is to try to get three Fermi."
+"\n If you get Nano,that's means your guess does not match any of the secret numbers."
+"\n Pico means your guess is correct,but not in the correct position.");

valid();
}

public static void valid()
{
String input;
char ch;
input=JOptionPane.showInputDialog("Enter any alphabert to start play or 'z' to quit:");
ch=input.charAt(0);
while(!Character.isLetter(ch))
{
input=JOptionPane.showInputDialog("!!You are only allow to enter alphabert!!"+
"\nPlease re-enter any alphabert to start play or 'z' to quit:");
ch=input.charAt(0);
}

if(ch=='z')
{
quit();
}
else
start();
}

public static void start()
{
char ch;
String input;
final int Num_Guess=3;
int [] guess=new int [Num_Guess];
final int Num_Random=3;
int [] random=new int [Num_Random];
Random ran=new Random();
for(int j=0; j<random.length; j++)
{
random[j]=ran.nextInt(10);
}
for(int i=0; i<guess.length; i++)
{
ch=input.charAt(0);
while(!Character.isDigit(ch))
{
input=JOptionPane.showInputDialog("!!This is not an integer!!"+
ch=input.charAt(0);
}
guess[i]=Integer.parseInt(input);

while(guess[i]<0 || guess[i]>9)
{
input=JOptionPane.showInputDialog("!!Invalid number!!"+
"\nYou can only enter integer in between 0-9."+
ch=input.charAt(0);
while(!Character.isDigit(ch))
{
input=JOptionPane.showInputDialog("!!This is not an integer!!"+
ch=input.charAt(0);
}
guess[i]=Integer.parseInt(input);
}
}

fermi give=new fermi(guess,random);
result(guess,random);
}

public static void result(int []guess,int []random)
{
fermi value=new fermi();
for(int k=0;k<3;k++)
{
if(guess[k]==random)
{
JOptionPane.showMessageDialog(null,guess[k]+"=FERMI (^0^)");
}
else if(guess[k]==random || guess[k]==random)
{
JOptionPane.showMessageDialog(null,guess[k]+"=PICO (^-^)");
}
else
JOptionPane.showMessageDialog(null,guess[k]+"=NANO (x_x)");
}
if(guess==random && guess==random && guess==random)
value.totalWin();
else
value.totalLose();

value.totalPlay();
JOptionPane.showMessageDialog(null,value);

valid();
}

public static void quit()
{

JOptionPane.showMessageDialog(null,"Come and play again!"+
"\nBye Bye!");
}

}```
why the number of total play, total win and total lose does't increase even if i play it for more than 1 time?..
tq.  Reply With Quote

2. ## Can you ask your question more specifically. You just post two classes here and who know regarding what code you are talking here.  Reply With Quote

3. Member Join Date
Mar 2009
Posts
7
Rep Power
0

## this is a program that ask user to enter 3 numbers,If the digit guessed for a given position is correct, then the reply is Fermi. If the digit guessed for a given position is in a different position, the reply is Pico. If the digit guessed for a given position does not match any of these three digits, then the reply is Nano. then i need to show the number of total play, total win and total lose after each game.
but my problem is, if i didnt get 3 correct,the number of total play is always 1,total of win is always zero and total lose is always 1, even when i play it for the 3rd or 4th time..
how can i change my coding so that after the 2nd time i play, the number of total play will be two and so on.  Reply With Quote

4. Senior Member Join Date
Dec 2008
Location
Hong Kong
Posts
473
Rep Power
13

## i find that you construct fermi value everytime when result method call.
you do not "save" any info to used by next result method call  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•