Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-20-2007, 06:47 PM   #1 (permalink)
 
Newb Techie

Join Date: Jan 2007

Location: Ireland

Posts: 8

Tara!

Default Quiz application - java

Hi,

what I'm doing here is creating an application that prepares test questions. It can create multiple choice or essay. I've gotten most of it to work perfectly. I'm just experiencing one problem. For the multi choice class, in the readQuestion method I can enter how many choices I want the answer to have. This is the method:

public void readQuestion()
{
System.out.println("How many choices? ");
numChoices = scan.nextInt();

String[] options = new String[numChoices];

System.out.println("Enter the question: ");
question = scan.next();

for(int index = 0; index < options.length; index++)
{
System.out.println("Enter Choice " + (index + 1) + ": ");
options[index] = scan.next();
}

}


When I call this method in my driver program, the output is as follows:


Enter the number of questions:
1
Enter question type:
m
Question type is m
How many choices?
2
Enter the question:
what package is the scanner class from?
Enter Choice 1: Enter Choice 2:


The problem is that it doesn't allow me to enter 'choice 1' or 'choice 2'.

I can't seem to see where I'm going wrong..maybe a pair of fresh eyes would help?

Thanks in advance =)
Tara! is offline  
Old 03-20-2007, 10:55 PM   #2 (permalink)
willsko87's Avatar
 
Monster Techie

Join Date: Apr 2004

Location: Melbourne, Australia

Posts: 1,219

willsko87 is on a distinguished road

Default Re: Quiz application - java

So you enter everything, but it wont let you enter anything for each choice?
__________________
http://www.aflonline.com.au



willsko87 is offline  
Old 03-20-2007, 11:06 PM   #3 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: Quiz application - java

I compiled and ran your method from the command line and it worked just fine. Are you using Eclipse or some other IDE to execute your program? Try running it manually.
jaeusm is offline  
Old 03-21-2007, 06:06 AM   #4 (permalink)
 
Newb Techie

Join Date: Jan 2007

Location: Ireland

Posts: 8

Tara!

Default Re: Quiz application - java

I'm running jGrasp, I will give it a go manually and let you know how it comes up! thanks
Tara! is offline  
Old 03-21-2007, 11:46 AM   #5 (permalink)
 
Newb Techie

Join Date: Jan 2007

Location: Ireland

Posts: 8

Tara!

Default Re: Quiz application - java

Quote:
Originally Posted by willsko87 View Post
So you enter everything, but it wont let you enter anything for each choice?
Yep, that's pretty much it. It just prints out "Enter Choice1" and "Enter Choice2" but won't let me actually input the choices.
Tara! is offline  
Old 03-21-2007, 12:22 PM   #6 (permalink)
 
Newb Techie

Join Date: Jan 2007

Location: Ireland

Posts: 8

Tara!

Default Re: Quiz application - java

Hmmm...:S I just compiled it there again and it seems to be working...whatever I was doing wrong.

Thanks for all the replies
Tara! is offline  
Old 03-22-2007, 08:42 AM   #7 (permalink)
 
Newb Techie

Join Date: Jan 2007

Location: Ireland

Posts: 8

Tara!

Default Re: Quiz application - java

Okay, just one more thing I'm having a bit of difficulty with :

System.out.println("Enter the question: ");
question = scan.next();


When I read in my question, it only reads in and prints out the first word. I've tried scan.nextLine() but then this doesn't let me enter a question in at all.

If anyone had any ideas I'd be very very grateful...

thanks
Tara! is offline  
Old 03-22-2007, 11:46 AM   #8 (permalink)
 
Newb Techie

Join Date: Jan 2007

Location: Ireland

Posts: 8

Tara!

Default Re: Quiz application - java

Never Mind!!

problem was the stuff that I didn't have in which is in bold:

public void readQuestion()
{
System.out.println("How many choices? ");
numChoices = scan.nextInt();
scan.nextLine();

String[] options = new String[numChoices];

System.out.println("Enter the question: ");
question = scan.nextLine();

for(int index = 0; index < options.length; index++)
{
System.out.println("Enter Choice " + (index + 1) + ": ");
options[index] = scan.next();
}

}
Tara! is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On