1
00:00:01,010 --> 00:00:08,420
Welcome back in this video, we're going to implement calculating the BMI using US units, which means

2
00:00:08,420 --> 00:00:11,010
we will need to use a different formula.

3
00:00:11,030 --> 00:00:16,219
You see a dividing weight in pounds by height in inches squared.

4
00:00:16,370 --> 00:00:19,910
Multiplying by conversion factor of 703.

5
00:00:20,660 --> 00:00:24,200
So yeah, it's quite complex.

6
00:00:24,740 --> 00:00:28,370
The metric system makes it a lot easier, but let's just implement that.

7
00:00:28,370 --> 00:00:32,930
You can try to do this yourself, of course, but basically speaking, you need to get the data first.

8
00:00:32,930 --> 00:00:36,020
You need to validate whether those added text are empty or not.

9
00:00:36,020 --> 00:00:39,170
If they're not empty, then do the calculation at then displays.

10
00:00:40,100 --> 00:00:46,390
OK, so let's go over to our code, and something that would be very easy will be to validate.

11
00:00:46,400 --> 00:00:51,380
Basically, we need to do the same thing as we did here, but with the other added texts or with three

12
00:00:51,380 --> 00:00:55,100
added texts now instead of just two added texts.

13
00:00:55,640 --> 00:00:59,630
OK, so I'm just going to paste it in here and go over it really quickly.

14
00:00:59,630 --> 00:01:01,760
So I'm validating the U.S. units now.

15
00:01:01,760 --> 00:01:05,360
This is a new method I'm going to set is valid to true by default.

16
00:01:05,660 --> 00:01:08,540
Then I'm using this one statement.

17
00:01:08,750 --> 00:01:15,170
When this added text metric unit weight, which is this one here at the top is empty or this one is

18
00:01:15,170 --> 00:01:16,760
empty or this one is empty.

19
00:01:17,060 --> 00:01:23,270
In either case, I'm going to set is valid to false and I'm going to return is valid.

20
00:01:23,330 --> 00:01:25,640
So it's going to be true by default.

21
00:01:25,640 --> 00:01:29,840
But then, depending on whether one of them is empty, we're going to overwrite it.

22
00:01:30,920 --> 00:01:35,120
OK, so now we need to do the calculations.

23
00:01:36,230 --> 00:01:43,700
So let's go ahead and create this new function that I'm going to call calculate units.

24
00:01:44,900 --> 00:01:49,580
And first, I need to check which view is current divisible.

25
00:01:49,580 --> 00:01:56,990
So if it's the matrix view, I just want to do the code that we did once we clicked on the button,

26
00:01:56,990 --> 00:01:57,420
I believe.

27
00:01:57,440 --> 00:01:58,100
Let me check.

28
00:01:58,520 --> 00:02:02,480
So we have this, yes on click if!

29
00:02:02,480 --> 00:02:04,990
Validate metric units here.

30
00:02:05,000 --> 00:02:06,200
That's what we're doing.

31
00:02:06,350 --> 00:02:12,620
OK, so let me take all of that and put it into this method.

32
00:02:13,670 --> 00:02:14,900
Well, we calculate.

33
00:02:16,970 --> 00:02:21,440
The units I would calculate BMI, basically.

34
00:02:22,820 --> 00:02:30,650
OK, so we validate if the metric units is true or not, and only then are we setting up all of those

35
00:02:31,100 --> 00:02:32,000
values, right?

36
00:02:32,000 --> 00:02:35,190
And then we calculate the BMI and we display the BMI result.

37
00:02:35,210 --> 00:02:38,960
Otherwise, we're displaying that there is nothing to see.

38
00:02:39,380 --> 00:02:40,880
OK, so that's one thing.

39
00:02:41,180 --> 00:02:46,820
But then if we are in the other view, which means we are not in the metrics units view, but in the

40
00:02:46,820 --> 00:02:57,170
US doing its view, then we want to validate once again if the Validate Yes unit, so you validate us

41
00:02:57,170 --> 00:03:05,600
units is true and only then do we want to get the height, value and feet.

42
00:03:06,770 --> 00:03:11,420
So here you as unit height value ft, which will be a string.

43
00:03:11,420 --> 00:03:13,310
We get that from our edit text.

44
00:03:13,340 --> 00:03:18,870
US metric units hide feet and we convert its tax property value into a string.

45
00:03:19,250 --> 00:03:22,850
Then we do the same thing with the hide value.

46
00:03:23,300 --> 00:03:26,680
So I'm going to do that with both height values.

47
00:03:26,690 --> 00:03:32,330
So we're doing it with both values here, with the feet and inch, and then we're also getting the weight.

48
00:03:32,630 --> 00:03:35,060
So he had a weight value would be a float.

49
00:03:35,840 --> 00:03:43,520
We're getting it as just a metric unit, weight text to string and then we're converting it into a float.

50
00:03:43,700 --> 00:03:46,850
So here, let me put it like this.

51
00:03:48,860 --> 00:03:52,190
And put this into the next line, I think that we should be good to go.

52
00:03:52,430 --> 00:03:53,120
Okay, so.

53
00:03:56,450 --> 00:03:56,990
Like this?

54
00:03:57,590 --> 00:03:59,250
OK, now we have the values.

55
00:03:59,270 --> 00:04:06,650
The problem is we now need to calculate the height value and the height value is in inches and also

56
00:04:06,650 --> 00:04:09,290
in feet, but one feet.

57
00:04:10,260 --> 00:04:18,720
Or one foot is a 12th of an inch, so we can calculate it using the following following formula so we

58
00:04:18,720 --> 00:04:23,280
say the height value is going to be the US unit's value, an inch, which is this string.

59
00:04:23,280 --> 00:04:30,300
We convert it into a float, plus the generate height value in feet, which is in a string, and we

60
00:04:30,300 --> 00:04:33,630
convert it into a float as well, and we multiplied with 12.

61
00:04:34,570 --> 00:04:40,770
OK, so this will give us the height value because in order to calculate the BMI, we need to, as you

62
00:04:40,770 --> 00:04:47,070
have seen, multiply with 703 and what do we need to multiply while the weight divided by the height

63
00:04:47,430 --> 00:04:47,880
squared?

64
00:04:48,930 --> 00:04:52,110
Okay, so the height value times the Heidfeld.

65
00:04:52,110 --> 00:04:59,190
You will give us the high value squared and we take the weight value and divide it by this.

66
00:04:59,190 --> 00:05:03,510
And then we take the 703 value to get the BMI.

67
00:05:04,170 --> 00:05:05,720
So whoever came up with this?

68
00:05:05,730 --> 00:05:06,690
Congratulations.

69
00:05:07,860 --> 00:05:13,200
So then we can now take this BMI and display the BMI results with that BMI.

70
00:05:15,070 --> 00:05:24,640
And if we do not have the valid US results, we can display this house block that we have here as well,

71
00:05:24,640 --> 00:05:28,600
which will just give us a toast text.

72
00:05:29,800 --> 00:05:33,650
Like so, which says, please enter a valid values.

73
00:05:34,880 --> 00:05:43,250
OK, so now we just need to call this method calculate units once we click on the calculate button.

74
00:05:43,250 --> 00:05:49,430
So all the way in our own create, we have this button calculate units set on Click Listener.

75
00:05:49,440 --> 00:05:51,710
Here, we need to calculate the units.

76
00:05:54,080 --> 00:05:57,050
So I believe there should be it, let's just try this.

77
00:06:01,890 --> 00:06:04,380
So let's go over to the BMI calculator.

78
00:06:04,620 --> 00:06:05,280
Wait.

79
00:06:07,180 --> 00:06:13,110
Which would be one hundred and fifty six, in my case, fee heights.

80
00:06:13,150 --> 00:06:14,290
I'm not very tall.

81
00:06:14,320 --> 00:06:14,980
What is it?

82
00:06:16,990 --> 00:06:24,130
It's five point five for like four, five and six, five five something like this.

83
00:06:25,060 --> 00:06:25,780
Calculate them.

84
00:06:25,780 --> 00:06:30,610
We see we have a similar BMI than I had in the metric units.

85
00:06:30,610 --> 00:06:38,800
So if I enter a 71 with one 69, then we see, well, it's and it's not exactly the same more or less,

86
00:06:38,800 --> 00:06:39,160
right?

87
00:06:39,640 --> 00:06:43,750
So that's the thing with feet, an inch and everything.

88
00:06:44,860 --> 00:06:50,340
But yeah, basically, you see, our application works now flawlessly for both ways.

89
00:06:50,830 --> 00:06:56,530
And now, instead of just having the BMI calculator here to bottom, I would like to also add a history

90
00:06:56,530 --> 00:06:57,520
of my exercise.

91
00:06:57,550 --> 00:06:59,470
So that's what we're going to do in the next video.

