Results 1 to 7 of 7
  1. #1
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default Who Wants to Be a Millionaire? need help

    i making simple program which is based on "Who Wants to Be a Millionaire?" for the indian version of "Kaun Banega Crorepati"

    rules for this game are simple

    1. for ever correct answere who won some prize
    2. for every question there are four options and only one is correct
    3. you can quit the question if doent know the answere and the games the won prize money with you



    Java Code:
    No.	Right Answer Value	Missed Answer Value	Walk Away Value	Wrong Answer Loss
    1	 1,000	                       0	                           0           	         0
    2	 2,000	                       0	                          1,000	        1,000
    3	 3,000	                       0	                          2,000	        2,000
    4	 5,000	                       0	                          3,000	        3,000
    5	 10,000	                       0	                          5,000	        5,000
    6	 20,000	                       10,000	                    10,000	          0
    7	 40,000	                       10,000	                     20,000	       10,000
    8	 80,000	                       10,000	                     40,000	        30,000
    9	 1,60,000 (160,000)	       10,000	                     80,000	        70,000
    10	 3,20,000 (320,000)	       10,000	                    1,60,000	        1,50,000
    11	 6,40,000 (640,000)	      320,000	                    320,000	            0
    12	 12,50,000 (1,250,000)	      320,000	                    640,000	        320,000
    13	 25,00,000 (2,500,000)	      320,000	                  1,250,000	        930,000
    14	 50,00,000 (5,000,000)	      320,000	                  2,500,000	      2,180,000
    15	 1,00,00,000 (10,000,000)   320,000	                  5,000,000	       4,680,000
    for info this game visit Kaun Banega Crorepati - Wikipedia, the free encyclopedia

    i dived question based on there answere i.e
    q1 contains question have answere as years
    q2 contains question whic have answere as name of states
    a1 a2 contains correct answere corresponding to there there index

    eg q1[0]="Vande Mataram was first sung at the session of the Indian National Congress in"
    so correct answere is a1[0]=1896

    o1,o2 contains wrong options that will be randomly selected

    money[]=the price money ladder
    com1[],com2[],com3[] are only to program more interseting

    qch randomly from which question array should be selcted q1 or q2

    after that it ramdonly selcets the postion to place correct option using ra and postion of correct answere is stored in ans

    the program is running
    but it sometime genrates two options same

    i want to resolve this problem

    plus i want to 3 more funtionaly i.e 3 helping for the player

    phone a friend
    it randoms selects any of the options displayed to the user

    50-50
    it randoms removes any of the 2 options displayed to the user

    audience poll
    option 1=10%
    option 2=20%
    option 3=20%
    option4 =50%
    ------
    100%


    Java Code:
    import java.util.*;
    class kbc
    {
    	public static void main(String ar[])
    	{
    		String q1[]={"Vande Mataram was first sung at the session of the Indian National Congress in",
    				"The Battle of Plassey was fought in",
    				"The system of competitive examination for civil service was accepted in principle in the year",
    				"Universities in the Presidency towns in India were established in",};
    		String a1[]={"1896","1757","1853","1857",};
    		String o1[]={"1892","1904","1886","1782","1748","1764","1897","1823","1899","1858","1900","1909",};
    		String q2[]={"qutab minar is in which state",
    				"which place is I.T hub of india",
    				"which state has biggest slum in INdia",
    				"_________ is called pink city "};
    		String a2[]={"New delhi","banlore","mumbai","jaipur"};
    		String o2[]={"u.p","bihar","tamil naidu","agra","chennia","kolkata","haryana","punjab"};
    		int money[]={0,1000,2000,3000,5000,10000,20000,40000,80000,160000,320000,640000,1250000,2500000,5000000,10000000};
    		String com1[]={"amithab: coumpter ji what is next question",
    				"amithab :next question pesh kare",
    				"amithab: kya next question  ke liye ready hai",
    				"amithab : nexy question hai"};
    		String com2[]={"amithab: shhhh ap har gaye",
    				"amithab :app har gaye",
    				"amithab:apke sapne aduhre rahe gaye ",
    				"amithab: app yeah kar sakte the",
    				"amithab: apne bahut acha kelhla",
    				"amithab jingayi me har jeet hoti hoti rahti hai"};
    		String com3[]={"amithab:kya lagte hai apke sahi answere kya tha",
    				"amithab: kya apko isks answere atha tha",
    				"amithab: kon sa option app ko laga ke sahi answere hai",
    				"amithab: apne bahut acha khela"};
    		Random r= new Random();
    		int qch,ra,rq=0,ans=0,nextq=0,m=1,bal=0;
    		do{
    		System.out.println("\033"); 
    		qch=r.nextInt(2);
    		int len1=o1.length;
    		int len2=o2.length;
    		System.out.println("\n\nyou have won= "+money[bal]+"\n");
    		System.out.println("\n\n\t\t\tThis question is for Rs"+money[m]+"\n\n");		
    		if(qch==0)
    		{
    			rq=r.nextInt(4);
    			System.out.println(q1[rq]);
    			ra=r.nextInt(4);
    			if(ra==0)
    			{
    				System.out.println(a1[rq]);
    				for(int i=0;i<3;i++)
    				System.out.println(o1[r.nextInt(len1)]);
    				ans=1;
    			}
    			if(ra==1)
    			{
    				System.out.println(o1[r.nextInt(len1)]);
    				System.out.println(a1[rq]);
    				for(int i=0;i<2;i++)
    				System.out.println(o1[r.nextInt(len1)]);
    				ans=2;
    			}
    			if(ra==2)
    			{
    				for(int i=0;i<2;i++)
    				System.out.println(o1[r.nextInt(len1)]);
    				System.out.println(a1[rq]);
    				System.out.println(o1[r.nextInt(len1)]);
    				ans=3;
    			}
    			if(ra==3)
    			{
    				for(int i=0;i<3;i++)
    				System.out.println(o1[r.nextInt(len1)]);
    				System.out.println(a1[rq]);
    				ans=4;
    			}	
    				
    		}
    		if(qch==1)
    		{
    			rq=r.nextInt(4);
    			System.out.println(q2[rq]);
    			ra=r.nextInt(4);
    			if(ra==0)
    			{
    				System.out.println(a2[rq]);
    				for(int i=0;i<3;i++)
    				System.out.println(o2[r.nextInt(len2)]);
    				ans=1;
    			}
    			if(ra==1)
    			{
    				System.out.println(o2[r.nextInt(len2)]);
    				System.out.println(a2[rq]);
    				for(int i=0;i<2;i++)
    				System.out.println(o2[r.nextInt(len2)]);
    				ans=2;
    			}
    			if(ra==2)
    			{
    				for(int i=0;i<2;i++)
    				System.out.println(o2[r.nextInt(len2)]);
    				System.out.println(a2[rq]);
    				System.out.println(o2[r.nextInt(len2)]);
    				ans=3;
    			}
    			if(ra==3)
    			{
    				for(int i=0;i<3;i++)
    				System.out.println(o2[r.nextInt(len2)]);
    				System.out.println(a2[rq]);
    				ans=4;
    			}	
    				
    		}
    		
    		Scanner sc=new Scanner(System.in);
    		int uans;
    		System.out.println("\n\n\n\t\t\tenter your answere 1,2,3,4\n");
    		System.out.println("\n\n\n\t\t\tif you want to quit enter 5\n");
    		uans=sc.nextInt();
    		if(uans==ans)
    		{
    			System.out.println("\n\n\n\t\t\tCorrect answere\n\n\n\n");
    			nextq=1;m++;bal++;
    			if(m==14)
    			{
    				System.out.println("\n\ncongrats\t\t\t\t\t\t\tcongrats");
    				System.out.println("\n\n\t\t\t\t\t\tyou are new Crorepati\n\n\n");
    				System.out.println("\n\ncongrats\t\t\t\t\t\t\tcongrats");
    			}
    		}
    		else if(uans==5)
    		{
    			System.out.println("\t\t\tyou have quited this question");
    			System.out.println(com3[r.nextInt(4)]);
    			System.out.print("\t\tthe answere to the question was ");
    			if(qch==0)
    				System.out.println("option "+ans+" "+a1[rq]);
    			if(qch==1)
    				System.out.println("option "+ans+" "+a2[rq]);
    			nextq=0;
    		}
    		else
    		{
    			nextq=0;
    			System.out.println("\n\n\t\t\twrong answere\n");
    			System.out.println(com2[r.nextInt(6)]);
    			System.out.print("\t\t\t you have won=");
    			if((money[bal]<10000)&&(money[bal]>=0))
    			System.out.println("0");
    			if((money[bal]<320000)&&(money[bal]>=10000))
    			System.out.println("10000");
    			if((money[bal]<10000000)&&(money[bal]>=320000))
    			System.out.println("320000");
    		}
    		if(nextq==1)
    			System.out.println(com1[r.nextInt(4)]);
    		}while(nextq==1);
    	}
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Don't do everything in the main method. Split the functionality into separate, well defined methods and classes.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    Did the OP have a question?

  4. #4
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Did the OP have a question?
    the program is running
    but it sometime genrates two options same

    i want to resolve this problem

    plus i want to 3 more funtionaly i.e 3 helping for the player

    phone a friend
    it randoms selects any of the options displayed to the user

    50-50
    it randoms removes any of the 2 options displayed to the user

    audience poll
    option 1=10%
    option 2=20%
    option 3=20%
    option4 =50%

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    but it sometime genrates two options same
    Have you tried adding printlns to debug the code?

  6. #6
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Have you tried adding printlns to debug the code?
    i dont know how to debug

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    i dont know how to debug
    Are you trying to learn how to be a programmer?
    You will need to learn.
    My style of debugging includes adding printlns to the code to show the values of variables as they are used and as they change. If you have an interactive debugger, it can be much easier than this.
    The programmer that writes a program should know how his variables should change as the code executes. By printing out their values he can see if the program is using the variables properly. When he sees that a variable is getting an invalid value, then he can look at that location in the code to see why that is happening.

Posting Permissions

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