Hi everyone.
So let's create a new class called Taxi manager inside our project.
So at the top and you just click on view to the windows and then click on project here.
Just open this app folder open this job folder and when cities first package here right just right click
on this package that actually contains this make me an activity class.
Right click on this package new and then click on Dobber class.
So for the name of the class just type in here taxi manager taxi manager and here let's actually specify
you can see that this kind is class.
OK.
Make sure that it is actually the class and here don't change anything.
The visibility is public and the modifier is not just going to kind of key.
So here we have this class called Taxi manager.
So let's go inside this class.
Let me actually double click on this top here.
Taxi manager's job up in order to make this area wider.
So inside this class inside the credibility of this class first let's create some valuables.
So the first variable that I am going to create is going to be a private as you can see that the access
to the fire is private and the data type is going to be off the location and the name of this variable
is going to be destination location destination location right semi-colon.
So this is our first value but and as you can see if it is not initialized yet we do not initialize
this valuable yet.
So now let's create a new method here.
Actually it is called a set here for this destination location instance variable.
So now I can say Puplick void and the name of this value is going to be set destination location and
put up her of here.
So if you're going to provide a parameter for this method which is going to be off their location and
the value is going to be destination destination location and an open and close.
This method by using the curly braces so you can see that the name of our instance variable is the initial
location and this name is actually exactly the same as the name of our promoter.
So in this case we must put this dot destination location.
So when I say this that this initial location I am referring to this instance variable of this taxi
manager class this refers to an instance of taxi manager.
So when I say this that this initial location is going to refer to this instance variable assignment
operator and now I can assign this this initial location this parameter to this instance variable.
So here I can see actually I can assign this parameter as an argument to this instance value but this
initial location.
So now after the end calibers of this sector and before the really cold embrace of this task manager
class that actually puts more lines of code here.
So here let's create another team effort so that they can hear Puplick and their return type of this
method is going to be float the name of the Smurfit is going to be return that this then is returned
a distance to destination location destination location in meters right and put up at Apprentice's.
So this is going to accept an identity and argument.
So if you need to specify that parameter here which is going to be off the up location and the name
of this parameter is going to be current location current location and just open and close the Smurfette
by using these curly braces.
So that may actually create some space here.
Now I can create an if statement here so I can't say current location is not equal to null.
So if you are going to check that it is called defensive programming.
First we must make sure that these are actually location objects are not null.
OK.
Otherwise our application may crash.
So first let's actually make sure that this current location is which is actually the parameter right.
It is null and then we must make sure that the destination location which is actually an instance variable
right.
It is actually also not null so not null.
Only in that case we can actually go inside this if statement and then we can return current location
that distance to and then we need to specify the destination location right so that its initial location
is going to be this one this initial location semi-colon.
So this is actually a predefined method.
The distance to my feet is a predefined method of this location class that we can actually use in order
to actually get the distance of actually from the current location to the destination location in meters.
Okay this is going to return a float value of floating point value.
So the first say current location data distance to destination location and thats as simple as that.
So what happens if current location is for example Nol or for example this the initial location is not
in that case you are going to have an else statement.
So I just open and close this statement by using the curly braces and here I can see return.
So we need to adjust the return of floating point value.
So here I just are just going to return up the actual negative value.
So for example return one hundred point zero if.
OK so this is of type float.
We must put this letter F here at the end of this value semicolon.
Right.
So thats it.
Lets actually.
So this is our man for the right.
Let's create another method.
So after the curly brace of this method and before the end in calibrates of this class I'm going to
create another method here the access money for you that I am going to create is going to be public
the return type of this method is going to be streamed.
So this method must return a value of type string.
And then in the name of this it is going to be returned return the miles between
current location and this the nation location
and it's actually quite a bit of practices here.
So now we need to specify the parameters of this method right.
So the first trimester of this Smurfette is going to be off site location and the name is going to be
cut into location right karma.
And the second location is going to be of type integer so it and the name of this valuable and shoot
the name of this primary is going to be meters per mile.
Right.
So let's actually open and close this method by using these curly braces.
Let me actually create a new line here so you can see it is my fifth year entirely.
This is the name of the method.
And these these are the two promoters of this method right.
So let's go inside the curly braces of the Smurfit.
So let's create valuable of that interior so it and the name of this variable is going to be Miles assignment
operator.
And let's actually we are going to actually get a floating point a floating value but we need to cast
it to an integer value in order to assign it to odd integer value but here the.
So here I can actually put a pair of parenthesis and right.
And now I can put up another prof practices here and I can defer to the Smurfette he returned the distance
to destination location in meters.
So let's actually refer to this Meffert return the distance to destination location in meters.
And now we need to pass the current location to dismiss it.
Right.
So I can't say Konitz location and here you can see that we have this Meffert and we passed the current
location divided by meters Hermite meters per mile.
So this formula this is actually a formula that you are not actually expected to know mathematics in
order to actually use this formula.
This is the formula you can use it whenever you want it where ever you want when you want to actually
create an Android application in order to for example get the miles between the current location and
the destination location.
First you need to actually get that distance emitters from the current location to the destination location
and then you need to divide that value to the value of the meters per mile that the user wants actually
to for example travel.
So if you get this meters per mile as that as an argument from the Smurfette here.
Right.
So and then we cast it to an integer value and we assign it to this variable of 10 miles.
So we have the Miles you're right.
Let me actually create another new line here.
So let me just actually put this new line here so that you can see the entire piece of code here right
now that we have Miles.
Let's create an if statement so if Miles is actually equal to number one if there is only one one mile
between the current location and the destination location I can just say return one might.
So we're going to return.
One might this value this string value from this method if the miles is actually equal to one.
So let's create an ELSE IF statement else.
If at inside Apprentice's I can say LCF Miles is actually greater than one.
In that case we are going to say return miles plus and let's actually put a pair of Cozzi at these two
double quotes and here I put our space here and then I can say Miles semi-colon.
So it's going to get the value of the Miles value of it and it's going to actually concatenated this
value of the value of the miles here.
So we're going to return this value from this actually else if statement let's actually create an else
statement.
If none of the conditions above is actually true then we are going to execute this Ellis statement here.
So he can't just return to cotes I can't say no mind no mind or Miles semi-colon.
OK.
So that this is on my feet and let's actually create another fit inside our taxi manager class.
So after the ending calibers of this method I'm going to create another fit in the next tutorial.
You can actually continue building this application.
Thanks very much for watching.
If you have any questions please put the discussion into Course and then I'll do my best to answer all
of your questions.