Welcome back and this video, we are going to finalise our app and you can, of course, do so yourself
if you want, you can try and implement the rest yourself.
So the only thing that we will need to do is we need to copy and paste our statement here for two different
operations.
So we have this statement where we have our statement where we check if we have a minus at the beginning,
and other than that, we just do a calculation.
So what I'm going to do is I'm going to add an LST block here and another elsewhere.
It's as if to be precise.
And then we finally have the last.
Else if and it can contain.
Another value here, so let's say we have a multiplication, then I want to use.
And asterisk.
Then if we have a.
Ed. I want to use a plus sign.
So let's replace all of those aspects with the plus, then finally, if we have a division, then we
should use a slash.
So now we should have all of the calculations that we see, actually one is missing and that's the minus
one.
So now we have all four of them, all of the four operations.
And now if we check it, it should work fine.
With all of the different operations, so let me check times six, we can see that works then minus
another value that works as well, divide by 10.
Well, that seems not to work, so let's check what's wrong with the division.
Do we have division here?
We didn't have the slash in there, so I forgot this one.
Let's run it again.
All right, so there we are.
So.
Minus three that works, plus 66 works multiplied with six works and division by 10.
Works as well.
All right, so now all the operations work fine.
Now let's say we get a negative value again.
All right, there we are.
And now we multiply with six and, well, there is the limitation and that has to do with the limitation
of letters that we want to display here.
In our case, it's not letters, it's mainly digits, but basically this is a string, right?
So all of them are characters in here.
There is one more thing that I don't like about this application, and that's that it shows too many
zeros after.
It calculates something, so here we have thirty four point zero, so this point zero doesn't add any
value.
So how can we get rid of it?
Well, I'm going to do it with a function, so I'm going to create a new function here, fun.
And maybe I'm going to even make it private because it's really just going to be required in here in
our main activity.
So remove zero after that is I'm going to call this one and it needs the result, which is of a type
string and it's going to return a new string.
So that's the idea.
It's just going to cut the old string a little bit.
So first, I create a new variable called value here, which is going to be our result.
So we just put the result into this new variable called value, and then we check if result contains.
Not zero.
If that's the case, then set the value as a result thud.
Substring, so we used to substring functionality, which allows us to have a START index and an index,
so we use substring before, but we didn't do it like this.
So result that.
Length minus two.
So what I do with this is I just say, OK, use the string as it is, but get rid of the last two characters.
So, for example, if I have something like.
Ninety nine point zero.
The last two characters will be this one and that one.
So the zero is the first part of the string, so which is just nine and then the nine is the second.
So the overall length is four.
So if we look at the indexes, let's do it like that.
Maybe it's easier.
Zero, one, two and three.
So this is a zero, index one, index two and index three.
And what we say, start at index zero and then stop at the length, which is four minus two.
So stop at two excluding, which means we get rid of those two and we just leave zero and one.
OK, so that's what this substring does, and now what we can do is we can just return disvalue.
Now we can remove zero after dots each time that we do this calculation here, so each time that we
finalize this calculation, we can do it.
So I'm going to do it for the whole string.
So we need to have an opening bracket and a closing bracket.
All right, so that's pretty much it.
So I'm just going to copy and paste this.
For the other operations.
And of course, I need to be careful with the operation itself so that it maintains the old value,
so here it has to be a plus.
And once again here, so why can I do that?
Well, that's because.
We have.
This being a string, so we just passed a string to remove zero after the if we look at our function,
we can see that it requires a string, which is the result.
And if you look at it, this is the result of our calculation.
Right.
And we put it into our TV input.
OK, so one last thing is theft.
And that's our division here, actually.
Subdivision division, it should be minus here.
Let me check if all of them are fine, plus.
Minus and so forth.
And as it seems, I have one of those too many, so I'm going to get rid of this line of code or this
whole block, which didn't do anything because we now have four of them.
Right.
So we have containers minus containers, slash containers, plus containers, multiplication with asterisk.
OK, now let's try it again and see if we have gotten rid of the unnecessary zero there.
All right, so ninety nine minus 66 is 33.
So now we don't have this DOT zero anymore.
So now one last thing is left to do, and that is to change where the text is positioned because it's
always positioned at the top left.
And in the application that I showed you at the very first video of this chapter, the text was here
at the bottom and it started at the bottom.
Right, which is very common for calculators.
So let's just change that real quick.
And that is this text you that we need to adjust for that.
And there are multiple things that I want to add, one of them is a little padding because the text
starts right at the corner.
So here, right at the edge, the left edge.
So I will add a little padding.
Let's say 10 pixels or 10 dusty pixels should be fine, and then I will also add a gravity.
So this is gravity, not clever, layered gravity, but gravity where I actually say to which corner
it should go.
I want this text to gravitate towards the right.
Center vertically.
Bottom.
All right, so if I do that now, if we have text in there, it will go towards the bottom, right?
So the thing is, it's a lot easier if we set the text to, let's say, zero, so you now can see where
it's actually going.
So now let's get rid of all of those just to see how this will position.
So now we're positioned at the top, right.
And here if I add bottom.
I could see its positioning it at the bottom, right, but then if I add center vertically, then the
text will be centered vertically once we have a little more text in here.
All right.
So let's run it again just to see.
What this looks like.
All right, there we are.
So let's do the calculation.
All right, cool.
As it seems, our application works fine, and of course, if we have too long of a number, then our
calculation will not work anymore because it's not adding any additional text to our text you, because
that's really the limitation of our text you, which we assigned here with max length 12.
That has to do with the data types having a limitation of how much data they can actually store or how
long numbers they can store.
All right, so I hope you enjoyed this chapter and I hope you tried some of the exercises yourself and
built a little something and yeah, see you in the next chapter where we're going to build the next
episode.
Thanks a lot for being part of this and still being around.