Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!

# ARRAYS AND STRINGS

J Doggett
Greenhorn
Posts: 6
Am trying to do a question with no luck. This is the question that I am trying to do.
A) Write a program that displays a multiple choice quiz of 10 questions. Each question has one correct answer and three possible answers. Verify that the user enters only A, B, or C. as the answer. Store the correct answers in an array. Store the user's answers in a second array. If the user responds to a question correctly, display "Correct"; otherwise display "The correct answer is" and the letter of the correct answer. Determine what to display by comparing the response to the array of correct answers.
B) Modify the quiz class so that it displays the number of correct answers after the user answers 10 questions. Determine the score by comparing the two arrays.
This is what I have done so far:

/*package assignment4;

public class Quiz
{
public static void main(String[] args)throws Exception
{
char [] correctAns= {'A','B','C','D','A','B','C','D','A','B'};
char []stuAns = new char [10];
int x, tot = 0;
char ans;
System.out.println ("The following test has 10 multiple choice questions");
do
{ tot = 0;
for (x = 0; x< stuAns.length; ++x)
{
System.in.skip(System.in.available());
stuAns[x] = Character.toUpperCase(stuAns[x]);
if ( stuAns[x] == correctAns[x])
tot = tot + 1;
}
System.out.println ("You got " + tot +" right and " + (10 - tot) + " wrong");
System.out.println ("Do you want to try again ? ( 'Y' or 'N') ");
System.in.skip(System.in.available());
} while (ans == 'y' || ans =='Y') ;

}
}*/

Am I on the right track here.
I don't know how to get my question in there any where.
Any help that you could give me would be greatly appreciated.
thanks

Rovas Kram
Ranch Hand
Posts: 135
I'd store each question and answers set in 10 diferent String arrays of 4, for example

String[] one = {"What is your favorite color?", "red", "blue", "yellow"};

Store the correct answers and user answers in a int arrays, for example,

int[] correct = {1, 2, 3,...}; // 1=A, 2=B, 3=C
int[] user_thinks = new int[10];
If the user chooses answer B for question 2 => user_thinks[1] = 2;

Mark Spritzler
ranger
Sheriff
Posts: 17278
6
Hi J, welcome to JavaRanch.

Unfortunately, you have posted your Java In General questions in a Servlets forum.

This forum is for Servlets questions, and since you question is not about Servlets, I am going to move this to the Java In General (Beginner) forum.

Thanks

Mark