Welcome back in this video, we're going to finalize our application, and therefore I'm just going
to get started by.
Well, copy and paste this code because this is basically where the calculation happens, right?
So we check, is it the minus?
If it's a minus, then we're going to split it at the minus and then we do the calculation here at the
bottom.
So now we just need to replace this or do the same thing with a bunch of ifs for the other operations.
So here let me add else, if then else, and paste it in.
So now I have all four operations here.
So let's start with the minus.
We have that now let's go over to the plus.
So let's add the plus here and add it in the calculation itself as well.
Now let's add the division slash and do the same thing here, and then we just need another one, which
will be the multiplication.
So here we just need to add the multiplication like so and of course, we mustn't forget it here at
the bottom and the actual multiplication as well.
OK, so now let's try this once again.
So 99 Times 99 gives nine thousand eight hundred and one.
Now 66, it was actually let's use sixty six times three.
Well, B 198.
That's good.
Now 99, divided by 66 will be 1.5.
And 66 minus.
Thirty three will be 33.
Plus fifty five is eighty eight, minus sixty eight is twenty and so forth.
So you see that works fine.
Now at this point, you could say I am not super happy with their constantly being a dot zero at the
end.
So if we are working with just whole numbers, I want to get rid of this dot zero and you already know
more or less how this can be done.
You could use a substring, you could use a split here, so both would be fine.
I'm just going to show you my solution to it, and that is going to be a new method that will take care
of just that.
So here I'm going to create this new private function called remove zero after.
Dot.
All right.
And it needs to get the result type string and it will return a string itself.
So the result will be the result of our calculation, and then it will take that and it will return
a string without the dot zero.
So first of all, let's get the value, which will be our result at the beginning.
So when we start, the value will be the result and we only change it if we actually need to change
it, which means if the result contains.
The string of dots zero, which means ninety nine point zero, 33.0 and so forth.
If that's the case, then let me set the value to be the result of the sub string of zero.
Well, start index zero all the way up to result that length minus two.
So what is going on here?
Well, let's just use this here and play the codling.
So we had this Helloworld example earlier.
And here I'm going to use this result.
Length minus two.
OK, so what will this return?
Let's run it.
And of course, my string needs to be used here instead of result.
So here is going to be a returned empty space war.
So what it does is it starts at position zero, which is just empty space, and it goes all the way
to the length of the entire string, which is 11.
So we have 11 entries minus two, so it goes all the way to index nine, which means it goes all the
way to this hour and doesn't use this L.D.
Maybe it's going to be easier if we actually are going to use these as strings here, like the numbers
of strings.
You can see it starts at Index five, which is this number here, and it goes all the way up to everything
except for the last two entries.
So this eight nine is going to be excluded.
It's the same as if it were saying 90.0, and we start at Substring Index zero and go all the way to
length minus two, which means we just get 90.
So we are eliminating the dot zero here with this substring.
And now, of course, we need to return value, so here, return value, like so.
And by the way, what you see here, I'm using this f clause without curly brackets because I just have
one line of code that will be executed for this if statement, if it's true.
So now we return value, which means now we can go ahead and remove zero after dot for each of the calculation
results, so to speak.
OK, so here what we said to the text.
We can now just use this remove after dot and pass the calculation in there.
So the result?
So the string of the result in there as the parameter.
OK, so remove after dot with this thing as a string.
OK, and now we can do the same thing with the other calculations.
So here we do the same thing.
We just need to make sure that we replace it with the right operation.
And here it has to be the plus and then here accordingly, the minus.
OK.
And.
Was it the minus for this one?
Yes, it was.
OK, so now let me check because I believe I have this minus twice.
OK, that's good to know.
So let's use it instead here.
Which creates a situation where this elusive would have been unnecessary.
OK, let's run it again and 99 minus 66 and see, OK, we have only 33 now, not 30 3.0.
All right.
So that's pretty much it for this calculator.
So you see, we have a proper calculator, we can clear the entry.
Now, as you could, of course, have zero as the default value that is going to be displayed here if
you wanted to.
But overall, this is a calculator that works, at least for the basic operations.
I hope you enjoyed this chapter in the next one.
We're going to build an actually cool app because this was just to show you the fundamentals and really
teach you how to use all of the good string stuff and the next chapter.
We're actually going to build a cool quiz app, so see you there.