Okay, so now that we're displaying the question, how about we also ask for the user input and then
check the user input input for correctness.
All right.
So therefore let's go ahead and modify our application a little further.
So what we will need to start with is going to be another method.
So I'm going to create another method down here which will be a private int get user choice.
So the idea here is that this method will get the user choice and it will return it as an int directly.
Because usually what we get from the console is a string, right.
So we're converting that accordingly obviously as well.
So what I'm going to do is I'm going to display console dot write to the user.
And I'm going to say your answer.
And then in brackets I'm going to say number and empty space like so.
So this is what I want to display.
And then I want to get the user input.
So I'm going to get the user input which will be console dot write line.
And then I'm going to have a variable which will store the choice of the user.
And then while I get input from the user and it's not null slash, as long as it's not a proper number
that fits into the amount of choices that we have for so long, I'm going to make sure that we keep
going.
So that's what this while loop does.
It gets the user input.
And what I'm going to say is as long as whatever the user entered.
So this one will be a little tricky.
So let me just type that out for you quickly try parse.
And I'm going to say whatever the user input is and out choice okay.
So what I'm saying here is as long as whatever the user entered is a number.
So as long as this worked, we're going to keep going with the code after.
But if it isn't a number then we're going to try again.
So if it isn't a number we're going to let the user know, hey, please enter a proper number.
So we're going to say something like invalid choice.
Please enter a number between 1 and 4 okay.
So I use it this way.
So I'm hard coding so to speak.
How many answers I want to have.
Like how many possible answers there will be.
So I'm saying the user should enter something between 1 and 4.
So I also need to check that here.
So I'm going to say as well as just the input being a number, I'm also going to check is the choice
less than one or is the choice less than or greater than four?
As long as the user entered something less than one or greater than four or not a number, the user
will be greeted with an invalid choice message.
And then I will obviously need to read the console input once again.
So we are going to overwrite the input and we're going to check the input again, because otherwise
it will always just iterate through the old input that we had.
So we're asking for new input from the user.
And once we did get a proper response we're going to return the choice.
Now however we need to make one thing clear.
Like this would work, but we would get an like, we would basically build an application that would
make the user go crazy.
Why is that?
Because look at what we had here.
So here inside of our display question, we had this statement where we said write I plus one.
What this did is it didn't display the answer possibility at the right index but always one up.
So what we need to do when getting the user choice we will need to deduct one.
So we need to adjust to zero indexing or indexed array.
Because here we are incrementing the user choice by one.
We need to decrement the user choice by one.
Once we actually get the user choice, so that we can then do the calculation accordingly.
Okay.
So that's what the whole point here is.
That's the idea here.
So for now in order to test that let's use this get user choice method directly inside of our quiz and
compare it to the question answer index.
So what we can do here is we can say if get user choice equal equal question dot user or correct answer
index.
If that's the case then we know that the user was correct.
So we're going to just write currently correct.
And otherwise we're going to write incorrect okay.
So let's just run this real quick because this is not the final result.
How we.
But let's just try it.
So your answer number.
So let's say we know that the answer is Berlin.
So let's press two and enter.
And you see we get correct.
Now let's run it again and see if it says incorrect.
Once we press Enter Paris and you see it's incorrect.
Now this is not going to be how our final application is going to look like, but I'm just adding these
two lines here into our display question method so that we can quickly check if our get user choice
method is working correctly or not.
All right.
So that's it for this video.
In the next video we can take care of actually designing how to start the quiz correctly.
Okay.
So that this is going to not just be one question, but that it can display multiple questions after
each answer that we have given.
It can start with the next question.
So see you in the next video.