Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7912347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:34:42+00:00 2026-06-03T13:34:42+00:00

for an assignment in my Java class I’m supposed to write a program for

  • 0

for an assignment in my Java class I’m supposed to write a program for that creates a Tria Game between two players and I have the program done but she wants us to add on to it too. “Complete the Question class as is described. Add a method that turns the array of 10 answers into a 2D array and returns the 2D array.

In the tester, add the information for each player’s answered questions into a 2d array (2 players, 5 questions each).

Display the correct answers (call the new method in Question) and then display the 2D array with player’s answers. Finally, display the points for each player and the player who won.”

Any help with how I can go about doing this? I appreciate any help that you can give me.

Here is my code so far, first is my class called “Question” and second is the tester called “Trivia Game”

public class Question
{
  String question;
  String possibleAns1;
  String possibleAns2;
  String possibleAns3;
  String possibleAns4;
  int CorrectAnsNum;

  Question(String ques, String ans1, String ans2, String ans3, String ans4, int num)
  {
    question = ques;
    possibleAns1 = ans1;
    possibleAns2 = ans2;
    possibleAns3 = ans3;
    possibleAns4 = ans4;
    CorrectAnsNum = num;
  }

  Question(){
  }

  String getQuestion(){
    return question;
  }

  String getAns1(){
    return possibleAns1;
  }

  String getAns2(){
    return possibleAns2;
  }

  String getAns3(){
    return possibleAns3;
  }

  String getAns4(){
    return possibleAns4;
  }

  int getCorrectAnsNum(){
    return CorrectAnsNum;
  }

  void setQuestion(String newQuestion){
    question = newQuestion;
  }

  void setAns1(String newPossibleAns1){
    possibleAns1 = newPossibleAns1;
  }

  void setAns2(String newPossibleAns2){
    possibleAns2 = newPossibleAns2;
  }

  void setAns3(String newPossibleAns3){
    possibleAns3 = newPossibleAns3;
  }

  void setAns4(String newPossibleAns4){
    possibleAns4 = newPossibleAns4;
  }

  void setCorrectAnsNum(int newCorrectAnsNum){
    CorrectAnsNum = newCorrectAnsNum;
  }
}

///////////TESTER

import java.util.ArrayList;
import java.util.Scanner;

public class TriviaGame
{
  public static void main(String args[])
  {
    Scanner input = new Scanner(System.in);

    int pointsPlayer1 = 0;
    int pointsPlayer2 = 0;

    Question q1 = new Question("How many days are there in a week?", "5", "2", "7", "57", 3);
    Question q2 = new Question("What is the first month of the year?", "February", "January", "December", "August", 2);
    Question q3 = new Question("How many hours are there in one day?", "32", "12", "0", "24", 4);
    Question q4 = new Question("What is the capital of Massachusetts?", "Framingham", "Worcester", "Boston", "Springfield", 3);
    Question q5 = new Question("At what age are you legally aloud to buy lottery tickets", "18", "16", "21", "19", 1);
    Question q6 = new Question("What sport can you hit a homerun in?", "Golf", "Football", "Soccer", "Baseball", 4);
    Question q7 = new Question("Which one of these fruits is yellow?", "Apple", "Banana", "Strawberry", "Grape", 2);
    Question q8 = new Question("Who is the current president of the United States?", "Bill Clinton", "George Bush", "Barack Obama", "Jason Statham", 3);
    Question q9 = new Question("What is the highway speed limit in most areas?", "85", "65", "35", "110", 2);

    Question q10 = new Question();
    q10.setQuestion("What is the company that makes the iPod?");

    q10.setAns1("Microsoft");
    q10.setAns2("Verizon");
    q10.setAns3("Apple");
    q10.setAns4("Walmart");
    q10.setCorrectAnsNum(3);

    ArrayList<Question> questionList = new ArrayList<Question>();

    questionList.add(q1);
    questionList.add(q2);
    questionList.add(q3);
    questionList.add(q4);
    questionList.add(q5);
    questionList.add(q6);
    questionList.add(q7);
    questionList.add(q8);
    questionList.add(q9);
    questionList.add(q10);

    System.out.println("****Player1****");

    for(int i = 0; i < 5; i++)
    {
      Question q = questionList.get(i);

      System.out.println("\n" + (i+1) + ". " + q.getQuestion());
      System.out.println("1) " + q.getAns1());
      System.out.println("2) " + q.getAns2());
      System.out.println("3) " + q.getAns3());
      System.out.println("4) " + q.getAns4());

      System.out.print("Enter your answer: ");
      int userAns = input.nextInt();

      if (userAns == q.getCorrectAnsNum())
        pointsPlayer1++;
    }

    System.out.println("\n****Player2****");

    for(int i = 5; i < 10; i++)
    {
      Question q = questionList.get(i);

      System.out.println("\n" + (i+1) + ". " + q.getQuestion());
      System.out.println("1) " + q.getAns1());
      System.out.println("2) " + q.getAns2());
      System.out.println("3) " + q.getAns3());
      System.out.println("4) " + q.getAns4());

      System.out.print("Enter your answer: ");
      int userAns = input.nextInt();

      if (userAns == q.getCorrectAnsNum())
        pointsPlayer2++;
    }

    System.out.println("\n****Points Earned****");
    System.out.println("Player 1: " + pointsPlayer1);
    System.out.println("Player 2: " + pointsPlayer2);

    if (pointsPlayer1>pointsPlayer2)
      System.out.println("\nPlayer 1 is the winner! ");
    else if (pointsPlayer1<pointsPlayer2)
      System.out.println("\nPlayer 2 is the winner! ");
    else
      System.out.println("\nIt's a tie! ");
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:34:42+00:00Added an answer on June 3, 2026 at 1:34 pm

    In java, you can declare arrays of arrays, which then are two-dimensional:

    String[][] allAnswers = new String[10][4];
    

    Now, you can iterate through the outer array:

    for (String[] questionAnswers : allAnswers) {
    

    The variable questionAnswers is an array of String. You can then iterate through this inner array, and set the answers:

    questionAnswers[0] = "Answer 1";
    // ...
    

    Note that arrays in java are always zero-based, so the first answer belongs to index 0.

    You also can access a specific field using the index operators:

    System.out.println("Second answer of question 3 is: " questionAnswers[2][1];
    

    If this was not quite clear to you, you should read a tutorial on multidimensional arrays in java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm taking a beginning Java class and an assignment requires that I write a
I have an assignment in my java class that i need to recursively print
We have a java assignment where in we're supposed to develop a method that
ok so my assignment I'm supposed to write a class that stores a temperature
I have to write a multiplayer pacman game in Java for a university assignment
My class assignment is to write a program that has the user input a
My Java assignment is to to write a Java application that uses data from
I am working on a short java assignment that I have been set. The
I have to create a CD inventory program for my first Java class. The
Working on my assignment for Java and I have created a class called Triangle.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.