Welcome back and this video, we are going to implement the U.S. units so that they will work.
So here these whole elements here, they don't do anything yet.
And that's what we need to change.
And therefore, we need to do two things.
So one of them is to validate if there is valid data in those three.
So similar to what we've done here where we validated, is there any data into two if there's none and
don't do anything?
And then the next thing we need to do is, of course, to also execute the BMI calculation.
So once all of that is done and we calculate, then we, of course, want to calculate the BMI and accordingly
display the data that is associated to that BMI score should be displayed.
So let's go ahead and do that.
You can, of course, try to do that yourself.
You know, everything you need to know in order to do that.
It's basically just copy and paste with a little bit of adjustment and that's it.
So good luck with that.
OK, I hope you tried it if you didn't.
No worries.
I'm just going to show you how it's done.
So, first of all, we go all the way back to this method here, validate metric units.
Now, what I'm going to do is I'm going to do the same thing for the US units.
So I'm just going to say validate US units.
And this one is going to have the same thing, except for now it's going to be etty at a text and here
we have two different ones.
So you just, you know, tight fit is empty then else if it is, you know, height, inch is empty.
And then we have another else.
If you're.
ET, U.S.A. and I was white is empty, so text to string.
Is empty, if that is the case, then said is valid to false because otherwise it's going to stay true
and you can see already we can replace it with an when.
So now prefers when.
You can, of course, use when here you can see, then it will make it this beautiful as you see here.
It's going to use a lambda expression here to make it even more beautiful.
OK, so whatever you prefer, I'm old fashioned.
I like this if l stuff.
But of course I have to say it looks pretty nice to have this one statement.
OK, so that's validate US units.
That's number one.
I will return a boolean either.
Everything was entered or in each of them, there is an entry or there is not, and then in the uncreate
function.
So all the way up here in uncreate, we have this button calculate units.
So I know it's already pretty full, a bunch of stuff in here, but we're going to extend that even
further.
You could, of course, go ahead and make an extra function to keep your uncreate super tidy and clean.
But that's open to you.
If you want to do that, that's fine.
But I'm just going to put everything in this unclick listener in here.
So now we need to before we do that, check first if.
The current visible view equals the metric.
Units view.
If that's the case, then do everything that you did before, because that was totally fine, but otherwise.
You're going to be in the US system, so in this US unit view and then, of course, we want to do very
similar things, but not exactly the same.
So here we are also going to check if the entries are correct, so if valid date.
Metric U.S. units.
If that's true, then do something else right, a little toast.
And it's going to be this toast here.
OK, please enter a valid values and then, of course, what we want to do in here is the same as we
did here.
We want to get the Heidfeld.
You want to get the weight?
Well, you want to calculate a BMI, but things are a little different because now we have the height,
not just being the centimeters, but actually defeat and inches.
So in order to get all of those values, I'm just going to paste it in here.
So it's going to be the unit, high value feet unit, high value inch unit weight value.
And we get those and we make a string out of them.
So out of the value, feed and value, we make a string and then out of the value that we get in the
weight, that's what we make a float out of.
Because even though it is a number that is entered in feet an inch, it's still going to be a string
in the end.
The next thing we need to do is to calculate the height value, the height value will be 12 times the
feet plus the inch.
So the following formula.
So I'm just going to say height value is equal to US units, height, value and inch to float, plus
the US units, high value and free to float at times 12 because 12 inch are one feet or one foot.
And yeah, that's pretty much the formula here for the height value because we need that height value
in order to calculate the BMI.
So the calculation hereby is the following.
So the formula for the BMI with the American system, you can find it here.
It says the formula is seven hundred three times the weight in pounds and then the height in inch squared.
OK, so the actual formula is the following.
It's PMI is equal to seven hundred three times US unit weight value divided by height value multiplied
with itself so high value squared.
So that's the BMI and now we, of course, need to call this display BMI result function, which will
then result in and displaying all of the BMI relevant information.
OK, so that's already it.
Let's try this.
Let's run our application.
All right, and there we are.
So let's go ahead and calculate.
So first of all, my weight in kilos and then the height in centimeters.
Let's try again.
Calculate twenty four point nineteen.
OK, I was 16 actually.
And now let's try the same thing here.
So it's roughly 152 pounds and the height is five feet six roughly.
And you can see the BMI is similar.
So it's also twenty four point something.
OK, so the calculation seems to work.
Of course, feet and age are not as precise as centimeters are because one inch is roughly three centimeters.
So that's why you will never get the same precision here.
All right.
So that was it.
Now we can use the metric system and the U.S. system, both in order to calculate our BMI.
The next pretty cool thing would be if we had a list of all the exercises that we've done, or at least
of all the sessions that we finished and completed.
Well, that's going to add in the next few videos.
So see you in the next one.