00:01
Hello, welcome to this lesson.
00:02
In this lesson, we'll write a java app, the word, let's use a guest.
00:09
Then when the random number the system will pick, when they get that we will show them a message, if not we will let them try again.
00:26
Then if they get it right, we'll show them the number of trials that it took for them to get them to get them.
00:32
It right okay so let's go on let's create the file calling game .java okay here we have the starting side the the point of entry which is the main class which will be public static boy main just like any other application in the axe okay so this one there are few things that will need for we need to count for each of the trials after that would need a guess something available to hold the guess that they use a word input it would also need a scanner in order to help them read from the from the command line right okay then also need a while for it to keep running as far as they have not got the right answer okay so let's go on these are the few things that we'll need i'll set the count as integer so the account will be zero that i guess initially set it to zero okay then i'll need a scanner so say scanner which is equal to new scanner system .cene.
02:33
This is java's way of gettons that i imported.
02:58
There's a quick fix.
03:03
Import scanner.
03:05
All right.
03:07
So there's one variable that i will also need.
03:10
I will need the random variable which the game will pick.
03:19
So here i will say integer.
03:22
You now call it machine number or machine guess so that will be machine guess.
03:35
Now i'll make it be random.
03:42
The oddness hint.
03:45
Now set the bound to 11 so that it goes from 0 to 10.
03:50
So we can pick random numbers between 0 and 11.
03:55
11 or inclusive okay so i'll need a while now say while the machine number the machine guess is not equal to the user test so whilst that is not the case then we'll say try again okay if they guess it wrong we'll let them try again then here we'll do increment increment the count so we will add the count one to the count so that we know how many times they have actually tried that okay then we will let them get input from command line so we'll let them drag in all right so here we'll say system out again okay if you're saying try again then it means that they have actually tried the first place so you will say system out before the while you say enter your guess okay so if they enter the first time and they don't get what the machine is actually happening.
06:03
They will let them try it.
06:06
For them to do that, we would use the guess, which would be called to the scanner that we created.
06:19
So scanner.
06:21
We have nest beat to get the next integer that user inputs.
06:28
All right.
06:30
So if the input, and the user doesn't get what the machine has got, we would let them try again.
06:40
So we would be count plus plus in other to increment account by one.
06:51
Okay, then we would get the input from the command line.
06:57
So i would copy this one.
07:04
I would copy them paste here...