Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-15-2009, 06:35 PM
Member
 
Join Date: Mar 2009
Posts: 7
Rep Power: 0
rayda is on a distinguished road
Default why the number will not increase?
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()
	{
		return total+=1;
	}

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



}
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.");
		JOptionPane.showMessageDialog(null,"Are you ready to play?");

		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++)
		{
			input=JOptionPane.showInputDialog("Enter your guess"+(i+1)+"(0-9):");
			ch=input.charAt(0);
			while(!Character.isDigit(ch))
			{
				input=JOptionPane.showInputDialog("!!This is not an integer!!"+
													"\nPlease re-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!!"+
														"\nYou can only enter integer in between 0-9."+
														"\nPlease re-enter your guess "+(i+1)+"(0-9):");
					ch=input.charAt(0);
					while(!Character.isDigit(ch))
					{
						input=JOptionPane.showInputDialog("!!This is not an integer!!"+
															"\nPlease re-enter your guess"+(i+1)+"(0-9):");
						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[0])
			{
				JOptionPane.showMessageDialog(null,guess[k]+"=FERMI (^0^)");
			}
			else if(guess[k]==random[1] || guess[k]==random[2])
			{
				JOptionPane.showMessageDialog(null,guess[k]+"=PICO (^-^)");
			}
			else
			JOptionPane.showMessageDialog(null,guess[k]+"=NANO (x_x)");
		}
		if(guess[0]==random[0] && guess[1]==random[1] && guess[2]==random[2])
		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?..
please help.
tq.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-15-2009, 06:36 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,504
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Can you ask your question more specifically. You just post two classes here and who know regarding what code you are talking here.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-15-2009, 06:53 PM
Member
 
Join Date: Mar 2009
Posts: 7
Rep Power: 0
rayda is on a distinguished road
Default
sorry about it..
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-16-2009, 06:47 AM
Senior Member
 
Join Date: Dec 2008
Location: Hong Kong
Posts: 473
Rep Power: 2
mtyoung is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Increase signature length? xcallmejudasx Suggestions & Feedback 3 12-18-2008 07:04 PM
how to extract the number of the image which looks like a number Crest.Boy Java Servlet 1 11-03-2008 03:38 PM
increase pixel size rosh72851 New To Java 7 10-01-2008 08:14 PM
increase stack size in eclipse for highly recursive method. Daedalus Eclipse 3 09-27-2008 05:46 AM
gridbaglayout: increase/decrease size of components. newtojava7 New To Java 2 01-28-2008 08:22 AM


All times are GMT +2. The time now is 11:03 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org