Question

In this programming exercise, you will create a simple trivia game for two players. The program...

In this programming exercise, you will create a simple trivia game for two players. The program will work like this:

Starting out with player 1, each player gets a turn at answering 5 trivia questions. (There should be a total of 10 questions.) When a question is displayed, 4 possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point.

After answers have been selected for all questions, the program displays the number of points earned by each player and declares the player with the highest number of points is the winner.

To create this program, write a Question class to hold the data for a trivia question. The Question class should have attributes for the following data:

A trivia question

Possible answer 1

Possible answer 2

Possible answer 3

Possible answer 4

The number of the correct answer (1, 2, 3, or 4)

The Question class also should have an appropriate constructor, accessors, and mutators. The Header file has been included for you to implement.

The program should have an array containing 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subjects of your choice for the objects and read Trivia Questions with possible answers and number of the correct answer from an input text file that you create (trivia.txt) in any format.

Sample Output (user input is bold)

Player 1:

What is 1 + 1?

1: 1

2: 2

3: 3

4: 4

Choose an answer by entering a number from 1 to 4.

2

Player 1:

What is 2 + 2?

1: 1

2: 2

3: 3

4: 4

Choose an answer by entering a number from 1 to 4.

1

Player 1:

What is 3 + 3?

1: 2

2: 4

3: 6

4: 8

Choose an answer by entering a number from 1 to 4.

1

Player 1:

What is 4 + 4?

1: 2

2: 4

3: 6

4: 8

Choose an answer by entering a number from 1 to 4.

3

Player 1:

What is 5 + 5?

1: 7

2: 8

3: 9

4: 10

Choose an answer by entering a number from 1 to 4.

2

Player 2:

What is 6 + 6?

1: 12

2: 14

3: 16

4: 18

Choose an answer by entering a number from 1 to 4.

1

Player 2:

What is 7 + 7?

1: 12

2: 14

3: 16

4: 18

Choose an answer by entering a number from 1 to 4.

2

Player 2:

What is 8 + 8?

1: 12

2: 14

3: 16

4: 18

Choose an answer by entering a number from 1 to 4.

3

Player 2:

What is 9 + 9?

1: 12

2: 14

3: 16

4: 18

Choose an answer by entering a number from 1 to 4.

1

Player 2:

What is 10 + 10?

1: 16

2: 18

3: 20

4: 22

Choose an answer by entering a number from 1 to 4.

4

Player 1 scored 1 points

Player 2 scored 3 points

The winner is Player 2

Press any key to continue . . .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static void initQuestions (questions qArray[]) throws IOException // Open the trivia.txt file. File file new File(tri// Display the stats System.out.println(Game Over!); System.out.println( System.out.println ( Player 1s points: System//Constructor public player(int playerNum) playerNumber = playerNum; points-0 public void chooseAnswer() // Create a Scanner

Add a comment
Know the answer?
Add Answer to:
In this programming exercise, you will create a simple trivia game for two players. The program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • the main problem i have with this project is getting the "trivia.txt" file to be printed...

    the main problem i have with this project is getting the "trivia.txt" file to be printed and stream correctly into my program. thanks. this is for c++ thanks In this programming challenge, you will create a simple trivia game for two players. The program will work like this: Starting with player 1, each player gets a turn at answering five trivia questions. (There are a total of 10 questions.) When a question is displayed, four possible answers are also displayed....

  • C only (not C++) Write a C program that simulates a game. There are two players...

    C only (not C++) Write a C program that simulates a game. There are two players (called Player1 and Player2). At the start of the game, each player chooses a number from 1 to 10 (cannot be the same). Then, the program will generate a random number from 1 to 10. The game ends when either Player1 or Player2 hits the number generated by the program. Display the winning message for the winner. Example output: Player 1: 6 Player 2:...

  • Use Java language to create this program Write a program that allows two players to play...

    Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...

  • java In this project you will implement a trivia game. It will ask random trivia questions,...

    java In this project you will implement a trivia game. It will ask random trivia questions, evaluate their answers and keep score. The project will also have an administrative module that will allow for managing the question bank. Question bank management will include adding new questions, deleting questions and displaying all of the questions, answers and point values. 2. The project can be a GUI or a menu based command line program. 3. Project details 1. Create a class to...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • java In this project you will implement a trivia game. It will ask random trivia questions, evaluate their answers and keep score. The project will also have an administrative module that will allow f...

    java In this project you will implement a trivia game. It will ask random trivia questions, evaluate their answers and keep score. The project will also have an administrative module that will allow for managing the question bank. Question bank management will include adding new questions, deleting questions and displaying all of the questions, answers and point values. 2. The project can be a GUI or a menu based command line program. 3. Project details 1. Create a class to...

  • Written in Python In this lab, you are to build a trivia game. The game should...

    Written in Python In this lab, you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got...

  • You will need to first create an object class encapsulating a Trivia Game which INHERITS from...

    You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: description - which is a string write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money - double 3. number of questions that must be answered to win - integer. 4. write the accessor, mutator, constructor,...

  • Hello I need help with python programming here is my code # Trivia Challenge # Trivia...

    Hello I need help with python programming here is my code # Trivia Challenge # Trivia game that reads a plain text file import sys def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program.\n", e) input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file):...

  • Create a Dice Game: PYTHON This game is between two people. They will roll a pair...

    Create a Dice Game: PYTHON This game is between two people. They will roll a pair of dice each 10 times. Each roll will be added to a total, and after 10 rolls the player with the highest total will be the Winner! You will use the RANDOM class RANDRANGE to create a random number from 1 to 6. You'll need a function for "rollDice" to roll a pair of dice and return a total of the dice. You must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT