*
The moose likes Beginning Java and the fly likes ARRAYS AND STRINGS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ARRAYS AND STRINGS" Watch "ARRAYS AND STRINGS" New topic
Author

ARRAYS AND STRINGS

J Doggett
Greenhorn

Joined: Mar 03, 2003
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.out.print ("Enter your answer for question " + (x+1)+ " ");
stuAns[x] = (char)System.in.read();
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') ");
ans = (char)System.in.read();
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

Joined: Aug 08, 2003
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

Joined: Feb 05, 2001
Posts: 17250
    
    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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ARRAYS AND STRINGS