Hello this is mortars or Curdy.
And in this material we're going to create an idea of function or Mfat named as operator is tapped so
that whenever the user taps on the operator something happens you're going to see the results here.
Let's go inside this head here later class and after the increase the price of this number is to have
to function we're going to say private void and the name is going to be operator is that operator is
typed and then put up or Apprentice's.
So we are ready to create a parameter for this function because we want to pass the operator that is
actually tapped to this function whenever.
Each move it or any a function or a switch statement calls this function or method we are going to pass
the operator that is papped to that this method.
So are going to say operator and the name is going to be tapped operators tapped.
Operator And we're going to open and close this method by using these curly braces and first of all
if you are great you are going to create an if statement inside this operator is tapetum it.
So we're going to say if current operator current operator is not equal to non.
And then we're going to often enclose these statements by using these curly braces.
There isn't that we created this if statement is that.
So for example in the emulator for example there is nothing here and the user actually presses on this
plus OPERATOR We don't want anything to happen because the current operator is not.
OK so in that case we are creating an if statement we are saying that if the current operator is not
non OK and we are going to create another if statement if we can actually create an and logical operator
here so we have.
If current operator is not equal to not an current number that number is not equal to an empty string.
So this means that there is something there is a number on this screen on the text view.
And we want to actually do some operation on it.
So first we are saying that if the current operator is not equal to not and the current number is not
equal to an empty string then we can go inside each statement and say strange number.
That's right assignment operator current number current numbers semicolon.
So here we are saying that the number is that is actually at the right hand side of the operator is
going to be the kind of number so if you are assigning the column number to the string number that's
right.
So let me show you the emulator.
So let me show you this calculator.
And here for example we have number five.
Number five is the current operator and we press and this multiplication operator and we press on the
number six.
So number six is the current operator right.
And we also want this number six.
There is actually at the right hand side of this the multiplication operator to be the current number.
So you're saying the current number that is actually the number 6 it is the string number at.
Right.
OK.
So that's why we are assigning the current number to this three number.
That's right.
Valuable because this is how it is actually implemented.
A little unclear but and again let me show you let me explain again.
We have numbers too.
This is the number at left and it is also the kind of number.
And we press on.
For example the plus operator.
Now I want to press on the number three.
Number three is the current number right.
So it is also going to be the number at the right hand side of the operator of the plus operator.
So if you're saying that the current number to be to be assigned to this Thring number.
Right.
OK.
So that's how it is implemented.
So now that the current number is assigned to this thing number asteroid we are going to say Carne's
number assignment operator two quotes.
So now we're going to empty this current number valuable because the value of the current number is
already assigned to the string number.
That's right.
Valuable.
We don't need it anymore.
We are going to we we're going to actually empty this valuable this current number variable so that
we can actually do something else with it later.
Let's go back to our function this method.
Operator restaffed Meffert.
Now to create a switch statement here in order to switch between the values of the current operator.
So we're going to say switch.
And here I want to just put current.
Operator here kind of later.
Open and close this.
So is this meant by using these curly braces.
So we already provided our limited values for the operator for the current operator because the current
operator is of type operator that we created ourselves inside our class so we can say case and then
we have the value plus case.
If the current operator if the value of the current operator is Plus break.
So let me show you the emulator we have.
Let me.
We have this subtract operator case.
If the value of the current operator is subtract
call it break and if the value of the current operator is for example multiplication operators so case
multiply break.
And we have this why the divide operator chase the right break.
And finally we have this equal operator so here we see a case
case
equal colon break.
OK.
So now for now I don't want you to just think about this equal operator and how these functions.
This actually did it in this case equal.
And for now I'm going to talk more about this later.
For now let's just focus on the main operators the plus operator subtract multiply and divide operators.
So now what happens when they use their taps.
On the plus operator Let's see the created of a variable of type integer named as calculations resolved.
It is of typing teacher assignment operator.
So if we're going to say in teacher the class teacher that parse in and we need to pass a string value
to this method parse it in order to convert it to an integer value.
So if we have three number that's left plus.
So let me create an inline integer integer that parse the pars and string number at.
Right.
You're going to add the value of the string number at lift to the value that is actually at the right
hand side of the operator string number at right and the result is going to be assigned to these calculations
result variable h.
We have this break statement now.
Let's see what happens.
And to use a pass on the subtract operator here we are going to see calculations result.
Assignment operator in teacher and teacher but parts in it.
String number lift's string Ratliffe minus integer the parse and
integer that parse gained string number.
That's right.
So three numbered right semicolon.
So break.
Now let's see what happens when the user taps on the multiplication operator.
So again tabulation is resolved.
Assignment operator teacher.
That part's amed three numbers.
Lift multiply.
Buy in teacher that parts end string number.
That's right.
Semicolon.
And finally we have this device OPERATOR So the calculation is resolved.
Assignment operator integer that parse ain't string number.
Lift divided by integer the parts in string number.
That's right.
String number three semicolon.
So now after the ending curly brace of this sweet statement here I'm going to say that string number
at lift strange number adds lift.
Assignment operator streambed dot value of calculations result calculations result semicolon.
So if you were to convert the calculations result to a string value and we're going to assign it to
this three number at left roudy able.
Why.
Let me show you why.
Let me show you the emulator.
So now here it is our emulator right.
And here for example we have number five.
Number five multiplied by two.
OK.
And now I am going to for example say plus as you can see the multiply the number five multiplied by
two the result is 10 right.
So we have number 10 here and here you can see it at.
Take a look at these takes you here at the top it is 10 plus.
When he said Number Five multiplied by two.
I didn't present this equal in here.
I pressed on this plus.
Operator.
So the number five multiplied by two operation is executed and the result which is going to be number
10 is assigned to this three number that's left Raddy bet.
Now the result which is is number 10 is at the left hand side of this plus.
Operator OK now number 10 is string number at left and that's why you can see here we assigned these
calculations result to this string number at left variable.
OK.
Now it says 10 plus because we pressed on the plus operator.
So now.
So it is actually a little bit confusing.
That's OK.
But if you don't or do not understand it please make sure to watch this part of the video over and over
again so that it completely makes sense.
So after all this line of code here I can say 60 results.
That said text string number at left street number that's left because now this three number at left
is the result and that's why you can see here the number 10 is going to be district number at left is
the result here we are going to display this value to the user.
OK.
So so now what happens if this if statements that we created here face this if current approach is not
equal to know what happens if the current operator is not X is actually not ok.
If the current operator is null then something else should happen.
This if statement is not going to be executed if the current operator is actually not.
So in that case you're going to create an if statement here.
It is really based on your statement you can see that here.
So when I click on this the curly braces can assure me that viridis anything really bright curly brace
blanks to.
So after this ending really brace I'm going to say it's ill's means that if this above part of the quote
is if this part of the code if counter-protests is actually null then we're going to execute this.
Else statement we're going to say that three number at liff is actually the current number.
Semicon So if the user presses on a number the current number is going to be assigned to the string
number at left valuable.
OK.
If the current operator is actually null.
If there is nothing on the screen let me show you the emulator.
Let me click on this clear.
So now the current operator is knol.
OK.
And then I press on this number for example number five.
Number five is the current number the kind of number is now going to be this three but live is going
to be assigned to this number at left value.
OK.
And you're going to say current number assignment operator two code so that it is now completely emptied.
And then we can actually use it later.
And here after this statement here we can see that this is the curly brace of our Meffert operator is
that we're going to say that the current operator is going to be the tapped operator.
So we call.
So now at the end of the Meffert you're going to say that the tapped operator is going to be assigned
to the current operator whether it is if statement here or this statement is executed.
It doesn't really matter when the function operator is tapped is called The tapped operator is going
to be the current operator it is going to be assigned to the current operator.
So for example let me show you the emulator we have number four multiplied by three.
OK.
And I'm going to say that plus.
So now the plus operator is going to be the current operator von multiplied.
So now we can see that the multiplied multiplication operator is now going to be the current operator.
So that's why we put this line of code here in order to specify what is going to be the current operator.
Every time the user presses on the specific operator on our calculator application.
So now our function our operator is that function is complete.
Now we need to call this function from somewhere else.
And you know we want to actually call it we want to call it from that is that these case statements
and we have some operators here.
So for example case or ID that BT and plus right we are going to say operator is tapped.
So what is the top now we need to pass the operator.
We already know that BT and plus is tapped.
So if are going to say OPERATOR You're going to refer to our in on call that we created this type darte
plus Okay.
And we also have to subtract operator.
So case our that that BT and said right you're going to say operator is tapped.
So I think there is a typo in the name of our income.
So let me scroll to the top.
You can see that yes there is a typo here.
Operator So here we need to change the type our instance variable the type of this current operator
to OPERATOR We need to actually delete this type here and scroll down here.
We also need to choose the right name for this operator here.
And for this SBT and subtract we're going to say operator that Cyp tracked this school down here so
here for this for the name of the parameter of this operator is tap function Vinita right.
We need to write the right name of right.
So now the problem is solved with scrotal it up here you can see that for this PTM Plus we called operators
tappet operator plus and for the speedy and subtract operator that set.
Right.
And we also have these PTEN multiply.
So we're going to see operator is tapped
operator is tapped.
And we're going to say operator that Monte play.
And finally we have this PTEN divide operators tapped
operator dot divide so that sits.
So now it's time to run our application.
Let me show you the emulator.
So here for example we have number five multiplied by number of free and let me click on this number.
This plus operator.
So now you can see the result here number five multiplied by three is 15.
And we clicked on this A-plus operator plus free minus.
So 18 15 plus free is 18 and we clicked on this minus operator 1 divided by.
So here we can see this is number 17 here.
So it works fine.
It works perfect.
So now we're going to do something so that the text we hear at the top is going to show some calculations
that actually occur here so that we can see what number is multiplied with another number and how the
calculations worked.
So we're going to do that in the next story.
Thank you very much for watching.
And if you have any questions please sponsor a discussion in of course and I'll do my best to answer
all of your questions and I'll see you in the next tutorial.