1 00:00:02,120 --> 00:00:07,520 In the structure, we're going to see some examples to method first create a new class for these two. 2 00:00:08,240 --> 00:00:20,090 So rocklike new Java class function and hit enter now copy a method from one of the files you've been 3 00:00:20,090 --> 00:00:21,140 created before. 4 00:00:23,400 --> 00:00:25,710 Copy and paste it here. 5 00:00:26,310 --> 00:00:33,090 Hit enter again, as you see, there is a static key word in the definition of my method in Java. 6 00:00:33,120 --> 00:00:38,160 There is a rule that static methods can code on the other static methods. 7 00:00:38,280 --> 00:00:44,700 I will tell you why we have to do this, and I will share more details about the static keyword in a 8 00:00:44,700 --> 00:00:47,270 separate lecture later in this course. 9 00:00:47,670 --> 00:00:52,060 So we are going to add static to every function we will create here. 10 00:00:52,410 --> 00:00:59,190 So first, create a function that doesn't have any parameters and it doesn't have a return value. 11 00:00:59,880 --> 00:01:06,130 This function is going to print out something like hello or Good morning, I will go with hello. 12 00:01:06,720 --> 00:01:07,320 So. 13 00:01:07,620 --> 00:01:08,640 Static 14 00:01:11,550 --> 00:01:14,760 void say hello. 15 00:01:15,030 --> 00:01:19,470 It is the function name, parentheses, curly braces. 16 00:01:19,650 --> 00:01:26,130 It's a. system that all that brings Winterland double quotes. 17 00:01:26,520 --> 00:01:27,030 Hello. 18 00:01:29,100 --> 00:01:30,180 Now run our code. 19 00:01:33,740 --> 00:01:39,830 And as you can see, nothing is printed out, yes, because we didn't call this function to do that 20 00:01:39,830 --> 00:01:42,970 type in the name of the method in the main method. 21 00:01:44,580 --> 00:01:50,670 Just like this, so say hello, and that's it now we're Amarcord again. 22 00:01:52,890 --> 00:01:54,240 Until it was printed out. 23 00:01:55,710 --> 00:02:02,220 Moving on to a function that has a parameter but that still doesn't have a return value, that function 24 00:02:02,220 --> 00:02:08,190 is going to use a loop to print out something on the screen based on the parameter it gets. 25 00:02:08,670 --> 00:02:13,230 OK, so static void. 26 00:02:13,890 --> 00:02:15,930 Let's call this blackboard punishment. 27 00:02:23,250 --> 00:02:33,120 Parentheses and curly braces and in the parentheses, there is going to be a paint repeat number. 28 00:02:34,830 --> 00:02:37,240 As I said, we are going to use a follow up here. 29 00:02:37,500 --> 00:02:38,790 So for. 30 00:02:41,130 --> 00:02:47,700 And I equals one semicolon. 31 00:02:49,240 --> 00:03:01,690 I should be less than or equal, then repeat no more than a semicolon I Lospalos and the curly braces 32 00:03:02,080 --> 00:03:05,410 and the not into the text is printed out really up to you. 33 00:03:05,590 --> 00:03:07,960 I'm going to use being White Sox. 34 00:03:07,970 --> 00:03:14,980 So standard outdoor printer and double codes being right. 35 00:03:16,090 --> 00:03:28,690 Sox now call our function in the main method so that both punishment and use five as a parameter. 36 00:03:29,740 --> 00:03:30,850 Now run our code. 37 00:03:34,680 --> 00:03:38,470 Now, being right Sucks is printed out five times after hello. 38 00:03:40,440 --> 00:03:46,800 Now I will show you how to create the discount price function with one parameter, then I will show 39 00:03:46,800 --> 00:03:48,840 you an example of overloading. 40 00:03:49,900 --> 00:03:51,820 All right, start with static. 41 00:03:55,350 --> 00:04:00,360 Double the return type, the function name get. 42 00:04:01,530 --> 00:04:08,130 Eight per cent of the second class. 43 00:04:09,410 --> 00:04:19,460 Parentheses and an end price as a parameter in curly braces and. 44 00:04:20,930 --> 00:04:24,020 And the return statement return. 45 00:04:26,560 --> 00:04:36,430 Rice multiplied by zero point nine and a SEMICON to print out the 10 percent of price we're going to 46 00:04:36,430 --> 00:04:40,700 use system that allowed that printer and function and the main method. 47 00:04:40,810 --> 00:04:45,970 So system that allowed that printer on top of codes. 48 00:04:47,570 --> 00:04:52,610 The price with 10 percent of. 49 00:04:54,250 --> 00:05:05,080 Colin in the space plus and the function name get 10 percent of it, enter and use 20 thousand. 50 00:05:06,040 --> 00:05:07,090 Now run our code. 51 00:05:10,090 --> 00:05:13,250 And as you can see, eighteen thousand appeared on the screen. 52 00:05:13,900 --> 00:05:15,700 Now let's move on to overloading 53 00:05:18,550 --> 00:05:19,360 static. 54 00:05:21,050 --> 00:05:21,590 Double. 55 00:05:23,390 --> 00:05:31,580 The function name get discount price fantasy's. 56 00:05:32,740 --> 00:05:36,520 The first is and price. 57 00:05:38,690 --> 00:05:46,430 Coma then and percent curly braces. 58 00:05:48,350 --> 00:05:56,240 And the return statement return the price multiplied by. 59 00:05:57,500 --> 00:06:02,660 Percent and divided by a hundred. 60 00:06:06,390 --> 00:06:15,780 Intelligence out this, let's see why surprise percent divided by 100 integer division and floating 61 00:06:15,780 --> 00:06:16,890 point context. 62 00:06:18,430 --> 00:06:26,020 Our code can run this way, but the problem is that in the expression we have integers only, but it 63 00:06:26,020 --> 00:06:35,320 should return a double and an integer divided by another integer would give another integer, and that 64 00:06:35,320 --> 00:06:44,450 while you would convert it to double at the end, it would lead to weird numbers to make it work correctly. 65 00:06:44,740 --> 00:06:54,730 We have to convert one of our integers to double the easiest way to convert 100 to double by adding 66 00:06:54,730 --> 00:06:56,800 a dot and a zero to it. 67 00:06:59,830 --> 00:07:00,890 And now it's fine. 68 00:07:01,420 --> 00:07:08,230 Now move on our last function in this lecture, so static. 69 00:07:10,160 --> 00:07:10,790 Double. 70 00:07:13,280 --> 00:07:22,010 Get discount price, so the function name is the same prentice's. 71 00:07:23,300 --> 00:07:25,760 Double price 72 00:07:28,280 --> 00:07:38,270 coma and percent curly braces hit enter and the return statement. 73 00:07:40,490 --> 00:07:50,660 Price multiplied by the percent and divided by a hundred. 74 00:07:52,340 --> 00:08:00,800 And they semicon and as you can see, we have a double in the return statement, the price, so we don't 75 00:08:00,800 --> 00:08:04,520 have to convert any of our values into a double. 76 00:08:05,060 --> 00:08:07,580 Now let's use the functions we created. 77 00:08:08,150 --> 00:08:11,830 And as you can see, they are great out because they are not used. 78 00:08:12,320 --> 00:08:14,120 So go back to the main method. 79 00:08:16,550 --> 00:08:31,740 Double D-line changed the tax to 50 percent and change the function name to get discount price. 80 00:08:32,180 --> 00:08:33,650 Use the inversion. 81 00:08:35,620 --> 00:08:40,240 We need the second parameter here, which is going to be 50. 82 00:08:42,320 --> 00:08:51,920 Now, just let's scroll down and as you can see, the function that uses an end is not great out anymore 83 00:08:52,640 --> 00:08:58,970 because we're going to use this function and not this one here. 84 00:09:00,230 --> 00:09:11,000 Now, double D-line again, now let's say it's going to be 40 percent change the value to a double value, 85 00:09:11,450 --> 00:09:15,230 which is going to be a point fifty five. 86 00:09:16,300 --> 00:09:19,780 And change the percentage to 60. 87 00:09:21,710 --> 00:09:22,300 OK. 88 00:09:23,640 --> 00:09:30,270 Now, all the functions are yellow, scroll back and run our code. 89 00:09:33,570 --> 00:09:40,650 Everything seems fine, I hope it made clear how functions can be created and how overloading works, 90 00:09:41,010 --> 00:09:42,740 if not, feel free to ask. 91 00:09:43,110 --> 00:09:44,460 See you in the next lecture.