In the structure, we're going to see some examples to method first create a new class for these two.
So rocklike new Java class function and hit enter now copy a method from one of the files you've been
created before.
Copy and paste it here.
Hit enter again, as you see, there is a static key word in the definition of my method in Java.
There is a rule that static methods can code on the other static methods.
I will tell you why we have to do this, and I will share more details about the static keyword in a
separate lecture later in this course.
So we are going to add static to every function we will create here.
So first, create a function that doesn't have any parameters and it doesn't have a return value.
This function is going to print out something like hello or Good morning, I will go with hello.
So.
Static
void say hello.
It is the function name, parentheses, curly braces.
It's a. system that all that brings Winterland double quotes.
Hello.
Now run our code.
And as you can see, nothing is printed out, yes, because we didn't call this function to do that
type in the name of the method in the main method.
Just like this, so say hello, and that's it now we're Amarcord again.
Until it was printed out.
Moving on to a function that has a parameter but that still doesn't have a return value, that function
is going to use a loop to print out something on the screen based on the parameter it gets.
OK, so static void.
Let's call this blackboard punishment.
Parentheses and curly braces and in the parentheses, there is going to be a paint repeat number.
As I said, we are going to use a follow up here.
So for.
And I equals one semicolon.
I should be less than or equal, then repeat no more than a semicolon I Lospalos and the curly braces
and the not into the text is printed out really up to you.
I'm going to use being White Sox.
So standard outdoor printer and double codes being right.
Sox now call our function in the main method so that both punishment and use five as a parameter.
Now run our code.
Now, being right Sucks is printed out five times after hello.
Now I will show you how to create the discount price function with one parameter, then I will show
you an example of overloading.
All right, start with static.
Double the return type, the function name get.
Eight per cent of the second class.
Parentheses and an end price as a parameter in curly braces and.
And the return statement return.
Rice multiplied by zero point nine and a SEMICON to print out the 10 percent of price we're going to
use system that allowed that printer and function and the main method.
So system that allowed that printer on top of codes.
The price with 10 percent of.
Colin in the space plus and the function name get 10 percent of it, enter and use 20 thousand.
Now run our code.
And as you can see, eighteen thousand appeared on the screen.
Now let's move on to overloading
static.
Double.
The function name get discount price fantasy's.
The first is and price.
Coma then and percent curly braces.
And the return statement return the price multiplied by.
Percent and divided by a hundred.
Intelligence out this, let's see why surprise percent divided by 100 integer division and floating
point context.
Our code can run this way, but the problem is that in the expression we have integers only, but it
should return a double and an integer divided by another integer would give another integer, and that
while you would convert it to double at the end, it would lead to weird numbers to make it work correctly.
We have to convert one of our integers to double the easiest way to convert 100 to double by adding
a dot and a zero to it.
And now it's fine.
Now move on our last function in this lecture, so static.
Double.
Get discount price, so the function name is the same prentice's.
Double price
coma and percent curly braces hit enter and the return statement.
Price multiplied by the percent and divided by a hundred.
And they semicon and as you can see, we have a double in the return statement, the price, so we don't
have to convert any of our values into a double.
Now let's use the functions we created.
And as you can see, they are great out because they are not used.
So go back to the main method.
Double D-line changed the tax to 50 percent and change the function name to get discount price.
Use the inversion.
We need the second parameter here, which is going to be 50.
Now, just let's scroll down and as you can see, the function that uses an end is not great out anymore
because we're going to use this function and not this one here.
Now, double D-line again, now let's say it's going to be 40 percent change the value to a double value,
which is going to be a point fifty five.
And change the percentage to 60.
OK.
Now, all the functions are yellow, scroll back and run our code.
Everything seems fine, I hope it made clear how functions can be created and how overloading works,
if not, feel free to ask.
See you in the next lecture.