1
00:00:00,790 --> 00:00:01,610
Hi everyone.

2
00:00:01,630 --> 00:00:06,790
So let's create a new class called Taxi manager inside our project.

3
00:00:06,850 --> 00:00:11,550
So at the top and you just click on view to the windows and then click on project here.

4
00:00:11,590 --> 00:00:17,950
Just open this app folder open this job folder and when cities first package here right just right click

5
00:00:17,950 --> 00:00:21,180
on this package that actually contains this make me an activity class.

6
00:00:21,280 --> 00:00:24,710
Right click on this package new and then click on Dobber class.

7
00:00:24,730 --> 00:00:34,920
So for the name of the class just type in here taxi manager taxi manager and here let's actually specify

8
00:00:35,000 --> 00:00:37,010
you can see that this kind is class.

9
00:00:37,050 --> 00:00:37,350
OK.

10
00:00:37,350 --> 00:00:41,520
Make sure that it is actually the class and here don't change anything.

11
00:00:41,610 --> 00:00:46,510
The visibility is public and the modifier is not just going to kind of key.

12
00:00:46,520 --> 00:00:49,760
So here we have this class called Taxi manager.

13
00:00:49,760 --> 00:00:51,230
So let's go inside this class.

14
00:00:51,350 --> 00:00:53,120
Let me actually double click on this top here.

15
00:00:53,120 --> 00:00:57,240
Taxi manager's job up in order to make this area wider.

16
00:00:57,260 --> 00:01:02,230
So inside this class inside the credibility of this class first let's create some valuables.

17
00:01:02,270 --> 00:01:07,820
So the first variable that I am going to create is going to be a private as you can see that the access

18
00:01:07,820 --> 00:01:13,850
to the fire is private and the data type is going to be off the location and the name of this variable

19
00:01:14,060 --> 00:01:20,560
is going to be destination location destination location right semi-colon.

20
00:01:20,710 --> 00:01:25,920
So this is our first value but and as you can see if it is not initialized yet we do not initialize

21
00:01:25,980 --> 00:01:26,900
this valuable yet.

22
00:01:27,040 --> 00:01:29,830
So now let's create a new method here.

23
00:01:29,830 --> 00:01:34,840
Actually it is called a set here for this destination location instance variable.

24
00:01:35,050 --> 00:01:42,010
So now I can say Puplick void and the name of this value is going to be set destination location and

25
00:01:42,010 --> 00:01:43,670
put up her of here.

26
00:01:43,690 --> 00:01:47,950
So if you're going to provide a parameter for this method which is going to be off their location and

27
00:01:47,950 --> 00:01:54,870
the value is going to be destination destination location and an open and close.

28
00:01:54,870 --> 00:02:01,140
This method by using the curly braces so you can see that the name of our instance variable is the initial

29
00:02:01,140 --> 00:02:07,530
location and this name is actually exactly the same as the name of our promoter.

30
00:02:07,620 --> 00:02:13,680
So in this case we must put this dot destination location.

31
00:02:13,680 --> 00:02:19,620
So when I say this that this initial location I am referring to this instance variable of this taxi

32
00:02:19,620 --> 00:02:24,100
manager class this refers to an instance of taxi manager.

33
00:02:24,300 --> 00:02:29,790
So when I say this that this initial location is going to refer to this instance variable assignment

34
00:02:29,790 --> 00:02:35,600
operator and now I can assign this this initial location this parameter to this instance variable.

35
00:02:35,610 --> 00:02:44,410
So here I can see actually I can assign this parameter as an argument to this instance value but this

36
00:02:44,430 --> 00:02:45,780
initial location.

37
00:02:45,780 --> 00:02:52,170
So now after the end calibers of this sector and before the really cold embrace of this task manager

38
00:02:52,170 --> 00:02:54,660
class that actually puts more lines of code here.

39
00:02:54,900 --> 00:03:00,780
So here let's create another team effort so that they can hear Puplick and their return type of this

40
00:03:00,780 --> 00:03:08,010
method is going to be float the name of the Smurfit is going to be return that this then is returned

41
00:03:08,010 --> 00:03:20,120
a distance to destination location destination location in meters right and put up at Apprentice's.

42
00:03:20,130 --> 00:03:23,430
So this is going to accept an identity and argument.

43
00:03:23,460 --> 00:03:27,930
So if you need to specify that parameter here which is going to be off the up location and the name

44
00:03:27,930 --> 00:03:35,360
of this parameter is going to be current location current location and just open and close the Smurfette

45
00:03:35,540 --> 00:03:37,360
by using these curly braces.

46
00:03:37,490 --> 00:03:40,100
So that may actually create some space here.

47
00:03:41,220 --> 00:03:48,550
Now I can create an if statement here so I can't say current location is not equal to null.

48
00:03:48,840 --> 00:03:52,230
So if you are going to check that it is called defensive programming.

49
00:03:52,230 --> 00:03:57,710
First we must make sure that these are actually location objects are not null.

50
00:03:57,830 --> 00:03:58,250
OK.

51
00:03:58,260 --> 00:04:00,480
Otherwise our application may crash.

52
00:04:00,480 --> 00:04:04,820
So first let's actually make sure that this current location is which is actually the parameter right.

53
00:04:04,860 --> 00:04:10,870
It is null and then we must make sure that the destination location which is actually an instance variable

54
00:04:10,870 --> 00:04:11,500
right.

55
00:04:11,580 --> 00:04:16,590
It is actually also not null so not null.

56
00:04:16,680 --> 00:04:25,510
Only in that case we can actually go inside this if statement and then we can return current location

57
00:04:25,820 --> 00:04:32,750
that distance to and then we need to specify the destination location right so that its initial location

58
00:04:32,750 --> 00:04:35,420
is going to be this one this initial location semi-colon.

59
00:04:35,420 --> 00:04:37,340
So this is actually a predefined method.

60
00:04:37,370 --> 00:04:43,940
The distance to my feet is a predefined method of this location class that we can actually use in order

61
00:04:44,150 --> 00:04:52,130
to actually get the distance of actually from the current location to the destination location in meters.

62
00:04:52,280 --> 00:04:55,440
Okay this is going to return a float value of floating point value.

63
00:04:55,580 --> 00:05:02,000
So the first say current location data distance to destination location and thats as simple as that.

64
00:05:02,180 --> 00:05:08,570
So what happens if current location is for example Nol or for example this the initial location is not

65
00:05:08,660 --> 00:05:12,500
in that case you are going to have an else statement.

66
00:05:12,640 --> 00:05:18,070
So I just open and close this statement by using the curly braces and here I can see return.

67
00:05:18,100 --> 00:05:20,650
So we need to adjust the return of floating point value.

68
00:05:20,660 --> 00:05:24,820
So here I just are just going to return up the actual negative value.

69
00:05:24,820 --> 00:05:29,450
So for example return one hundred point zero if.

70
00:05:29,540 --> 00:05:31,440
OK so this is of type float.

71
00:05:31,480 --> 00:05:35,660
We must put this letter F here at the end of this value semicolon.

72
00:05:35,920 --> 00:05:36,480
Right.

73
00:05:36,820 --> 00:05:38,070
So thats it.

74
00:05:38,100 --> 00:05:39,120
Lets actually.

75
00:05:39,140 --> 00:05:40,420
So this is our man for the right.

76
00:05:40,420 --> 00:05:41,780
Let's create another method.

77
00:05:41,770 --> 00:05:47,290
So after the curly brace of this method and before the end in calibrates of this class I'm going to

78
00:05:47,290 --> 00:05:52,880
create another method here the access money for you that I am going to create is going to be public

79
00:05:53,300 --> 00:05:56,830
the return type of this method is going to be streamed.

80
00:05:56,840 --> 00:06:00,090
So this method must return a value of type string.

81
00:06:00,230 --> 00:06:08,650
And then in the name of this it is going to be returned return the miles between

82
00:06:11,400 --> 00:06:16,320
current location and this the nation location

83
00:06:20,780 --> 00:06:24,190
and it's actually quite a bit of practices here.

84
00:06:24,230 --> 00:06:28,680
So now we need to specify the parameters of this method right.

85
00:06:29,960 --> 00:06:36,140
So the first trimester of this Smurfette is going to be off site location and the name is going to be

86
00:06:36,140 --> 00:06:39,310
cut into location right karma.

87
00:06:39,890 --> 00:06:45,810
And the second location is going to be of type integer so it and the name of this valuable and shoot

88
00:06:45,820 --> 00:06:50,840
the name of this primary is going to be meters per mile.

89
00:06:51,320 --> 00:06:51,830
Right.

90
00:06:51,830 --> 00:06:55,190
So let's actually open and close this method by using these curly braces.

91
00:06:55,190 --> 00:06:59,990
Let me actually create a new line here so you can see it is my fifth year entirely.

92
00:06:59,990 --> 00:07:00,920
This is the name of the method.

93
00:07:00,940 --> 00:07:03,490
And these these are the two promoters of this method right.

94
00:07:03,680 --> 00:07:06,870
So let's go inside the curly braces of the Smurfit.

95
00:07:06,920 --> 00:07:13,400
So let's create valuable of that interior so it and the name of this variable is going to be Miles assignment

96
00:07:13,400 --> 00:07:14,240
operator.

97
00:07:14,630 --> 00:07:20,810
And let's actually we are going to actually get a floating point a floating value but we need to cast

98
00:07:20,810 --> 00:07:25,640
it to an integer value in order to assign it to odd integer value but here the.

99
00:07:25,700 --> 00:07:29,410
So here I can actually put a pair of parenthesis and right.

100
00:07:29,680 --> 00:07:37,610
And now I can put up another prof practices here and I can defer to the Smurfette he returned the distance

101
00:07:37,610 --> 00:07:39,490
to destination location in meters.

102
00:07:39,500 --> 00:07:45,560
So let's actually refer to this Meffert return the distance to destination location in meters.

103
00:07:45,830 --> 00:07:48,490
And now we need to pass the current location to dismiss it.

104
00:07:48,490 --> 00:07:49,190
Right.

105
00:07:49,220 --> 00:07:56,950
So I can't say Konitz location and here you can see that we have this Meffert and we passed the current

106
00:07:56,950 --> 00:08:02,680
location divided by meters Hermite meters per mile.

107
00:08:02,890 --> 00:08:09,520
So this formula this is actually a formula that you are not actually expected to know mathematics in

108
00:08:09,520 --> 00:08:11,530
order to actually use this formula.

109
00:08:11,530 --> 00:08:16,180
This is the formula you can use it whenever you want it where ever you want when you want to actually

110
00:08:16,180 --> 00:08:21,190
create an Android application in order to for example get the miles between the current location and

111
00:08:21,190 --> 00:08:22,490
the destination location.

112
00:08:22,550 --> 00:08:28,640
First you need to actually get that distance emitters from the current location to the destination location

113
00:08:28,960 --> 00:08:35,450
and then you need to divide that value to the value of the meters per mile that the user wants actually

114
00:08:35,450 --> 00:08:36,700
to for example travel.

115
00:08:36,790 --> 00:08:40,690
So if you get this meters per mile as that as an argument from the Smurfette here.

116
00:08:40,690 --> 00:08:41,420
Right.

117
00:08:41,450 --> 00:08:46,390
So and then we cast it to an integer value and we assign it to this variable of 10 miles.

118
00:08:46,600 --> 00:08:48,070
So we have the Miles you're right.

119
00:08:48,070 --> 00:08:50,970
Let me actually create another new line here.

120
00:08:51,460 --> 00:09:01,520
So let me just actually put this new line here so that you can see the entire piece of code here right

121
00:09:02,060 --> 00:09:03,570
now that we have Miles.

122
00:09:03,680 --> 00:09:11,840
Let's create an if statement so if Miles is actually equal to number one if there is only one one mile

123
00:09:11,840 --> 00:09:20,110
between the current location and the destination location I can just say return one might.

124
00:09:20,170 --> 00:09:21,510
So we're going to return.

125
00:09:21,610 --> 00:09:26,490
One might this value this string value from this method if the miles is actually equal to one.

126
00:09:26,850 --> 00:09:29,280
So let's create an ELSE IF statement else.

127
00:09:29,320 --> 00:09:36,870
If at inside Apprentice's I can say LCF Miles is actually greater than one.

128
00:09:36,990 --> 00:09:45,480
In that case we are going to say return miles plus and let's actually put a pair of Cozzi at these two

129
00:09:45,480 --> 00:09:50,950
double quotes and here I put our space here and then I can say Miles semi-colon.

130
00:09:51,030 --> 00:09:55,290
So it's going to get the value of the Miles value of it and it's going to actually concatenated this

131
00:09:55,290 --> 00:09:57,780
value of the value of the miles here.

132
00:09:57,780 --> 00:10:02,550
So we're going to return this value from this actually else if statement let's actually create an else

133
00:10:02,550 --> 00:10:03,500
statement.

134
00:10:03,630 --> 00:10:09,870
If none of the conditions above is actually true then we are going to execute this Ellis statement here.

135
00:10:10,790 --> 00:10:18,510
So he can't just return to cotes I can't say no mind no mind or Miles semi-colon.

136
00:10:18,680 --> 00:10:19,490
OK.

137
00:10:19,580 --> 00:10:26,870
So that this is on my feet and let's actually create another fit inside our taxi manager class.

138
00:10:26,870 --> 00:10:31,090
So after the ending calibers of this method I'm going to create another fit in the next tutorial.

139
00:10:31,140 --> 00:10:33,350
You can actually continue building this application.

140
00:10:33,350 --> 00:10:34,700
Thanks very much for watching.

141
00:10:34,700 --> 00:10:40,010
If you have any questions please put the discussion into Course and then I'll do my best to answer all

142
00:10:40,010 --> 00:10:41,030
of your questions.

