Results 1 to 7 of 7
- 07-14-2011, 06:00 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
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
- for ever correct answere who won some prize
- for every question there are four options and only one is correct
- you can quit the question if doent know the answere and the games the won prize money with you
for info this game visit Kaun Banega Crorepati - Wikipedia, the free encyclopediaJava 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
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); } }
- 07-14-2011, 06:18 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't do everything in the main method. Split the functionality into separate, well defined methods and classes.
- 07-14-2011, 06:19 PM #3
Did the OP have a question?
- 07-14-2011, 06:21 PM #4
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
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%
- 07-14-2011, 06:25 PM #5
Have you tried adding printlns to debug the code?but it sometime genrates two options same
- 07-14-2011, 08:53 PM #6
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
- 07-14-2011, 08:57 PM #7
Are you trying to learn how to be a programmer?i dont know how to debug
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.


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks