>tfw I'm trying to create a trivia program

BaconShelf | Mythic Inconceivable!
 
more |
XBL: BaconShelf
PSN:
Steam: BaconShelf
ID: BaconShelf
IP: Logged

10,737 posts
 
My advice would be define each question/ answer and the input/ output of such as a function, then give that function a number variable (IE question==1)

Then use a random module to choose a random number between the amount of numbers you assigned and it then run that function.

Or use a list and use the random to select which place in the list it should look, then removing that number from the list.
You could also import a file for questions and a file for answers, and have the matching pair on the same line. That would make it easier to edit them without recompiling the code.


I'm going off what I know for python, which unfortunately cannot import other files. I just write functions (Or is it modules? I get confused) and then recall them later. It's the next best thing.
Pretty sure you can read an external file in Java.


Well I know that Minecraft has hundreds of files and that's java, so I'm inclined to agree.


The way is write the questions would be more like this, though:

"What is the capital of England?"

If input=="London":
    Output "+1 point"

Else:
    Output"-1 point"


And then return to the file


The thing I wrote above was more for selecting a question at random


 
Naru
| The Tide Caller
 
more |
XBL: Naru No Baka
PSN:
Steam: The Tide Caller
ID: GasaiYuno
IP: Logged

18,501 posts
The Rage....
My advice would be define each question/ answer and the input/ output of such as a function, then give that function a number variable (IE question==1)

Then use a random module to choose a random number between the amount of numbers you assigned and it then run that function.

Or use a list and use the random to select which place in the list it should look, then removing that number from the list.

So (I use python so it would have to be tweaked a bit)

def q1():
    *question 1 function*

def q2():
   *question 2 function*

q1=1
q2=2

list[1,2]

a=rand.number(0,1)


list[a]



I hope that made sense
omg wat


I edited the last part because it made no sense.


Essentially, write the question as a function, so it can be called later.

def q1():
        *question and answer input and shit*

def q2():
      *same as above*



Then put those into a list

list[q1,q2]

Then use a random number (In this case 0 or 1) and assign it to a variable

A=rand.number(0,1)

Then use A in the list to recall that function and run it.

list[a]

When I'm on a computer tomorrow I'll write a basic one in python for you to look at if you like. It's kind of hard to explain.
The assignment is due today :/

I'm close to finishing it, but I'm stumped at how to make words into answers.


BaconShelf | Mythic Inconceivable!
 
more |
XBL: BaconShelf
PSN:
Steam: BaconShelf
ID: BaconShelf
IP: Logged

10,737 posts
 
My advice would be define each question/ answer and the input/ output of such as a function, then give that function a number variable (IE question==1)

Then use a random module to choose a random number between the amount of numbers you assigned and it then run that function.

Or use a list and use the random to select which place in the list it should look, then removing that number from the list.

So (I use python so it would have to be tweaked a bit)

def q1():
    *question 1 function*

def q2():
   *question 2 function*

q1=1
q2=2

list[1,2]

a=rand.number(0,1)


list[a]



I hope that made sense
omg wat


I edited the last part because it made no sense.


Essentially, write the question as a function, so it can be called later.

def q1():
        *question and answer input and shit*

def q2():
      *same as above*



Then put those into a list

list[q1,q2]

Then use a random number (In this case 0 or 1) and assign it to a variable

A=rand.number(0,1)

Then use A in the list to recall that function and run it.

list[a]

When I'm on a computer tomorrow I'll write a basic one in python for you to look at if you like. It's kind of hard to explain.
The assignment is due today :/

I'm close to finishing it, but I'm stumped at how to make words into answers.


What do you mean?


 
Naru
| The Tide Caller
 
more |
XBL: Naru No Baka
PSN:
Steam: The Tide Caller
ID: GasaiYuno
IP: Logged

18,501 posts
The Rage....
My advice would be define each question/ answer and the input/ output of such as a function, then give that function a number variable (IE question==1)

Then use a random module to choose a random number between the amount of numbers you assigned and it then run that function.

Or use a list and use the random to select which place in the list it should look, then removing that number from the list.

So (I use python so it would have to be tweaked a bit)

def q1():
    *question 1 function*

def q2():
   *question 2 function*

q1=1
q2=2

list[1,2]

a=rand.number(0,1)


list[a]



I hope that made sense
omg wat


I edited the last part because it made no sense.


Essentially, write the question as a function, so it can be called later.

def q1():
        *question and answer input and shit*

def q2():
      *same as above*



Then put those into a list

list[q1,q2]

Then use a random number (In this case 0 or 1) and assign it to a variable

A=rand.number(0,1)

Then use A in the list to recall that function and run it.

list[a]

When I'm on a computer tomorrow I'll write a basic one in python for you to look at if you like. It's kind of hard to explain.
The assignment is due today :/

I'm close to finishing it, but I'm stumped at how to make words into answers.


What do you mean?
Question: What class are you going to play?

Answers : Hunter, Faggot, Whorelock

Have user input one of those choices to be correct. String variables and stuff


BaconShelf | Mythic Inconceivable!
 
more |
XBL: BaconShelf
PSN:
Steam: BaconShelf
ID: BaconShelf
IP: Logged

10,737 posts
 
My advice would be define each question/ answer and the input/ output of such as a function, then give that function a number variable (IE question==1)

Then use a random module to choose a random number between the amount of numbers you assigned and it then run that function.

Or use a list and use the random to select which place in the list it should look, then removing that number from the list.

So (I use python so it would have to be tweaked a bit)

def q1():
    *question 1 function*

def q2():
   *question 2 function*

q1=1
q2=2

list[1,2]

a=rand.number(0,1)


list[a]



I hope that made sense
omg wat


I edited the last part because it made no sense.


Essentially, write the question as a function, so it can be called later.

def q1():
        *question and answer input and shit*

def q2():
      *same as above*



Then put those into a list

list[q1,q2]

Then use a random number (In this case 0 or 1) and assign it to a variable

A=rand.number(0,1)

Then use A in the list to recall that function and run it.

list[a]

When I'm on a computer tomorrow I'll write a basic one in python for you to look at if you like. It's kind of hard to explain.
The assignment is due today :/

I'm close to finishing it, but I'm stumped at how to make words into answers.


What do you mean?
Question: What class are you going to play?

Answers : Hunter, Faggot, Whorelock

Have user input one of those choices to be correct. String variables and stuff


I'd set the answer as one of those:

answer=hunter

Then ask for an input and use an if statement to decide what to do next:

userchoice=input()
if userchoice==answer:
   Output ("You got it right")
else:
    Output ("you got it wrong")

That way, you can just change hunter to whatever you want it to be and the program does the rest.

Though I'm not sure how if statements work in java, so you may need to alter accordingly. Likewise, change output to print or whatever java uses to display text.