public class fermi
{
	private int[] guess;
	private int[] random;
	private int total;

	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];

		total=0;
	}
	public int totalPlay()
	{
		return total+=1;
	}



}
import javax.swing.JOptionPane;
import java.util.Random;

public class playFermi
{
	public static void main(String [] args)
	{
		final int Num_Guess=3;
		int [] guess=new int [Num_Guess];
		String input;
		char ch;
		final int Num_Random=3;
		int [] random=new int [Num_Random];
		int quit;
		int win=0;
		int lose=0;
		Random ran=new Random();
		for(int j=0; j<random.length; j++)
		{
			random[j]=ran.nextInt(9);
		}

		input=JOptionPane.showInputDialog("Enter -1 to quit or else to play:");
		quit=Integer.parseInt(input);
		while(quit !=-1)
		{
			for(int i=0; i<guess.length; i++)
			{
				input=JOptionPane.showInputDialog("Enter your guess"+(i+1)+"(0-9):");
				ch=input.charAt(0);

				while(!Character.isDigit(ch))
				{
					input=JOptionPane.showInputDialog("Oops!Enter your guess"+(i+1)+"(0-9):");
					ch=input.charAt(0);
				}
				guess[i]=Integer.parseInt(input);

				while(guess[i]<0 || guess[i]>9)
				{
					input=JOptionPane.showInputDialog("Invalid number!!Please re-enter your guess "+(i+1)+"(0-9):");
					ch=input.charAt(0);
					while(!Character.isDigit(ch))
					{
						input=JOptionPane.showInputDialog("Oops!Enter your guess"+(i+1)+"(0-9):");
						ch=input.charAt(0);
					}
					guess[i]=Integer.parseInt(input);
				}
			}


			fermi give=new fermi(guess,random);

			for(int k=0;k<3;k++)
			{
				if(guess[k]==random[0])
				{
					JOptionPane.showMessageDialog(null,"FERMI");
				}
				else if(guess[k]==random[1] || guess[k]==random[2])
				{
					JOptionPane.showMessageDialog(null,"PICO");
				}
				else
				JOptionPane.showMessageDialog(null,"NANO");
			}
			if(guess[0]==random[0] && guess[1]==random[1] && guess[2]==random[2])
			win+=1;
			else
			lose+=1;
			input=JOptionPane.showInputDialog("Enter -1 to quit");
			quit=Integer.parseInt(input);


			give.totalPlay();
		}
	JOptionPane.showMessageDialog(null,"total play is "+give.totalPlay()+"\ntotal win is"+win+"\ntotal lose is"+lose);
}

}

i get an error said that cannot find symbol
symbol : variable give
what's wrong with my code?
pls help!
tq.

The problem is you declare 'give' inside this while loop while(quit !=-1) but then this loop ends at the '}' after give.totalPlay(); , so that the 'give' variable goes out of scope and at this statment JOptionPane.showMessageDialog(null,"total play is "+give.totalPlay()+"\ntotal win is"+win+"\ntotal lose is"+lose); the compiler cannot find a declaration for give.

Move the declaration for give outside of the while loop so that it doesn't fall out scope before you want to reference to it.

i solved it already!..
i create another constructor in d class and declare another statement outside the loop..
thanks for helping me..

>i create another constructor in d class and declare another statement outside the loop..

Are you creating another instance of 'fermi', I am not sure how that helps, but anyways if it solves your query, just mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.