Hello In this lecture.
We are going to wrap up the code for the calculator and hookup what's left to make the calculator work.
We need a way to tell when an operator has being clicked at the moment there is no way of telling if
I click this plus button or the multiplication there is no way of telling it has been clicked.
So what we're going to do we're going to create a variable that will store that value.
I've already created a variable I'll just gonna let you know where it is.
So here I've created a variable called is operator clicked.
And by default I've set it to false which means it hasn't been clicked.
It's a bull data type.
That means where the bull is either true or false.
So when the button has not been clicked it will be false.
I also need to be able to capture when the button or the operator has been clicked.
So when any of the operator buttons has been clicked I want to capture that.
I've already defined the value here as a bull.
So all I need to do is just reuse that variable and change the value to force.
And the way we're going to specify I'm going to specify that inside the Click event
so inside the Operator We've got an event for the operator.
So here inside the operator click event I have specified this variable here.
So when the button I know the operator has been clicked it will be specified here that that value then
changes to true which means it has been clicked.
We also need to do the same for each of these numbers.
So we need to know when they're being clicked and when they have not been clicked.
So we'll do a similar operation to what we did with the operator.
So go back into code.
I've already specified this.
So we'll specify this value inside the button click event with the operator what we specified it inside
the operator click event.
So we'll look for the button click event.
So this is the button click event.
And this is where I specified it.
So when the button is addressed to when it hasn't been clicked the default value will be false.
I have the if statement here that we defined Alia.
I have actually added another operator.
This here is called the all.
So I've added another condition to this if statement saying that if the result text box is pretty close
to zero or this operator click value which is this variable here here too is looking for these two conditions.
Either this or that it will clear the box because previously if you clicked on this it doesn't clear
it.
So that's what this extra this value has called a pipe.
It means all.
So as I'll check for this condition and also check for this condition.
And then it will clear the box.
It will use this clear box this clear method to clear what's in there.
So again we've already specified when the operator all is clicked if he's not clicked it will be false
when he's clicked a becomes true.
So here on court and if statements have implemented saying if the button the text is strictly equal
to the period which is dot it will execute this code.
If the result if it is the result if the text this exclamation means does not the result box does not
contain this and it silences exclamation why miss it.
It means does not a thing.
If this variable does not contain this this will happen.
The result does result box or text is variable will display the text on the button.
If that condition is not met if the first condition is not met it will do this.
It will show this piece of code.
It will show this and the text which is basically the same part of this.
So within each statement if the first condition is true to execute what's in this to execute this if
it is false it will execute what's in the else statement here inside the operator or method.
We have an if statement with checks if the result value is not equal to zero it will execute this code.
The equal to button dot click it will perform that if the operator or click button it will execute that.
So if the result is not zero to execute this piece of code that's basically what that is saying.
All right.
If this condition is false.
It will execute this piece of code.
That's basically what an if statement does.
If one condition is true it executes was in that part of the code.
If it's not it will execute what's in the else statement.
So let's scroll down and see what else we've done.
And here we've got the operator collect a the button texts and we got the result of this result.
Value here equals so that we've already gone through that piece of code.
So this is the switch statement for the equals two button.
So we are basically done now and so all the code just check in true to make sure we've not left anything
out.
OK so we are good to fire run the application now the calculator should work.
So let me just go through the code.
Make sure nothing has been left out.
Okay.
It looks good so far I can't see any errors.
So that's a good sign.
One thing with widgets to do if there's any arrows in your code e to complain and tell you about it.
So all right so I think we good to go.
All right.
That's fine.
So I'm just gonna run the code and click on Start and just perform some basic calculation.
So do seven times seven plus forty nine.
Clear that and do five minus two that's three clear that I do six.
Divide by
two.
Give me three.
And I do two point five.
Lost two point five.
That's five.
So the calculator is working all the operator sides are working the number bottoms up work in the clear
button is also working.
So that is it.
We have successfully created a basic working calculator.
Feel free to play around if any aspects of this project you do not understand.
Please feel free to contact me.
I'll be more than happy to explain further.
Thanks very much.
Take care and bye for now.