Tim: So armed with the knowledge
that you've learned in the last video
about naming conventions,
your challenge here is as follows.
Wanna do three things.
Firstly, create a variable of type double
to track the number of miles driven in a month
by a company's sales representative.
Number two, create a variable of type int
to track the number of customers
who visited a store in a day,
and thirdly, create a variable to record
the last key pressed in a game.
So use the proper naming conventions
discussed in the previous video for your variable names.
Pause now and do that and come back
when you're ready to see my solution.
All right, so welcome back.
So hopefully, you managed to do that.
So let's go through my solution.
So what I'm going to do is delete
the existing example we had there.
We no longer need that,
and I'm gonna start by typing the answer to the first one,
which was to track the number of miles driven in a month
by a company's sales rep.
Now there's a few options, obviously, with this.
We could type double milesDriven if we want.
Our milesDriven equals 1000d,
and obviously, the value is irrelevant.
Now you might've done something like instead
salesRepMilesDriven
or alternatively, you might've done repMilesDriven,
and obviously there's a number of other ways
you could've done it as well.
All right, so that's the first one.
The second one,
we're needed to create a variable of type int
to track the number of customers
who visit a store in a particular day,
so we could keep it simple
and just do int customers equals 50,
and again, the value's irrelevant,
or you might've done something like
calling dailyCustomers perhaps
or even maybe storeDailyCustomers.
All of those would be okay or something similar to that,
and third one, if you recall,
we needed to create a variable,
which I didn't mention the type,
and that was to record the last key pressed in a game.
So you might do something like,
if it's a key press, it's a single digit,
maybe you've defined a char,
but a String would've been acceptable as well.
So lastKey might be one equals,
and we'll just put an arbitrary value there d,
or maybe you did something, instead of lastKey,
maybe lastKeyPressed
or maybe playerLastKeyPressed,
and again, if you used a String
instead of a char that I've used,
that would've been perfectly acceptable as well.
So in general, try and be a little bit concise
with your variable names,
but don't focus only on that.
So if you need to use a few extra letters
to name something to be clearer, then do it.
So there is obviously a limit
where it becomes impractical
when you're defeating the purpose of making it easy to read.
So if I said something like
thePlayersLastKeyPressedInThisGame,
I think you'd probably agree that's starting to get
a little bit too long,
and it's defeating the purpose
of being able to sort of see a variable at a glance
and know what it's for.
The point I'm making here is unlikely
that the extra words I've added in this particular example
don't really make it any clearer
as to the purpose of the variable.
lastKeyPressed or lastKey or playerLastKeyPressed
are probably sufficient.
All right, I'll just delete this last bit of code there.
Okay, so I'm gonna end the video here,
and in the next one, we're going to do a quick recap
of operator precedence
but then get into another topic
called operator associativity,
so I'll see you in the next video.