Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Project Name: IC23_TriviaGame In this programming challenge you will create

ID: 3765779 • Letter: C

Question

C++ Project Name: IC23_TriviaGame

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. Only one of the answers is correct, and if the player selects the correct answer s/he earns a point.  

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

To succeed in this "pursuit", you will design a Question class to hold the data for a trivia question.

The Question class should have member variables 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 should have appropriate constructor(s), accessor, and mutator functions.  

The program should create an array of 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.

Explanation / Answer

the Question class

import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;

public class Question {
private static int NumberofQuest = 10;
private String[] question = new String[NumberofQuest] ;
private static int NumofAns=0;
private String[] possibleAns = new String[NumofAns];
private int[] correctAns = new int[NumberofQuest];
public Question()
{
question= null;
for (int i=0; i<= NumofAns; i++)
{
setPossibleAns("");
}
correctAns=null;
}

public static ArrayList<Object> createquestion(String filename) throws IOException
{
Question qArray[] = null;
File file = new File(filename);
Scanner line = new Scanner(file);

ArrayList<Object> qObject = new ArrayList<>();
while (line.hasNext())
{

for (int i=0; i<= NumberofQuest; i++)
{
qArray[i] = new Question();
qArray[i].setQuestion(line.nextLine());
qArray[i].setNumofAns(Integer.parseInt(line.nextLine()));
for (int j=0; j<= NumofAns; j++){
qArray[i].setPossibleAns(line.nextLine());
}
qArray[i].setNumofAns(Integer.parseInt(line.nextLine()));
qObject.add(qArray[i]);
}

}
return qObject;
}

public void setQuestion(String quest)
{
question[NumberofQuest]= quest;
}
public String[] getQuestion()
{
return question;
}
public void setNumofAns(int num)
{
NumofAns=num;
}
public int getNumofAns()
{
return NumofAns;
}
public void setPossibleAns(String ans)
{
possibleAns[NumofAns]= ans;
}
public String[] getPossibleAns()
{
return possibleAns;
}
public void setCorrectAns(int correctNum)
{
correctAns[NumberofQuest]= correctNum;
}
public int[] getCorrectAns()
{
return correctAns;
}
public static void displayQuestion(Question q, int playerTurn) throws IOException
{
System.out.println("Question for player #" + playerTurn);
System.out.println(q.getQuestion());
for (int i=0; i <= NumofAns; i++)
{
System.out.println(q.getPossibleAns());
}
}


}

////****This is my main class which is not completed cuz I don't know how to do it T.T

import java.io.IOException;
import java.util.ArrayList;
import java.lang.NumberFormatException;
public class TriviaGame {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
int playerturn=0;
ArrayList<Question> qArray = new ArrayList<>();

for (Question q : qArray)
{
q.createQuestion(question, playerturn);
}




}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote