1
00:00:00,180 --> 00:00:05,760
Welcome back and this video, we are going to implement the U.S. units so that they will work.

2
00:00:05,760 --> 00:00:09,480
So here these whole elements here, they don't do anything yet.

3
00:00:09,480 --> 00:00:11,010
And that's what we need to change.

4
00:00:11,190 --> 00:00:13,130
And therefore, we need to do two things.

5
00:00:13,140 --> 00:00:17,930
So one of them is to validate if there is valid data in those three.

6
00:00:18,270 --> 00:00:23,820
So similar to what we've done here where we validated, is there any data into two if there's none and

7
00:00:23,820 --> 00:00:24,590
don't do anything?

8
00:00:24,930 --> 00:00:30,590
And then the next thing we need to do is, of course, to also execute the BMI calculation.

9
00:00:30,600 --> 00:00:38,130
So once all of that is done and we calculate, then we, of course, want to calculate the BMI and accordingly

10
00:00:38,130 --> 00:00:45,190
display the data that is associated to that BMI score should be displayed.

11
00:00:45,480 --> 00:00:47,930
So let's go ahead and do that.

12
00:00:47,970 --> 00:00:49,980
You can, of course, try to do that yourself.

13
00:00:50,130 --> 00:00:52,580
You know, everything you need to know in order to do that.

14
00:00:52,590 --> 00:00:57,540
It's basically just copy and paste with a little bit of adjustment and that's it.

15
00:00:57,570 --> 00:00:58,770
So good luck with that.

16
00:00:59,850 --> 00:01:02,550
OK, I hope you tried it if you didn't.

17
00:01:02,580 --> 00:01:03,120
No worries.

18
00:01:03,130 --> 00:01:04,500
I'm just going to show you how it's done.

19
00:01:04,769 --> 00:01:12,720
So, first of all, we go all the way back to this method here, validate metric units.

20
00:01:13,530 --> 00:01:17,790
Now, what I'm going to do is I'm going to do the same thing for the US units.

21
00:01:17,790 --> 00:01:21,090
So I'm just going to say validate US units.

22
00:01:23,450 --> 00:01:32,030
And this one is going to have the same thing, except for now it's going to be etty at a text and here

23
00:01:32,390 --> 00:01:33,260
we have two different ones.

24
00:01:33,260 --> 00:01:42,410
So you just, you know, tight fit is empty then else if it is, you know, height, inch is empty.

25
00:01:42,740 --> 00:01:44,070
And then we have another else.

26
00:01:44,090 --> 00:01:44,780
If you're.

27
00:01:46,040 --> 00:01:53,030
ET, U.S.A. and I was white is empty, so text to string.

28
00:01:54,990 --> 00:02:03,480
Is empty, if that is the case, then said is valid to false because otherwise it's going to stay true

29
00:02:03,930 --> 00:02:09,060
and you can see already we can replace it with an when.

30
00:02:09,270 --> 00:02:10,979
So now prefers when.

31
00:02:11,220 --> 00:02:16,880
You can, of course, use when here you can see, then it will make it this beautiful as you see here.

32
00:02:16,890 --> 00:02:21,990
It's going to use a lambda expression here to make it even more beautiful.

33
00:02:22,350 --> 00:02:26,040
OK, so whatever you prefer, I'm old fashioned.

34
00:02:26,040 --> 00:02:27,720
I like this if l stuff.

35
00:02:27,720 --> 00:02:33,360
But of course I have to say it looks pretty nice to have this one statement.

36
00:02:34,440 --> 00:02:36,270
OK, so that's validate US units.

37
00:02:36,270 --> 00:02:37,070
That's number one.

38
00:02:37,080 --> 00:02:38,910
I will return a boolean either.

39
00:02:40,020 --> 00:02:48,300
Everything was entered or in each of them, there is an entry or there is not, and then in the uncreate

40
00:02:48,300 --> 00:02:48,790
function.

41
00:02:49,500 --> 00:02:54,930
So all the way up here in uncreate, we have this button calculate units.

42
00:02:55,200 --> 00:03:03,750
So I know it's already pretty full, a bunch of stuff in here, but we're going to extend that even

43
00:03:03,750 --> 00:03:04,160
further.

44
00:03:04,170 --> 00:03:10,290
You could, of course, go ahead and make an extra function to keep your uncreate super tidy and clean.

45
00:03:10,560 --> 00:03:12,060
But that's open to you.

46
00:03:12,060 --> 00:03:13,440
If you want to do that, that's fine.

47
00:03:13,560 --> 00:03:17,190
But I'm just going to put everything in this unclick listener in here.

48
00:03:17,580 --> 00:03:22,380
So now we need to before we do that, check first if.

49
00:03:23,670 --> 00:03:28,830
The current visible view equals the metric.

50
00:03:30,170 --> 00:03:30,950
Units view.

51
00:03:31,960 --> 00:03:39,280
If that's the case, then do everything that you did before, because that was totally fine, but otherwise.

52
00:03:41,570 --> 00:03:49,070
You're going to be in the US system, so in this US unit view and then, of course, we want to do very

53
00:03:49,070 --> 00:03:51,500
similar things, but not exactly the same.

54
00:03:52,900 --> 00:04:02,110
So here we are also going to check if the entries are correct, so if valid date.

55
00:04:03,910 --> 00:04:05,660
Metric U.S. units.

56
00:04:05,680 --> 00:04:10,930
If that's true, then do something else right, a little toast.

57
00:04:13,120 --> 00:04:15,070
And it's going to be this toast here.

58
00:04:16,490 --> 00:04:22,870
OK, please enter a valid values and then, of course, what we want to do in here is the same as we

59
00:04:22,870 --> 00:04:23,240
did here.

60
00:04:23,260 --> 00:04:24,580
We want to get the Heidfeld.

61
00:04:24,580 --> 00:04:25,500
You want to get the weight?

62
00:04:25,510 --> 00:04:31,600
Well, you want to calculate a BMI, but things are a little different because now we have the height,

63
00:04:31,780 --> 00:04:37,110
not just being the centimeters, but actually defeat and inches.

64
00:04:37,570 --> 00:04:42,070
So in order to get all of those values, I'm just going to paste it in here.

65
00:04:42,310 --> 00:04:49,510
So it's going to be the unit, high value feet unit, high value inch unit weight value.

66
00:04:50,050 --> 00:04:53,110
And we get those and we make a string out of them.

67
00:04:54,450 --> 00:05:03,630
So out of the value, feed and value, we make a string and then out of the value that we get in the

68
00:05:03,630 --> 00:05:06,270
weight, that's what we make a float out of.

69
00:05:08,140 --> 00:05:13,420
Because even though it is a number that is entered in feet an inch, it's still going to be a string

70
00:05:13,420 --> 00:05:13,930
in the end.

71
00:05:16,360 --> 00:05:23,200
The next thing we need to do is to calculate the height value, the height value will be 12 times the

72
00:05:23,200 --> 00:05:25,270
feet plus the inch.

73
00:05:26,170 --> 00:05:28,690
So the following formula.

74
00:05:30,670 --> 00:05:38,950
So I'm just going to say height value is equal to US units, height, value and inch to float, plus

75
00:05:38,950 --> 00:05:46,950
the US units, high value and free to float at times 12 because 12 inch are one feet or one foot.

76
00:05:47,800 --> 00:05:52,930
And yeah, that's pretty much the formula here for the height value because we need that height value

77
00:05:53,170 --> 00:05:55,100
in order to calculate the BMI.

78
00:05:56,080 --> 00:05:58,580
So the calculation hereby is the following.

79
00:05:58,870 --> 00:06:04,900
So the formula for the BMI with the American system, you can find it here.

80
00:06:04,900 --> 00:06:12,610
It says the formula is seven hundred three times the weight in pounds and then the height in inch squared.

81
00:06:14,250 --> 00:06:17,160
OK, so the actual formula is the following.

82
00:06:18,420 --> 00:06:26,130
It's PMI is equal to seven hundred three times US unit weight value divided by height value multiplied

83
00:06:26,130 --> 00:06:28,880
with itself so high value squared.

84
00:06:29,760 --> 00:06:36,360
So that's the BMI and now we, of course, need to call this display BMI result function, which will

85
00:06:36,360 --> 00:06:42,390
then result in and displaying all of the BMI relevant information.

86
00:06:43,230 --> 00:06:44,590
OK, so that's already it.

87
00:06:44,700 --> 00:06:45,540
Let's try this.

88
00:06:45,690 --> 00:06:47,550
Let's run our application.

89
00:06:48,400 --> 00:06:49,570
All right, and there we are.

90
00:06:49,660 --> 00:06:51,590
So let's go ahead and calculate.

91
00:06:51,610 --> 00:06:56,420
So first of all, my weight in kilos and then the height in centimeters.

92
00:06:56,440 --> 00:06:57,340
Let's try again.

93
00:06:57,670 --> 00:06:59,420
Calculate twenty four point nineteen.

94
00:06:59,440 --> 00:07:01,170
OK, I was 16 actually.

95
00:07:01,420 --> 00:07:03,180
And now let's try the same thing here.

96
00:07:03,190 --> 00:07:10,290
So it's roughly 152 pounds and the height is five feet six roughly.

97
00:07:11,380 --> 00:07:13,540
And you can see the BMI is similar.

98
00:07:13,550 --> 00:07:15,520
So it's also twenty four point something.

99
00:07:15,960 --> 00:07:17,940
OK, so the calculation seems to work.

100
00:07:17,950 --> 00:07:24,910
Of course, feet and age are not as precise as centimeters are because one inch is roughly three centimeters.

101
00:07:25,220 --> 00:07:28,810
So that's why you will never get the same precision here.

102
00:07:29,380 --> 00:07:29,910
All right.

103
00:07:30,130 --> 00:07:31,000
So that was it.

104
00:07:31,030 --> 00:07:36,880
Now we can use the metric system and the U.S. system, both in order to calculate our BMI.

105
00:07:37,420 --> 00:07:42,190
The next pretty cool thing would be if we had a list of all the exercises that we've done, or at least

106
00:07:42,190 --> 00:07:45,330
of all the sessions that we finished and completed.

107
00:07:45,820 --> 00:07:48,480
Well, that's going to add in the next few videos.

108
00:07:48,520 --> 00:07:49,750
So see you in the next one.

