Computer Science Canada

Millionaire Project

Author:  rto [ Wed Oct 08, 2008 10:39 am ]
Post subject:  Millionaire Project

By no means is my code going to be flawless but it works as of right now. i have to add in the 3 lifelines but i want it so that once one is used, it will not be available for a second use. Please help if you can, critism (unless constructive) is not helpful Smile thank you

Java:

// Make 3 variables - 5050Count, PhoneCount, AudienceCount//
import java.io.DataInputStream;
import java.io.*;
class millionaire
{
        public static void main ( String [] args ) throws IOException
        {       
                //Works as Who wants to be a Millionaire. If you answer correct you will gain money whilst if you answer incorrectly you will lose money.
                BufferedReader input = new BufferedReader ( new InputStreamReader ( System.in ) );
                String answer;
                System.out.println( "\n\n\nPLEASE ANSWER ALL QUESTIONS BY INPUTTING LETTERS 'a' - 'd' ON YOUR KEYPAD! \n**Please be sure to only use Lower Case letters" );
                System.out.println ( "Your first question worth $100.00 is : \nIn Canada how much is a dime worth?" );
                System.out.println ( "(a) 10 cents" );
                System.out.println ( "(b) $1,000,000" );
                System.out.println ( "(c) 5 cents" );
                System.out.println ( "(d) 25 cents\n" );
                answer = input.readLine();
                System.out.println( " " );
                if ( answer .equals( "a") || answer .equals ("A") ) {
                        System.out.println( "Congratulations! You have $100.00" );
                        System.out.println( "$100 - Completed\n$200\n$400\n$1,000\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                                }
                else {
                        System.out.println ( "I'm Sorry, that answer is incorrect. Your total winnings are $0" );
                        System.out.println ( "$100 - Epic Fail\n$200\n$400\n$1,000\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000" );
                        System.exit(0);    
                        }
                System.out.println( "Your second question worth $200.00 is :\nWhich of the following is no longer an NHL Hockey team?" );
                System.out.println( "(a) Minnesota Wild" );
                System.out.println( "(b) Quebec Nordiques" );
                System.out.println( "(c) Nashville Predators" );
                System.out.println( "(d) Edmonton Oilers\n" );
                answer = input.readLine ();
                System.out.println ( " " );
                if ( answer .equals ("b") || answer .equals ("B")) {
                        System.out.println("Congratulations! You have $200.00!");
                        System.out.println( "$100 - Completed\n$200 - Completed\n$400\n$1,000\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        }
                else {
                        System.out.println ("I'm Sorry, that answer is incorrect. Your total winnings are $0");
                        System.out.println ( "$100 - Completed\n$200 - Epic Fail\n$400\n$1,000\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        System.exit(0)
                        }
                System.out.println("So far so good! your next question is worth $400.00");
                System.out.println("In order -> Bit, Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, what?");
                System.out.println("(a) Exobyte");
                System.out.println("(b) Yottabyte");
                System.out.println("(c) Pentabyte");
                System.out.println("(d) Filtabyte\n");
                answer = input.readLine();
                System.out.println(" ");
                if ( answer .equals ("c") || answer .equals ("C")) {
                        System.out.println ("Congratulations! You have $400.00");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        }
                else {
                        System.out.println ("I'm Sorry, that answer is incorrect. Your total winnings are $0");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Epic Fail\n$1,000\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        System.exit(0)
                        }
                System.out.println ("Fantastic Job! Now this next question is very important to you because it is a milestone question!\n");
                System.out.println ("For $1000.00 : Which of the following is the capital of Alaska?");
                System.out.println( "(a) Juneau" );
                System.out.println( "(b) Anvik" );
                System.out.println( "(c) Chignik" );
                System.out.println( "(d) Deering\n" );
                answer = input.readLine();
                System.out.println(" ");
                if ( answer .equals ("a") || answer .equals ("A") ) {
                        System.out.println ("Congratulations! You have $1000.00");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000 - Completed\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        }
                else {
                        System.out.println ("Im Sorry that answer is incorrect. Your total winnings are $0");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000 - Epic Fail\n$2,000\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        System.exit(0);
                        }
                System.out.println ("Alright. You are at $1000.00 and you cannot leave with less than that today! There is still alot of game to play hower\n");
                System.out.println ("For  $2000.00: What is the name of the book written by Ernest Vincent Wright containing over 50,000 words, none of which have the letter 'e'?");
                System.out.println ("(a) Aaron Trow");
                System.out.println ("(b) A Christmas Carol");
                System.out.println ("(c) A-Z without the 'e'");
                System.out.println ("(d) Gadsby\n");
                answer = input.readLine();
                if ( answer .equals ("d") || answer .equals ("D")) {
                        System.out.println ("Congratulations! You have $2000.00");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000 - Completed\n$2,000 - Completed\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        }
                else {
                        System.out.println ("Im Sorry that answer is incorrect. Your total winnings are $1000.00");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000 - Completed\n$2,000 - Epic Fail\n$8,000\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        System.exit(0);
                        }
                System.out.println("In mathematics, a 'factorial' is shown as which of the following symbols?");
                System.out.println("(a) *");
                System.out.println("(b) !");
                System.out.println("(c) |");
                System.out.println("(d) ^\n");
                answer = input.readLine();
                if ( answer .equals ("b") || answer .equals ("B") ) {
                        System.out.println ("Congratulations! You have $8000.00");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000 - Completed\n$2,000 - Completed\n$8,000 - Completed\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        }
                else {
                        System.out.println ("Im Sorry that answer is incorrect. Your total winnings are $1000.00");
                        System.out.println ( "$100 - Completed\n$200 - Completed\n$400 - Completed\n$1,000 - Completed\n$2,000 - Completed\n$8,000-Epic Fail\n$25,000" );
                        System.out.println( "$50,000\n$150,000\n$500,000\n$1,000,000\n" );
                        System.exit(0);
                        }
        }
}

Author:  S_Grimm [ Wed Oct 08, 2008 11:31 am ]
Post subject:  RE:Millionaire Project

int 5050count = 0;
int phoneafriendcount = 0;
int asktheaudiencecount =0;
if (answer.equals("lifeline")){
System.out.println ("What lifeline do you want to use?")
answer = input.readLine();
if (answer.equals (5050)) && (5050count == 0) {
//code for taking away 2 wrong aswers
}
//repeat for other 2 lifelines and if counts = 1 then have an error message displayed (ie. you already used that lifeline)

Author:  chrisbrown [ Wed Oct 08, 2008 12:12 pm ]
Post subject:  RE:Millionaire Project

For your $400 question, its petabyte, not pentabyte. Just pointing that out

Author:  Insectoid [ Wed Oct 08, 2008 12:27 pm ]
Post subject:  RE:Millionaire Project

Yay! I did it with no errors!

Anywho,

Would it not be possible to have a class for questions, then make objects of the actual questions? or a method where you sub in the question, answers, and whatever, and just have it do the calculations.

Yes, I know, I explained it horridly, but that is because I have forgotten the terminology.

Author:  S_Grimm [ Thu Oct 09, 2008 7:48 am ]
Post subject:  RE:Millionaire Project

he still wants LIFELINES not questions.

Author:  rto [ Thu Oct 09, 2008 7:51 am ]
Post subject:  RE:Millionaire Project

thanks methodox your right and insectoid its because your incredible lmao . A\V is correct however, any ideas how to put lifelines in there? i put a comment at the top for my ideas but im not sure if that will work or not

Author:  Insectoid [ Thu Oct 09, 2008 11:34 am ]
Post subject:  RE:Millionaire Project

Oh, Well, I put that in there because I figured you could shrink the code by...a lot.

Author:  wtd [ Thu Oct 09, 2008 11:52 am ]
Post subject:  RE:Millionaire Project

Insectoid is right. Especially given that this is Java, you should model the questions as objects, and just have a collection of them.

Author:  rto [ Fri Oct 10, 2008 7:37 am ]
Post subject:  Re: Millionaire Project

To be quite honest guys, im really new to java. Just trying to self teach myself out of a book right now (Java for AP Computer Science), and i havent quite gotten to the making new classes / methods section Razz soon as i do thow Smile

Author:  jbking [ Fri Oct 10, 2008 9:56 am ]
Post subject:  RE:Millionaire Project

My guess would be to think about how do you want the user to communicate, "I want to use a lifeline," in the program. For example, here are a couple of ideas on how this could be done:

1) Each question comes with 2 parts. The first asks if you want to use a lifeline here and then which one if so.

2) Each answer can take a 1-3 value for the lifeline to use and check against some small array to see if that has been used, e.g. lifeline[0] for 50/50, lifeline[1] for Phone a friend, lifeline[2] for Ask the Audience. Note here that this is slightly different in terms of how the logic is coming in since you may have someone try to use a lifeline just by putting in the same digit repeatedly.

My suggestion is to think about how do you want the user to use their lifelines in terms of the input and then figure out the details of what the program has to track.

Author:  wtd [ Fri Oct 10, 2008 10:54 am ]
Post subject:  RE:Millionaire Project

http://wiki.compsci.ca/index.php?title=Introduction_To_Java

This covers creation of classes and methods very early on.

Author:  S_Grimm [ Fri Oct 10, 2008 11:28 am ]
Post subject:  RE:Millionaire Project

wtd, no offense, but he doesn't want to use methods and classes. He wants to be able to come up with a lifeline option using the existing code.

Author:  wtd [ Fri Oct 10, 2008 11:50 am ]
Post subject:  RE:Millionaire Project

He needs to, especially if there's no one holding him back.

Classes and methods are the very core fundamental way that code in Java is organized. They cannot be an afterthought.

Author:  S_Grimm [ Sun Oct 12, 2008 12:14 pm ]
Post subject:  RE:Millionaire Project

the teacher really doesn't want us "Jumping the gun" this year. Last year, half the class was so far ahead that he had to stop giving work to us in order for the rest to catch up. this year he wants to explain everything and go through it all with us, instead of us teaching ourselves. but i think that the idea of putting everything in classes and methods is very similar to turings procedures, no? whatever is inside the method can be called later on in the program?

Author:  wtd [ Sun Oct 12, 2008 12:54 pm ]
Post subject:  RE:Millionaire Project

That's a decent way to start looking at it.

Author:  rto [ Sun Oct 12, 2008 8:17 pm ]
Post subject:  RE:Millionaire Project

ok im gonna skip ahead and look at the creating methods / classes in my book sometime within the next week Smile


: