• Post Reply Bookmark Topic Watch Topic
  • New Topic

which variable is best?  RSS feed

 
John Downham
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, this is my first post so here goes.

im trying to write a program that asks a user to answer a question with a pre determined set of answers. the user is then asked a further 3 questions. with the answers combined from all four questions I want
the program to generate a certain file that is a result of the answers received.

for each set of four answers there will be a different file opened.

im not too fussed about the file part. im pretty certain ill be able to manage that when i get to it. however im stumped at which variable to use for the answers. shall i use String or boolean?

ive tried both using a bunch of if else statements and can't seem to crack it. my main problem at the minute is using the pre determined set of answers as variables and managing the program to continue onto the next question, as well as asking the user to try again if the input is incorrect. so i need to know what the best way of going about it and which variable to use.

a friendly push in the right direction would be greatly appreciated.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Welcome to CodeRanch! It sounds like you need an array of something for the answers.

It's hard to tell whether String or boolean (or something else) is best from your description. Can you give an example of an answer? (In English, not Java)
 
John Downham
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, yeah sure,

so question one enter a type: a / b / c or d
if user inputs a, go to next question if not return to question 1.
when user inputs a,b,c or d question 2 is presented and the process repeated.
then when all four questions are answered,
so Q1 = a
Q2 = b
Q3 = c
Q4 = d

file xyz.text is generated and shown to the user.

hope this makes sense?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are the questions true/false, or will you be getting some other kind of input values?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that makes sense. You can't use booleans because the answer is a letter. Which means the choices are "char" or "String."

And then you have an array or ArrayList of that type so you can store the sequence of answers.
 
John Downham
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry that was a bad example, the answer will be Strings not char. so the user will select a worded answer.

so do i use a bunch of if else statements and an array lst or just an array list, havent really got into arrays yet?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you really need to do is StopCoding (<----click that). Don't worry about "java" stuff, just think about the kinds of things you need to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!