Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,030 --> 00:00:07,770
Hey guys, and welcome to a brand new tutorial\xa0\n
2
00:00:07,769 --> 00:00:12,839
teaching you Java from the beginning. So starting\xa0\n
3
00:00:12,839 --> 00:00:17,730
how to create variables, methods, like all\xa0\n
4
00:00:17,730 --> 00:00:22,289
the advanced stuff. This is a beginner tutorial\xa0\n
5
00:00:22,289 --> 00:00:27,390
never learned any programming language before.\xa0\n
6
00:00:27,390 --> 00:00:32,399
thing we need to do is download a ID E. And this\xa0\n
7
00:00:32,399 --> 00:00:36,329
okay, so it's called Eclipse, that's what I'm\xa0\n
8
00:00:36,329 --> 00:00:39,479
beginner, I recommend you just follow along with\xa0\n
9
00:00:39,479 --> 00:00:45,119
are specific to eclipse. So go to this link,\xa0\n
10
00:00:45,119 --> 00:00:50,309
click on download. And then obviously, 32 or 64\xa0\n
11
00:00:50,310 --> 00:00:55,829
have a 64 bit machine. Once you download this,\xa0\n
12
00:00:55,829 --> 00:01:00,000
but if we go to our downloads, we will see\xa0\n
13
00:01:00,000 --> 00:01:08,039
double click on it, wait for this to boot up\xa0\n
14
00:01:08,040 --> 00:01:14,219
let's see. And once we're in here, we're simply\xa0\n
15
00:01:14,219 --> 00:01:18,870
we don't need to be using any of this other\xa0\n
16
00:01:18,870 --> 00:01:22,920
so we're going to install this, I already have it\xa0\n
17
00:01:22,920 --> 00:01:27,900
gonna ask you for a project directory, something\xa0\n
18
00:01:27,900 --> 00:01:33,780
wherever on your computer, it doesn't really\xa0\n
19
00:01:33,780 --> 00:01:39,150
you chose your project directory. Now we're going\xa0\n
20
00:01:39,150 --> 00:01:42,930
we need to do so it should look something like\xa0\n
21
00:01:42,930 --> 00:01:50,610
and then Java project. Now here, I'm just gonna\xa0\n
22
00:01:50,609 --> 00:01:54,510
can just leave all the rest of this stuff blank.\xa0\n
23
00:01:54,510 --> 00:01:59,580
click Finish. And there we are. So once we have\xa0\n
24
00:01:59,579 --> 00:02:02,609
the package explorer, I'm just gonna shrink\xa0\n
25
00:02:02,609 --> 00:02:06,930
is we're going to go down to source or Oh, I\xa0\n
26
00:02:06,930 --> 00:02:12,000
I'm going to create a new one really quickly, and\xa0\n
27
00:02:12,000 --> 00:02:19,310
one. Okay, finish. Alright, we got tutorial\xa0\n
28
00:02:19,310 --> 00:02:22,129
the source, what we're going to do is we're going\xa0\n
29
00:02:22,129 --> 00:02:26,719
and we're going to click on package. Now, I\xa0\n
30
00:02:26,719 --> 00:02:32,840
the same as your project. So I'm going to do that\xa0\n
31
00:02:32,840 --> 00:02:38,569
name, I'm going to click New, and plus. Okay, so\xa0\n
32
00:02:38,569 --> 00:02:41,719
it's going to allow you to select the package and\xa0\n
33
00:02:41,719 --> 00:02:47,150
the name you can name is whatever you want. In my\xa0\n
34
00:02:47,150 --> 00:02:52,849
discouraged. Okay, so let's name it main with\xa0\n
35
00:02:52,849 --> 00:02:57,829
like that. And then we're going to do is make sure\xa0\n
36
00:02:57,830 --> 00:03:01,910
to check mark this because we're gonna need this\xa0\n
37
00:03:01,909 --> 00:03:06,049
inherited abstract methods, you can uncheck\xa0\n
38
00:03:06,050 --> 00:03:11,120
really matter for right now. Okay, so now we're in\xa0\n
39
00:03:11,120 --> 00:03:16,189
I'm going to explain what this is. And then we'll\xa0\n
40
00:03:16,189 --> 00:03:19,280
just printing a few things to the screen before\xa0\n
41
00:03:19,280 --> 00:03:24,710
about data types. So Java is an object oriented\xa0\n
42
00:03:24,710 --> 00:03:29,000
happens inside of something called classes, and\xa0\n
43
00:03:29,000 --> 00:03:32,930
Now, you're not gonna understand very much of this\xa0\n
44
00:03:32,930 --> 00:03:37,310
guys that are more advanced, you should come to\xa0\n
45
00:03:37,310 --> 00:03:42,379
okay? And everything in Java is written in a\xa0\n
46
00:03:42,379 --> 00:03:46,759
our purpose, just think everything is written in\xa0\n
47
00:03:46,759 --> 00:03:52,459
we have a special method is what it's called. And\xa0\n
48
00:03:52,460 --> 00:03:57,260
inside these curly brackets, public static, void,\xa0\n
49
00:03:57,259 --> 00:04:00,829
what those words mean, just know, this method\xa0\n
50
00:04:00,830 --> 00:04:05,390
writing all of our Java code in for right now. So\xa0\n
51
00:04:05,389 --> 00:04:09,649
curly braces, and not inside of this method,\xa0\n
52
00:04:09,650 --> 00:04:14,060
your code is not going to execute properly unless\xa0\n
53
00:04:14,060 --> 00:04:20,209
we don't yet. So all the code we're writing goes\xa0\n
54
00:04:20,209 --> 00:04:24,529
these curly braces. All right. Now the first\xa0\n
55
00:04:24,529 --> 00:04:28,750
something to the screen. So to print something\xa0\n
56
00:04:32,110 --> 00:04:37,689
computer's lagging one second dot print, ln,\xa0\n
57
00:04:37,689 --> 00:04:43,540
now inside of these brackets here, we can print a\xa0\n
58
00:04:43,540 --> 00:04:48,280
in Java is anything encapsulated by two quotation\xa0\n
59
00:04:48,279 --> 00:04:52,089
we want to do it in two quotation marks, at least\xa0\n
60
00:04:52,089 --> 00:04:59,709
the classic hello world with an exclamation point,\xa0\n
61
00:04:59,709 --> 00:05:06,939
Java But with exception of lines that start or end\xa0\n
62
00:05:06,939 --> 00:05:12,459
now you can see once I put the semicolon, that\xa0\n
63
00:05:12,459 --> 00:05:17,469
we can see that it now has syntax highlighting. In\xa0\n
64
00:05:17,470 --> 00:05:22,540
the program. So we have to make sure that whenever\xa0\n
65
00:05:22,540 --> 00:05:27,910
a semicolon. Okay, so now we've officially written\xa0\n
66
00:05:27,910 --> 00:05:32,800
to the screen, but how can we run this. So first,\xa0\n
67
00:05:32,800 --> 00:05:38,470
S. And to run this, there's a little green button\xa0\n
68
00:05:38,470 --> 00:05:44,110
to click that. And you can see that down here, a\xa0\n
69
00:05:44,110 --> 00:05:49,750
to the screen, hello, world. Now that we've\xa0\n
70
00:05:49,750 --> 00:05:55,240
very simple. And that is how we go about setting\xa0\n
71
00:05:55,240 --> 00:05:58,930
for right now, again, remember is going to happen\xa0\n
72
00:05:58,930 --> 00:06:04,060
I'm gonna explain that later. public static\xa0\n
73
00:06:04,060 --> 00:06:07,600
you want to print another line, you want to\xa0\n
74
00:06:07,600 --> 00:06:12,400
I'll show you how that works. So I'm gonna say\xa0\n
75
00:06:12,399 --> 00:06:17,829
hello world, too. And if I save this, and run\xa0\n
76
00:06:21,449 --> 00:06:26,490
So you can see where we are right where we left\xa0\n
77
00:06:26,490 --> 00:06:30,750
world to to the screen. And in this video, I'm\xa0\n
78
00:06:30,750 --> 00:06:34,560
the absolute fundamentals, we have to understand\xa0\n
79
00:06:34,560 --> 00:06:42,360
So let's talk about what a variable is. Now a\xa0\n
80
00:06:42,360 --> 00:06:47,250
that holds a value. Now in our case, that doesn't\xa0\n
81
00:06:47,250 --> 00:06:52,350
could be a Boolean, and integer, like we're going\xa0\n
82
00:06:52,350 --> 00:07:00,240
are what are known as data types, or objects. So\xa0\n
83
00:07:00,240 --> 00:07:05,009
a variable, we need to first figure out what\xa0\n
84
00:07:05,009 --> 00:07:07,920
I'm going to start with an integer. And then\xa0\n
85
00:07:07,920 --> 00:07:14,160
types and talk about the differences. So to start,\xa0\n
86
00:07:14,160 --> 00:07:18,750
that we're about to type out is going to be an\xa0\n
87
00:07:18,750 --> 00:07:24,750
name. Now the variable name should contain\xa0\n
88
00:07:24,750 --> 00:07:28,680
I believe you can use numbers as long as it's at\xa0\n
89
00:07:28,680 --> 00:07:33,480
do that when we create a variable name, you have\xa0\n
90
00:07:33,480 --> 00:07:36,900
don't use any special characters as well. So I'll\xa0\n
91
00:07:36,899 --> 00:07:42,479
and invalid variable names. So a valid variable\xa0\n
92
00:07:42,480 --> 00:07:46,650
because we don't have any spaces. We don't have\xa0\n
93
00:07:46,649 --> 00:07:52,620
and Okay, now, an invalid variable name would\xa0\n
94
00:07:52,620 --> 00:07:59,129
thing as our variable name is invalid, because\xa0\n
95
00:07:59,129 --> 00:08:05,129
what do you call it percent sign like this, or\xa0\n
96
00:08:05,129 --> 00:08:09,899
valid variable name. So don't use any special\xa0\n
97
00:08:09,899 --> 00:08:14,069
could start with an underscore if you want to. But\xa0\n
98
00:08:14,069 --> 00:08:19,860
Typically, when you create a variable, if you want\xa0\n
99
00:08:19,860 --> 00:08:24,509
it is you type like Hello, and then you would do\xa0\n
100
00:08:24,509 --> 00:08:30,269
an underscore representing a space. And then next\xa0\n
101
00:08:30,269 --> 00:08:34,559
Not super important right now. So I'm going\xa0\n
102
00:08:34,559 --> 00:08:39,449
and that's going to be equal to by just putting\xa0\n
103
00:08:39,450 --> 00:08:43,800
case, we're gonna say five. And then remember,\xa0\n
104
00:08:43,799 --> 00:08:48,870
just saying my integer Hello, world is equal to\xa0\n
105
00:08:48,870 --> 00:08:55,019
there we go. And we see we get int, our variable\xa0\n
106
00:08:55,019 --> 00:09:00,720
issues. So if I let's just see what it says this\xa0\n
107
00:09:00,720 --> 00:09:08,310
officially created a variable, the variable name\xa0\n
108
00:09:08,309 --> 00:09:15,719
prove this to you, I am simply going to print\xa0\n
109
00:09:15,720 --> 00:09:22,110
so I'm gonna say system dot out to comment is\xa0\n
110
00:09:22,110 --> 00:09:28,139
do is we're gonna say, okay, so hello, underscore\xa0\n
111
00:09:28,139 --> 00:09:32,789
holds five. So when we print this, we should be\xa0\n
112
00:09:32,789 --> 00:09:36,509
right? Is it says, Okay, hello, world. Let's\xa0\n
113
00:09:36,509 --> 00:09:40,950
hello, world is equal to five. So we print that.\xa0\n
114
00:09:40,950 --> 00:09:45,210
down here in the bottom of the screen. Now I\xa0\n
115
00:09:45,210 --> 00:09:48,840
is just going to go this is a really important\xa0\n
116
00:09:48,840 --> 00:09:55,710
in programming tutorials. It's kind of like order\xa0\n
117
00:09:55,710 --> 00:10:02,490
put my variable underneath my System dot out dot\xa0\n
118
00:10:02,490 --> 00:10:07,919
world. And then I'm going to set hello world equal\xa0\n
119
00:10:07,919 --> 00:10:13,620
the issue might be here. If not, I'll talk about\xa0\n
120
00:10:13,620 --> 00:10:18,960
trying to print the value of hello world before\xa0\n
121
00:10:18,960 --> 00:10:24,300
the way things work is unless you otherwise\xa0\n
122
00:10:24,299 --> 00:10:29,370
bottom and left to right, just the way you'd read\xa0\n
123
00:10:29,370 --> 00:10:34,409
dot out dot print ln a Hello World, and then we\xa0\n
124
00:10:34,409 --> 00:10:40,379
hello world is. So if we tried to do this, you\xa0\n
125
00:10:40,379 --> 00:10:43,379
you know what, there's an error. Let's proceed\xa0\n
126
00:10:43,379 --> 00:10:49,110
we get a bunch of red text. And it says, What\xa0\n
127
00:10:49,110 --> 00:10:53,909
to a variable, because we haven't yet declared\xa0\n
128
00:10:53,909 --> 00:10:59,639
we're referencing or using variables that we\xa0\n
129
00:10:59,639 --> 00:11:05,580
like the line that we're using them in. Okay. So\xa0\n
130
00:11:05,580 --> 00:11:10,560
we print that to the screen. Now, let's create a\xa0\n
131
00:11:10,559 --> 00:11:15,750
types are. So in case I didn't really specify\xa0\n
132
00:11:15,750 --> 00:11:21,090
stands for any number that does not have a decimal\xa0\n
133
00:11:21,090 --> 00:11:28,019
like 5.0, this actually becomes a new data type.\xa0\n
134
00:11:28,019 --> 00:11:32,549
stands for floating decimal point, which means\xa0\n
135
00:11:32,549 --> 00:11:39,479
so I'm gonna say float. Let's see, num. Two\xa0\n
136
00:11:39,480 --> 00:11:47,670
and in this case, I'm going to say 5.0. What's\xa0\n
137
00:11:47,669 --> 00:11:52,409
one second where I said double. So sorry, I made\xa0\n
138
00:11:52,409 --> 00:11:56,189
as the name Okay, not float. Don't worry about\xa0\n
139
00:11:56,190 --> 00:12:01,320
anyways, we have double num two equals 5.0. Now\xa0\n
140
00:12:01,320 --> 00:12:06,660
anything that has a floating decimal point. So\xa0\n
141
00:12:06,659 --> 00:12:10,980
this in terms of mathematics, because it has\xa0\n
142
00:12:10,980 --> 00:12:18,990
is referenced as a double. Okay? Now, there's some\xa0\n
143
00:12:18,990 --> 00:12:23,490
about. So we have int, we have double, we also\xa0\n
144
00:12:23,490 --> 00:12:28,980
is true or false. And these are gonna be really\xa0\n
145
00:12:28,980 --> 00:12:34,170
about. So Boolean, I'm just gonna say B as my\xa0\n
146
00:12:34,169 --> 00:12:39,269
this case, I'm going to say true. And again, make\xa0\n
147
00:12:39,269 --> 00:12:47,579
two values that a that your boolean data type\xa0\n
148
00:12:47,580 --> 00:12:52,320
are important is because based on the value of a\xa0\n
149
00:12:52,320 --> 00:12:55,980
in our program. Like if B was equal to true, we're\xa0\n
150
00:12:55,980 --> 00:13:03,409
something. So that's really important. So another\xa0\n
151
00:13:03,409 --> 00:13:08,299
is any character. Okay, so this is a little bit\xa0\n
152
00:13:08,299 --> 00:13:12,259
last video, but I'm going to talk about string\xa0\n
153
00:13:12,259 --> 00:13:17,179
and whenever we create a character, there's two\xa0\n
154
00:13:17,179 --> 00:13:22,309
which you probably don't know what that is. Or\xa0\n
155
00:13:22,309 --> 00:13:26,719
just simply hitting the single quotation marks, we\xa0\n
156
00:13:26,720 --> 00:13:30,860
and that is a character because that's what char\xa0\n
157
00:13:30,860 --> 00:13:36,680
your keyboard, in quotation marks, now character\xa0\n
158
00:13:36,679 --> 00:13:41,719
so that's still a valid character. Because it's\xa0\n
159
00:13:41,720 --> 00:13:48,830
like nine if you're, if I were to type that\xa0\n
160
00:13:48,830 --> 00:13:54,139
goes in quotation marks is a char. Now we have\xa0\n
161
00:13:54,139 --> 00:13:59,179
one character, if I tried to, like 03, you can see\xa0\n
162
00:13:59,179 --> 00:14:03,859
us, and it's saying no, that's not allowed,\xa0\n
163
00:14:03,860 --> 00:14:07,490
now I just want to show you I want to go over\xa0\n
164
00:14:07,490 --> 00:14:13,250
between this nine and this nine, up here we've\xa0\n
165
00:14:13,250 --> 00:14:18,500
hello world, and it's set equal to nine. Okay,\xa0\n
166
00:14:18,500 --> 00:14:23,960
since it's in quotation marks, this is not the\xa0\n
167
00:14:23,960 --> 00:14:29,180
really do matter in this sense, okay. So I'm just\xa0\n
168
00:14:29,179 --> 00:14:36,259
now. Okay. Choice equals h. So that is extremely\xa0\n
169
00:14:36,259 --> 00:14:40,159
It's a different kind of data type, which we'll\xa0\n
170
00:14:40,159 --> 00:14:46,459
we do string I believe with a capital We'll see.\xa0\n
171
00:14:46,460 --> 00:14:52,460
in this case, I'm just gonna say str is equal to,\xa0\n
172
00:14:52,460 --> 00:14:58,430
quotation marks, okay? And I'm just gonna say\xa0\n
173
00:14:58,429 --> 00:15:04,309
and strings are double quotation marks, okay? And\xa0\n
174
00:15:04,309 --> 00:15:11,989
have like 673 underscore star, that's a completely\xa0\n
175
00:15:11,990 --> 00:15:16,409
they're with inside of these quotation marks.\xa0\n
176
00:15:16,409 --> 00:15:23,610
a nine in a string, this is different than a nine\xa0\n
177
00:15:23,610 --> 00:15:29,879
there are a few other ones, but I'm not going\xa0\n
178
00:15:29,879 --> 00:15:34,049
a bit more complex than than we can handle right\xa0\n
179
00:15:34,049 --> 00:15:39,929
this string is highlighted as a different color\xa0\n
180
00:15:39,929 --> 00:15:45,449
Booleans, orange chars orange, why is string\xa0\n
181
00:15:45,450 --> 00:15:51,990
it's a different type of data type. These four\xa0\n
182
00:15:51,990 --> 00:15:58,710
as primitive. And, wow, I really just did that\xa0\n
183
00:15:58,710 --> 00:16:05,759
okay. And what that stands for, is not changeable.\xa0\n
184
00:16:05,759 --> 00:16:09,600
data types and not primitive data types later\xa0\n
185
00:16:09,600 --> 00:16:16,080
about here are known as primitive in Java. And\xa0\n
186
00:16:16,080 --> 00:16:20,520
let's just see now, printing out like some\xa0\n
187
00:16:20,519 --> 00:16:24,689
we print them to the screen, right. So if I\xa0\n
188
00:16:24,690 --> 00:16:32,220
you should guess what we're gonna get, we get H,\xa0\n
189
00:16:32,220 --> 00:16:36,509
and so on. Now, last thing I want to show you\xa0\n
190
00:16:36,509 --> 00:16:41,669
variables equal to other variables, and we can add\xa0\n
191
00:16:41,669 --> 00:16:45,419
gonna be doing a lot in the next video, but I want\xa0\n
192
00:16:45,419 --> 00:16:49,620
I want to create a new integer, Okay, I'm gonna\xa0\n
193
00:16:49,620 --> 00:16:55,980
let's just call it Tim, why not. Now I want\xa0\n
194
00:16:55,980 --> 00:16:59,820
but I don't want to type nine out, what I'm\xa0\n
195
00:17:00,570 --> 00:17:06,900
underscore, underscore world like this. Now what\xa0\n
196
00:17:06,900 --> 00:17:12,269
from hello world, and we've assigned it to Tim.\xa0\n
197
00:17:12,269 --> 00:17:20,819
we get the value nine. Now if I want to print\xa0\n
198
00:17:20,819 --> 00:17:26,099
still getting the value of nine. So now Tim points\xa0\n
199
00:17:26,099 --> 00:17:31,199
Tim is equal to nine and hello world is equal to\xa0\n
200
00:17:31,200 --> 00:17:35,370
together, we can subtract variables, we can do all\xa0\n
201
00:17:35,369 --> 00:17:39,509
of variables, right. So we just have to make sure\xa0\n
202
00:17:39,509 --> 00:17:46,109
do something like this. String temp equals hello\xa0\n
203
00:17:46,109 --> 00:17:51,329
from int to string, because the datatype string\xa0\n
204
00:17:51,329 --> 00:17:55,349
do that until we learn about something called\xa0\n
205
00:17:58,549 --> 00:18:02,779
Now in this video, I'm going to be adding on to\xa0\n
206
00:18:02,779 --> 00:18:08,000
video. And I am going to be talking about basic\xa0\n
207
00:18:08,000 --> 00:18:15,140
exponential, all of that fun stuff. So without\xa0\n
208
00:18:15,140 --> 00:18:19,730
going to do is just talk about another way that\xa0\n
209
00:18:19,730 --> 00:18:25,549
you saw me do something like this index equals\xa0\n
210
00:18:25,549 --> 00:18:29,359
know this. But there's another way that we can\xa0\n
211
00:18:29,359 --> 00:18:35,029
we can actually omit this equal six. So if we\xa0\n
212
00:18:35,029 --> 00:18:41,450
now is we've declared that x is a variable,\xa0\n
213
00:18:41,450 --> 00:18:46,220
we've declared it but we have not initialized it.\xa0\n
214
00:18:46,220 --> 00:18:53,600
System dot out dot print ln, and we're simply\xa0\n
215
00:18:53,599 --> 00:19:00,079
probably helped I spelt print correctly. Okay.\xa0\n
216
00:19:00,079 --> 00:19:04,970
okay, run this. And you can see, we are already\xa0\n
217
00:19:04,970 --> 00:19:10,400
but and it says the local variable x may not have\xa0\n
218
00:19:10,400 --> 00:19:14,570
the variable x, when we set up like this, we\xa0\n
219
00:19:14,569 --> 00:19:19,849
underneath this declaration, we can just say x is\xa0\n
220
00:19:19,849 --> 00:19:23,959
be as long as it's an integer value. So in this\xa0\n
221
00:19:23,960 --> 00:19:27,950
we run the program, everything looks fine, and\xa0\n
222
00:19:27,950 --> 00:19:35,870
every data type. So if I do like char, and char\xa0\n
223
00:19:35,869 --> 00:19:41,750
single quotation marks, f like that. Okay, then we\xa0\n
224
00:19:41,750 --> 00:19:47,450
what I want to talk about now is operations.\xa0\n
225
00:19:47,450 --> 00:19:54,860
I'm going to say integer x equals five. Don't\xa0\n
226
00:19:54,859 --> 00:20:03,049
and I'll say int Zed is equal to 50. Okay, I'll\xa0\n
227
00:20:03,049 --> 00:20:09,529
going to start talking. So what I want to do now\xa0\n
228
00:20:09,529 --> 00:20:17,950
seven, and five. But I don't want to write like 56\xa0\n
229
00:20:17,950 --> 00:20:23,200
the value of these variables, this works fine. But\xa0\n
230
00:20:23,200 --> 00:20:27,490
that means I have to go down here and I have to\xa0\n
231
00:20:27,490 --> 00:20:31,539
if I want to change x and y? Well, that means I\xa0\n
232
00:20:31,539 --> 00:20:36,129
cool thing that we can do. And we can just use the\xa0\n
233
00:20:36,130 --> 00:20:45,250
x plus y, plus Zed like this, okay. And now our\xa0\n
234
00:20:45,250 --> 00:20:50,289
three variables. And to prove it to you, I will\xa0\n
235
00:20:50,289 --> 00:20:56,559
get 68 as our sum. Now, Furthermore, if we wanted\xa0\n
236
00:20:56,559 --> 00:21:04,569
them, all we have to do is simply replaces with a\xa0\n
237
00:21:04,569 --> 00:21:10,839
multiply things, this is another operator, we can\xa0\n
238
00:21:10,839 --> 00:21:17,169
multiplication, and we'll multiply all these out\xa0\n
239
00:21:17,170 --> 00:21:21,970
divide, we can use the forward slash. Now I'm not\xa0\n
240
00:21:21,970 --> 00:21:27,309
of a different topic. There's a weird thing with\xa0\n
241
00:21:27,309 --> 00:21:33,909
do that. So those are four basic operators. Now,\xa0\n
242
00:21:33,910 --> 00:21:38,620
of order of operations, right? So we're gonna\xa0\n
243
00:21:38,619 --> 00:21:45,969
or brackets, exponents, division, multiplication,\xa0\n
244
00:21:45,970 --> 00:21:52,240
guys know order of operations. So that means\xa0\n
245
00:21:52,240 --> 00:21:57,759
What's first going to operate is x multiplied\xa0\n
246
00:21:57,759 --> 00:22:04,119
whatever this value is. Now again, if I switch\xa0\n
247
00:22:04,119 --> 00:22:09,399
going to happen first is y multiplied by Zed, and\xa0\n
248
00:22:09,400 --> 00:22:14,650
example, if we have the operators that have the\xa0\n
249
00:22:14,650 --> 00:22:21,160
order of operation level, I don't know what to\xa0\n
250
00:22:21,160 --> 00:22:25,930
to right, so it's going to do x multiplied by y\xa0\n
251
00:22:25,930 --> 00:22:30,250
a lot people to understand this. If we do a\xa0\n
252
00:22:30,250 --> 00:22:36,069
y, and then we're gonna divide by Zed afterwards.\xa0\n
253
00:22:36,069 --> 00:22:40,299
whenever we're doing operations like this, we\xa0\n
254
00:22:40,299 --> 00:22:46,779
example, say x multiplied by y, and then divided\xa0\n
255
00:22:46,779 --> 00:22:52,480
brackets in here. So now it's showing 100% that\xa0\n
256
00:22:52,480 --> 00:22:56,019
same thing, if I did this, now, whatever's\xa0\n
257
00:22:56,019 --> 00:23:00,549
then I can divide by said, and obviously we can\xa0\n
258
00:23:00,549 --> 00:23:07,930
multiplied by y, times y, okay? Like, get out\xa0\n
259
00:23:07,930 --> 00:23:14,740
that's totally acceptable. And that totally works.\xa0\n
260
00:23:14,740 --> 00:23:18,130
more specifically, and then go into a few more\xa0\n
261
00:23:18,130 --> 00:23:26,140
different. In Java, is it just in general, okay.\xa0\n
262
00:23:26,140 --> 00:23:35,980
divide Zed by y, okay? And I some just do you,\xa0\n
263
00:23:35,980 --> 00:23:42,519
this out to the screen. 56 divided by seven, gives\xa0\n
264
00:23:42,519 --> 00:23:49,900
for the variable u, which is holding the value of\xa0\n
265
00:23:49,900 --> 00:23:55,509
So it actually isn't able to give us a floating\xa0\n
266
00:23:55,509 --> 00:24:00,670
is a floating point number, or is it a? Let's\xa0\n
267
00:24:00,670 --> 00:24:06,700
divided by this guy. Yeah, so we can't give us a\xa0\n
268
00:24:06,700 --> 00:24:10,390
datatype. So it assumes that we want an integer\xa0\n
269
00:24:10,390 --> 00:24:15,640
value and terminate all the decimals guy. So say\xa0\n
270
00:24:15,640 --> 00:24:20,500
us eight, right? removes the remainder. Now if\xa0\n
271
00:24:20,500 --> 00:24:29,200
to do most the time, I could try to do something\xa0\n
272
00:24:29,200 --> 00:24:32,559
by y. And you mean Okay, that makes sense double\xa0\n
273
00:24:32,559 --> 00:24:37,750
But watch what happens around this, we just get a\xa0\n
274
00:24:37,750 --> 00:24:43,960
is not 8.0. It has some decimal component to it\xa0\n
275
00:24:43,960 --> 00:24:49,960
we getting that? Well, that is because the two\xa0\n
276
00:24:49,960 --> 00:24:56,230
which means when we get a value back from this,\xa0\n
277
00:24:56,230 --> 00:25:01,450
do is convert it into double because we have this\xa0\n
278
00:25:01,450 --> 00:25:06,670
so how can we ensure that we get a floating point?\xa0\n
279
00:25:06,670 --> 00:25:12,279
first change the bottom to be a double. And we\xa0\n
280
00:25:12,279 --> 00:25:20,019
do like this, it's like double. And I could change\xa0\n
281
00:25:20,019 --> 00:25:26,710
of these double, and we try this, now I can\xa0\n
282
00:25:26,710 --> 00:25:31,960
shows up and gives us like, whatever that is. Now,\xa0\n
283
00:25:31,960 --> 00:25:38,079
and this is double i'd let's try this. Now, you\xa0\n
284
00:25:38,079 --> 00:25:43,449
because if one of the values that we're dividing\xa0\n
285
00:25:43,450 --> 00:25:47,590
the whole thing a double. So one of them is a\xa0\n
286
00:25:47,589 --> 00:25:53,679
is the way it works for all the operations. So if\xa0\n
287
00:25:53,680 --> 00:26:02,320
x times y, or let's say x times Zed, since Zed is\xa0\n
288
00:26:02,319 --> 00:26:06,639
value. So if we run this, you can see that we get\xa0\n
289
00:26:06,640 --> 00:26:12,700
a double, then that means everything is going to\xa0\n
290
00:26:12,700 --> 00:26:19,360
exponent, whether we can explain it is we have\xa0\n
291
00:26:19,359 --> 00:26:27,759
dot how. And then in here, you put the, what do\xa0\n
292
00:26:27,759 --> 00:26:36,789
not a star star like in most languages, okay. I'm\xa0\n
293
00:26:36,789 --> 00:26:42,609
And here, I'm simply going to raise x to the power\xa0\n
294
00:26:42,609 --> 00:26:53,569
is it saying? convert doc. So let's do this. int,\xa0\n
295
00:26:53,569 --> 00:27:00,829
interesting why it's telling you that let's just\xa0\n
296
00:27:00,829 --> 00:27:06,139
get X, X, exponents, apparently they have to be\xa0\n
297
00:27:06,140 --> 00:27:13,190
all right. So now if I want to print out D, what's\xa0\n
298
00:27:13,190 --> 00:27:17,570
okay? So math dot pow, this is your base. And\xa0\n
299
00:27:17,569 --> 00:27:24,349
five to the seven apparently is equal to that.\xa0\n
300
00:27:24,349 --> 00:27:29,509
I guess. Obviously, you can have as many operators\xa0\n
301
00:27:29,509 --> 00:27:33,769
things work in terms of doubles. And instead\xa0\n
302
00:27:33,769 --> 00:27:39,019
operators that are operators variables that you're\xa0\n
303
00:27:39,019 --> 00:27:43,460
then that means you're going to get a double\xa0\n
304
00:27:43,460 --> 00:27:48,140
that means you're going to get an integer value\xa0\n
305
00:27:48,140 --> 00:27:57,050
y back to double. And let's change you to be int.\xa0\n
306
00:27:57,049 --> 00:28:03,470
that's x times x times y. Okay, so now you can see\xa0\n
307
00:28:03,470 --> 00:28:08,809
double to Ent. And that is because we're trying\xa0\n
308
00:28:08,809 --> 00:28:14,299
but y is a double value. So when we get a value\xa0\n
309
00:28:14,299 --> 00:28:18,680
convert that into an integer just by doing this.\xa0\n
310
00:28:18,680 --> 00:28:23,509
going to show you in a second, okay. So we would\xa0\n
311
00:28:23,509 --> 00:28:27,410
it's nice in this ID, it tells you when you made\xa0\n
312
00:28:27,410 --> 00:28:31,820
might not really see that in your program. Okay,\xa0\n
313
00:28:31,819 --> 00:28:37,189
typecasting. We're going to talk about this\xa0\n
314
00:28:37,190 --> 00:28:42,410
you like fairly quickly how this works. I'm\xa0\n
315
00:28:42,410 --> 00:28:49,460
to turn these back into integers. Okay, so if I\xa0\n
316
00:28:49,460 --> 00:28:54,860
and I want to make sure that I'm getting that\xa0\n
317
00:28:54,859 --> 00:29:01,279
so a double, rather than converting these like the\xa0\n
318
00:29:01,279 --> 00:29:07,339
can do called typecasting and to typecast, we are\xa0\n
319
00:29:07,339 --> 00:29:12,829
the type of the variable, the way to do this is\xa0\n
320
00:29:12,829 --> 00:29:17,089
to convert your variable into, and then directly\xa0\n
321
00:29:17,089 --> 00:29:24,169
So in this case, it's double. And then we have y.\xa0\n
322
00:29:24,170 --> 00:29:29,029
of D, you can see that we get the decimal value\xa0\n
323
00:29:29,029 --> 00:29:36,349
right, then we do not get that or we do just go\xa0\n
324
00:29:40,329 --> 00:29:44,679
So in this video, I'm just gonna be teaching you\xa0\n
325
00:29:44,680 --> 00:29:48,970
last video. And we're gonna be talking about\xa0\n
326
00:29:48,970 --> 00:29:54,490
called a scanner. Now this scanner is going to\xa0\n
327
00:29:54,490 --> 00:29:59,079
all that fun stuff from the user and then do\xa0\n
328
00:29:59,079 --> 00:30:04,509
basis of progress. All right, based on what a user\xa0\n
329
00:30:05,500 --> 00:30:08,920
first thing that we're going to do is just teach\xa0\n
330
00:30:08,920 --> 00:30:17,289
still going to take the very long excuse, I'm just\xa0\n
331
00:30:17,289 --> 00:30:20,740
is what the name of the operator is modulus,\xa0\n
332
00:30:20,740 --> 00:30:27,099
this case, I'm gonna pick five. Okay, so what this\xa0\n
333
00:30:27,099 --> 00:30:31,179
Okay? Some people like to call a remainder\xa0\n
334
00:30:31,180 --> 00:30:36,580
us the remainder of this division. So this\xa0\n
335
00:30:36,579 --> 00:30:43,089
it 36 divided by five should give us 11? Okay, 11\xa0\n
336
00:30:43,089 --> 00:30:50,919
equal to. So if we print x, we should get a value\xa0\n
337
00:30:50,920 --> 00:30:55,600
the remainder operator is gives you the remainder\xa0\n
338
00:30:55,599 --> 00:30:59,349
it too much more, I'm sure you guys want to get\xa0\n
339
00:30:59,349 --> 00:31:06,129
now. Okay, so let's get rid of this line. And now\xa0\n
340
00:31:06,130 --> 00:31:09,520
scanner is what we're going to do so well, first\xa0\n
341
00:31:09,519 --> 00:31:15,430
program, you'll notice I have a new line here that\xa0\n
342
00:31:15,430 --> 00:31:19,990
guys to type this out for me, Java dot util dot\xa0\n
343
00:31:19,990 --> 00:31:24,130
this is what we're going to be using to get input.\xa0\n
344
00:31:24,130 --> 00:31:30,550
to import them at the top of our program so that\xa0\n
345
00:31:30,549 --> 00:31:34,990
And we'll get into this later when we talk about\xa0\n
346
00:31:34,990 --> 00:31:39,759
so once we've done that, we need to set up a\xa0\n
347
00:31:39,759 --> 00:31:46,839
the name of the scanner, I'm just gonna say SC is\xa0\n
348
00:31:46,839 --> 00:31:53,799
we're gonna type System dot gains brackets. This\xa0\n
349
00:31:53,799 --> 00:31:59,379
saying scanner is a dump type just like string\xa0\n
350
00:31:59,380 --> 00:32:05,260
it's a different type of data type, but it is in\xa0\n
351
00:32:05,259 --> 00:32:10,089
like one, or like putting quotation marks and\xa0\n
352
00:32:10,089 --> 00:32:16,750
a new scanner. And what the scanner is going to be\xa0\n
353
00:32:16,750 --> 00:32:22,450
And there's different types of scanners, which\xa0\n
354
00:32:22,450 --> 00:32:28,809
we've set up our scanner, we need to actually use\xa0\n
355
00:32:28,809 --> 00:32:40,569
going to type now is I'm going to say string scan\xa0\n
356
00:32:40,569 --> 00:32:47,470
use next Yep. So what this does is we're creating\xa0\n
357
00:32:47,470 --> 00:32:54,430
string type called scan. And it is going to get\xa0\n
358
00:32:54,430 --> 00:33:00,340
Okay, so SC dot next is what allows us to get a\xa0\n
359
00:33:00,339 --> 00:33:04,149
out scans after we get it because I want to show\xa0\n
360
00:33:04,150 --> 00:33:09,130
and illustrate and we'll talk about it. So now\xa0\n
361
00:33:09,130 --> 00:33:13,210
I'm able to type this because when type will\xa0\n
362
00:33:13,210 --> 00:33:22,210
it prints Hello, underneath it. So hello, which\xa0\n
363
00:33:22,210 --> 00:33:26,710
the scanner object using SC dot next, it got\xa0\n
364
00:33:26,710 --> 00:33:32,890
were able to print scan out to the screen. Okay.\xa0\n
365
00:33:32,890 --> 00:33:40,720
strings. Now watch this. If I type one, one works\xa0\n
366
00:33:40,720 --> 00:33:46,329
going to do this with the MTA. So I'm gonna say\xa0\n
367
00:33:46,329 --> 00:33:53,799
happening? What's wrong? Well, the issue right\xa0\n
368
00:33:53,799 --> 00:33:59,619
which is what this returns to us into an integer.\xa0\n
369
00:34:00,190 --> 00:34:05,170
se would proceed, we just run into an error,\xa0\n
370
00:34:05,170 --> 00:34:10,690
what this method gives us is a string. Now, if we\xa0\n
371
00:34:10,690 --> 00:34:17,920
for them typing, we have to use a another method,\xa0\n
372
00:34:17,920 --> 00:34:23,500
see we're getting no more red lines, everything\xa0\n
373
00:34:23,500 --> 00:34:30,070
we run this, then we type like 54. That works fine\xa0\n
374
00:34:30,070 --> 00:34:34,210
I try to type in something like Hello, so there's\xa0\n
375
00:34:34,210 --> 00:34:40,210
there's anything wrong. If I type Hello, we get an\xa0\n
376
00:34:40,210 --> 00:34:45,220
type in a integer. And what happens in here like\xa0\n
377
00:34:45,219 --> 00:34:50,139
is it tries to convert what I'm typing in,\xa0\n
378
00:34:50,139 --> 00:34:55,299
integer. So when it tried to do this, it tried to\xa0\n
379
00:34:55,300 --> 00:35:00,010
not you, not you or me knows how to convert\xa0\n
380
00:35:00,010 --> 00:35:04,540
So now that that's not allowed, you can't do that.\xa0\n
381
00:35:04,539 --> 00:35:09,009
get Booleans and other types, and I'll show you\xa0\n
382
00:35:09,010 --> 00:35:15,310
So if we want to get a boolean value, we could\xa0\n
383
00:35:15,309 --> 00:35:21,820
look at this Boolean? That's literally the name to\xa0\n
384
00:35:21,820 --> 00:35:28,240
this. Now, note a Boolean has to be true. spelled\xa0\n
385
00:35:28,239 --> 00:35:33,250
sure. So true, that works fine. But if I try to\xa0\n
386
00:35:33,250 --> 00:35:37,989
that's gonna crash, it's going to give us an\xa0\n
387
00:35:37,989 --> 00:35:44,769
once you get a double could do double equals\xa0\n
388
00:35:44,769 --> 00:35:49,659
there you go. And now it's going to expect a\xa0\n
389
00:35:49,659 --> 00:35:55,210
but I'm going to undo 6.3. And it prints out\xa0\n
390
00:35:55,210 --> 00:36:00,099
just give us 6.0. So that works fine. Okay, to\xa0\n
391
00:36:00,099 --> 00:36:05,500
issue of what happens like we get that crash,\xa0\n
392
00:36:05,500 --> 00:36:10,269
how can we fix that if we're per se, when it's\xa0\n
393
00:36:10,269 --> 00:36:17,500
what we should do is always get a string. So we\xa0\n
394
00:36:17,500 --> 00:36:21,949
this into a string. And that's because a string\xa0\n
395
00:36:21,949 --> 00:36:25,849
fine to be a string, because remember, a string\xa0\n
396
00:36:25,849 --> 00:36:30,289
if I type true, although Yeah, we know it's a\xa0\n
397
00:36:30,289 --> 00:36:36,380
really a string. Okay? If I type one, that's a\xa0\n
398
00:36:36,380 --> 00:36:41,780
can be converted into a string, pretty much. So\xa0\n
399
00:36:41,780 --> 00:36:48,110
a string, we can then convert it into an integer.\xa0\n
400
00:36:48,110 --> 00:36:53,990
we're going to do now is we're going to attempt\xa0\n
401
00:36:53,989 --> 00:36:57,919
in our case, I want to convert it into an integer.\xa0\n
402
00:36:57,920 --> 00:37:03,619
to set up a variable. So I'm gonna say index\xa0\n
403
00:37:03,619 --> 00:37:09,619
to put something with this scan, I can't just say\xa0\n
404
00:37:09,619 --> 00:37:13,339
it's not just gonna be able to convert that for\xa0\n
405
00:37:13,340 --> 00:37:23,780
need to do here is actually do dots, and are\xa0\n
406
00:37:23,780 --> 00:37:30,440
okay. And then inside of the brackets for parse\xa0\n
407
00:37:30,440 --> 00:37:34,460
is going to allow us to do is well convert into an\xa0\n
408
00:37:34,460 --> 00:37:37,250
you don't know what it does, you can actually\xa0\n
409
00:37:37,250 --> 00:37:42,139
it's going to say parses the string argument\xa0\n
410
00:37:42,139 --> 00:37:47,000
the string must be old decimal digits, except the\xa0\n
411
00:37:47,000 --> 00:37:51,739
so we can tell you it tells you exactly what this\xa0\n
412
00:37:51,739 --> 00:37:58,039
class. So yeah, it'll convert that for us, so\xa0\n
413
00:37:58,039 --> 00:38:01,969
would work fine. Now, the thing is that when this\xa0\n
414
00:38:01,969 --> 00:38:09,230
is, we still run into the same issue because\xa0\n
415
00:38:09,230 --> 00:38:15,260
we still get a crash, because how do we can\xa0\n
416
00:38:15,260 --> 00:38:21,260
really first check if the value is an integer.\xa0\n
417
00:38:21,260 --> 00:38:25,550
I believe, the next one or the one after that, how\xa0\n
418
00:38:25,550 --> 00:38:31,519
else statements and error catching later on. So\xa0\n
419
00:38:31,519 --> 00:38:35,210
now. If you know, you're going to be getting an\xa0\n
420
00:38:35,210 --> 00:38:41,090
you could just do next int and turn this to an\xa0\n
421
00:38:44,590 --> 00:38:48,220
So in this video, we're going to be\xa0\n
422
00:38:48,219 --> 00:38:53,919
like greater than less than or equal to not really\xa0\n
423
00:38:53,920 --> 00:38:57,369
which you'll see if you don't really understand\xa0\n
424
00:38:57,369 --> 00:39:02,949
and how we can use those Boolean variables to do\xa0\n
425
00:39:02,949 --> 00:39:06,099
about in the first few videos. And if you guys\xa0\n
426
00:39:06,099 --> 00:39:10,869
well, this video will show you. So without further\xa0\n
427
00:39:10,869 --> 00:39:15,819
off by typing a few numbers here because it's\xa0\n
428
00:39:15,820 --> 00:39:20,140
and then we'll do some other stuff. So I'm going\xa0\n
429
00:39:20,139 --> 00:39:28,119
X is six, y is seven ends, that is 10. Now I'm\xa0\n
430
00:39:28,119 --> 00:39:34,539
else, call it compare, and we'll just set that\xa0\n
431
00:39:34,539 --> 00:39:40,840
want to compare x and y and Zed using some\xa0\n
432
00:39:40,840 --> 00:39:46,539
I'm going to write them out here. We have a belief\xa0\n
433
00:39:46,539 --> 00:39:50,800
we'll type them out and we can see, so the first\xa0\n
434
00:39:50,800 --> 00:39:57,190
we have equal to, oops, we have greater than or\xa0\n
435
00:39:57,190 --> 00:40:01,480
Now I know I just went through those fast but\xa0\n
436
00:40:01,480 --> 00:40:06,130
going to state whether something is greater than\xa0\n
437
00:40:06,130 --> 00:40:11,380
or whatever way you have it right? This is, is\xa0\n
438
00:40:11,380 --> 00:40:16,660
than the single equal sign, double equal sign is\xa0\n
439
00:40:16,659 --> 00:40:21,489
the same. And the single equal sign like this one\xa0\n
440
00:40:21,489 --> 00:40:25,750
you remember that because a lot of people when\xa0\n
441
00:40:25,750 --> 00:40:29,829
equal sign, and they just use one and they end up\xa0\n
442
00:40:29,829 --> 00:40:33,819
or equal to pretty straightforward, less than\xa0\n
443
00:40:33,820 --> 00:40:39,340
exclamation point and an equal sign. Now I'm going\xa0\n
444
00:40:39,340 --> 00:40:43,059
I saw Actually, I'll leave that there. And because\xa0\n
445
00:40:43,059 --> 00:40:49,630
teach you this. If you do two slashes in Java,\xa0\n
446
00:40:49,630 --> 00:40:54,369
something that the computer is going to ignore.\xa0\n
447
00:40:54,369 --> 00:40:59,960
can look at it and be like, Okay, this is what\xa0\n
448
00:40:59,960 --> 00:41:03,409
doesn't care, so whenever it sees a line that\xa0\n
449
00:41:03,409 --> 00:41:07,879
a comment. It just ignores that line and moves\xa0\n
450
00:41:07,880 --> 00:41:13,640
just Gray's out in here to show us that that's a\xa0\n
451
00:41:13,639 --> 00:41:21,139
and y. And I want to set see if x is less than\xa0\n
452
00:41:21,139 --> 00:41:24,859
statement right here that we're typing here is\xa0\n
453
00:41:24,860 --> 00:41:30,800
So we can look at this, we say, well, six is not\xa0\n
454
00:41:30,800 --> 00:41:36,950
us a value of true. So if we print compared to the\xa0\n
455
00:41:36,949 --> 00:41:42,139
Now, if I flip this around, and I say greater\xa0\n
456
00:41:42,139 --> 00:41:47,059
Well, we get false, it's pretty straightforward to\xa0\n
457
00:41:47,059 --> 00:41:54,079
we can do two equal signs. And in this case, we\xa0\n
458
00:41:54,079 --> 00:41:59,000
some people get confused by. But if I do not\xa0\n
459
00:41:59,000 --> 00:42:03,860
the two values on the left side and the right side\xa0\n
460
00:42:03,860 --> 00:42:07,760
they're not the same, I get true. If they are the\xa0\n
461
00:42:07,760 --> 00:42:13,970
the same. So we should be getting true. Okay. And\xa0\n
462
00:42:13,969 --> 00:42:18,319
but they're pretty straightforward in terms of\xa0\n
463
00:42:18,320 --> 00:42:22,910
these work fine. So greater than or equal to less\xa0\n
464
00:42:22,909 --> 00:42:28,670
to compare strings, so I'm just going to change x\xa0\n
465
00:42:28,670 --> 00:42:42,320
oops, string, x, will say hello, and string\xa0\n
466
00:42:42,320 --> 00:42:46,550
now I'm getting this blurred out, or this red\xa0\n
467
00:42:46,550 --> 00:42:51,769
greater than or equal to undefined for strings. So\xa0\n
468
00:42:51,769 --> 00:42:56,750
at least for right now that we're going to talk\xa0\n
469
00:42:56,750 --> 00:43:02,840
okay? And not equal to is simply going to say,\xa0\n
470
00:43:02,840 --> 00:43:07,280
they are the same, so in this case, I say not the\xa0\n
471
00:43:07,280 --> 00:43:12,120
if they are the same, I get false. Now, I want you\xa0\n
472
00:43:12,119 --> 00:43:18,480
and I add a capital O at the end of Hello like\xa0\n
473
00:43:18,480 --> 00:43:25,320
with all lower cases are not? Well, I'll show\xa0\n
474
00:43:25,320 --> 00:43:29,970
program, right, let's assume with variable names,\xa0\n
475
00:43:29,969 --> 00:43:35,309
lowercase variable y. Okay, so that's how we\xa0\n
476
00:43:35,309 --> 00:43:39,329
can we use greater than net, we can't use\xa0\n
477
00:43:39,329 --> 00:43:45,119
Okay. So what I'm going to do now is I want to\xa0\n
478
00:43:45,119 --> 00:43:50,699
to show you the end operator, the OR operator,\xa0\n
479
00:43:50,699 --> 00:43:56,219
add multiple conditions together to get one\xa0\n
480
00:43:56,219 --> 00:44:01,169
I'm going to change these back to two numbers\xa0\n
481
00:44:01,170 --> 00:44:07,860
equals what I have six into y equals, let's just\xa0\n
482
00:44:07,860 --> 00:44:13,650
compare multiple things at once. So I first want\xa0\n
483
00:44:13,650 --> 00:44:19,680
to compare if Zed is greater than x, say I want to\xa0\n
484
00:44:19,679 --> 00:44:24,690
you'd want to do that. The way that we can do that\xa0\n
485
00:44:24,690 --> 00:44:30,210
is using this an operator AND AND operator is\xa0\n
486
00:44:30,210 --> 00:44:34,650
okay? And then we have to add another condition\xa0\n
487
00:44:34,650 --> 00:44:41,460
Zed is arch, say Zed is less than y, okay? You can\xa0\n
488
00:44:41,460 --> 00:44:46,409
And what this does is it's going to compare the\xa0\n
489
00:44:46,409 --> 00:44:50,250
comparison on the right side, and then we're going\xa0\n
490
00:44:50,250 --> 00:44:54,389
x is greater than y. So six, is that greater than\xa0\n
491
00:44:54,389 --> 00:44:59,670
it out as if this is what's happening in the\xa0\n
492
00:44:59,670 --> 00:45:07,019
it is. So we get true like this, okay? Now, we\xa0\n
493
00:45:07,019 --> 00:45:11,880
this and operator in between them. What this and\xa0\n
494
00:45:11,880 --> 00:45:17,400
the conditions on the left side and the right side\xa0\n
495
00:45:17,400 --> 00:45:22,380
us. If they're both pretty one of them is false,\xa0\n
496
00:45:22,380 --> 00:45:26,940
value. So in this case, since this one is false,\xa0\n
497
00:45:26,940 --> 00:45:33,000
them have to be true for this to evaluate to true.\xa0\n
498
00:45:33,000 --> 00:45:37,320
this to the screen, you can see we get a false\xa0\n
499
00:45:37,320 --> 00:45:44,190
are true, then the whole thing is true. Okay. Now\xa0\n
500
00:45:44,190 --> 00:45:48,990
And the OR operator is to straight up lines like\xa0\n
501
00:45:48,989 --> 00:45:55,229
the key for that, but anyways, so this is gonna do\xa0\n
502
00:45:55,230 --> 00:46:00,869
around, if one of the two conditions are true,\xa0\n
503
00:46:00,869 --> 00:46:07,619
if both of them are false, it's false, right?\xa0\n
504
00:46:07,619 --> 00:46:10,349
right is we'll do this condition, we'll see what\xa0\n
505
00:46:10,349 --> 00:46:14,789
is equal to. And if one of them are true, we get a\xa0\n
506
00:46:14,789 --> 00:46:22,529
we get a true value. Now, we have a knot operator.\xa0\n
507
00:46:22,530 --> 00:46:26,820
anything. And this is what I like to think about\xa0\n
508
00:46:26,820 --> 00:46:34,800
reverse it. So what this does is it's going to say\xa0\n
509
00:46:34,800 --> 00:46:40,230
Or if this condition is false or not true, then\xa0\n
510
00:46:40,230 --> 00:46:45,809
is true, then it's false. Because it's checking if\xa0\n
511
00:46:45,809 --> 00:46:50,369
of just have to play with it to make sense of it.\xa0\n
512
00:46:50,369 --> 00:46:55,619
we have this exclamation point, which is our NOT\xa0\n
513
00:46:55,619 --> 00:47:02,579
here we get false. Now if in here I were to put a\xa0\n
514
00:47:02,579 --> 00:47:08,579
by typing in the value, I say not and then false\xa0\n
515
00:47:08,579 --> 00:47:13,259
So it's simply just reverses like anything that\xa0\n
516
00:47:13,260 --> 00:47:18,270
we can actually combined all of these operators\xa0\n
517
00:47:18,269 --> 00:47:22,530
ands and ORS and we can have an infinitely\xa0\n
518
00:47:22,530 --> 00:47:26,730
evaluate to true. Now this is actually some kind\xa0\n
519
00:47:26,730 --> 00:47:31,110
university, I'm gonna have to do it next semester,\xa0\n
520
00:47:31,110 --> 00:47:34,380
and you have to figure out if you're going to\xa0\n
521
00:47:34,380 --> 00:47:44,820
you like a pretty basic example. So I'll say if x\xa0\n
522
00:47:44,820 --> 00:47:54,300
plus two is less than five. Or what do you call\xa0\n
523
00:47:54,300 --> 00:47:59,700
so I just typed a bunch of conditions, right?\xa0\n
524
00:47:59,699 --> 00:48:04,230
are going to evaluate first? Well, that is a good\xa0\n
525
00:48:04,230 --> 00:48:07,440
this. Because just looking at this, like even\xa0\n
526
00:48:07,440 --> 00:48:12,960
it in. I'm like, wow, okay, how do I determine\xa0\n
527
00:48:12,960 --> 00:48:17,699
typically, you put things in brackets, so I would\xa0\n
528
00:48:17,699 --> 00:48:22,109
so I have this first conditional, right? You put\xa0\n
529
00:48:22,110 --> 00:48:25,769
this case, we'll get I'm not going to bother doing\xa0\n
530
00:48:25,769 --> 00:48:33,360
okay? Or so we have true, or whatever this\xa0\n
531
00:48:33,360 --> 00:48:38,550
going to do now is it's going to look at said plus\xa0\n
532
00:48:38,550 --> 00:48:43,710
then we get true or and then whatever this is,\xa0\n
533
00:48:43,710 --> 00:48:48,090
brackets like this. Okay. So now the way that this\xa0\n
534
00:48:48,090 --> 00:48:51,780
we get a value of like true or false. We do\xa0\n
535
00:48:51,780 --> 00:48:56,250
true or false. And then we'd see if either of them\xa0\n
536
00:48:56,250 --> 00:49:00,929
let's just print it to see what we get. If we get\xa0\n
537
00:49:00,929 --> 00:49:05,039
be honest. And yeah, that's how we could do\xa0\n
538
00:49:05,039 --> 00:49:09,239
too. So if I want to throw a knot like this,\xa0\n
539
00:49:09,239 --> 00:49:14,189
going to see massive chain conditionals like this,\xa0\n
540
00:49:14,190 --> 00:49:18,720
it's difficult to determine what they are by just\xa0\n
541
00:49:18,719 --> 00:49:23,579
and else statements in the next video how we can\xa0\n
542
00:49:23,579 --> 00:49:28,199
I just wanted to show you that you can combine\xa0\n
543
00:49:28,199 --> 00:49:32,399
have to use variables, you can see that here I put\xa0\n
544
00:49:32,400 --> 00:49:37,829
valid condition that works perfectly fine, can\xa0\n
545
00:49:37,829 --> 00:49:43,049
add constants, like I could just say two is equal\xa0\n
546
00:49:43,050 --> 00:49:47,519
compare with constants. And with strings, just\xa0\n
547
00:49:47,519 --> 00:49:52,590
sorry, not less than not the not equal to or equal\xa0\n
548
00:49:52,590 --> 00:49:56,010
you'll see as we continue going through the video,\xa0\n
549
00:49:59,329 --> 00:50:06,199
In this video, we're going to be going over if,\xa0\n
550
00:50:06,199 --> 00:50:09,710
just I want to fix a really small mistake I made\xa0\n
551
00:50:09,710 --> 00:50:15,019
I am like a Python programmer typically. So I'm\xa0\n
552
00:50:15,019 --> 00:50:18,530
first language. So I'm used to being able to use\xa0\n
553
00:50:18,530 --> 00:50:22,160
that's what you can do in Python. But in the\xa0\n
554
00:50:22,159 --> 00:50:28,039
on strings. Now, that's not incorrect to do that,\xa0\n
555
00:50:28,039 --> 00:50:33,320
now. So if you want to compare if two strings are\xa0\n
556
00:50:33,320 --> 00:50:38,059
have the same, what you should actually do is say\xa0\n
557
00:50:38,059 --> 00:50:42,889
do dot equals Okay. And then inside of this equals\xa0\n
558
00:50:42,889 --> 00:50:46,309
to compare it to, or you're going to put another\xa0\n
559
00:50:46,309 --> 00:50:50,659
I want to say if like, my scanner object, which\xa0\n
560
00:50:50,659 --> 00:50:56,539
to Hello, this is how I would do it with this dot\xa0\n
561
00:50:56,539 --> 00:51:00,920
equal signs isn't wrong, but it's going to give\xa0\n
562
00:51:00,920 --> 00:51:04,460
that in future videos, but it's too advanced to go\xa0\n
563
00:51:04,460 --> 00:51:09,710
compare two strings, use dot equals My apologies\xa0\n
564
00:51:09,710 --> 00:51:14,900
do now is we're going to do it using if and else\xa0\n
565
00:51:14,900 --> 00:51:22,070
do this, otherwise, do this. And this is the\xa0\n
566
00:51:22,070 --> 00:51:25,940
on like user input, or based on certain events\xa0\n
567
00:51:25,940 --> 00:51:30,500
right? So they're really important to understand.\xa0\n
568
00:51:30,500 --> 00:51:34,550
getting, I'm just setting up a new scanner object,\xa0\n
569
00:51:34,550 --> 00:51:39,500
already talked about this. And what I want to do\xa0\n
570
00:51:39,500 --> 00:51:44,210
on what they type in, I want to do something.\xa0\n
571
00:51:44,210 --> 00:51:49,970
you simply type if you put brackets, and inside\xa0\n
572
00:51:49,969 --> 00:51:54,319
And this is why I spend so much time talking about\xa0\n
573
00:51:54,320 --> 00:51:58,760
if this condition evaluates to true, whatever's\xa0\n
574
00:51:58,760 --> 00:52:03,230
whatever's inside of these curly braces is going\xa0\n
575
00:52:03,230 --> 00:52:10,699
I say if s dot equals not two equal signs, and\xa0\n
576
00:52:10,699 --> 00:52:16,939
user types in Tim, when we're when we prompt them\xa0\n
577
00:52:16,940 --> 00:52:21,980
going to happen is inside of these curly braces,\xa0\n
578
00:52:21,980 --> 00:52:28,099
an if statement, or an IF block. So this block\xa0\n
579
00:52:28,099 --> 00:52:33,380
these brackets inside the brackets as a condition,\xa0\n
580
00:52:33,380 --> 00:52:37,400
as you want, as long as you're going to get a\xa0\n
581
00:52:37,400 --> 00:52:42,440
have these curly braces, so an open brace and a\xa0\n
582
00:52:42,440 --> 00:52:47,900
that I typed in here is going to happen if this\xa0\n
583
00:52:47,900 --> 00:52:52,700
test here. And I'm going to do system dot out.\xa0\n
584
00:52:52,699 --> 00:53:02,359
you typed Tim, okay, what types you types? you\xa0\n
585
00:53:02,360 --> 00:53:10,700
see what happens. So when I run this, if it loads\xa0\n
586
00:53:10,699 --> 00:53:14,869
so we're back, I accidentally closed my console.\xa0\n
587
00:53:14,869 --> 00:53:21,079
So I got that up and running now. Let me\xa0\n
588
00:53:21,079 --> 00:53:25,880
I don't know why. That's why But anyways, let's\xa0\n
589
00:53:25,880 --> 00:53:31,550
let's type hello and see what we get? Well, we get\xa0\n
590
00:53:31,550 --> 00:53:36,800
it again. Let's try it. And this time I type Tim,\xa0\n
591
00:53:36,800 --> 00:53:45,950
basic if statement is working. Now I want you to\xa0\n
592
00:53:45,949 --> 00:53:51,349
we can see what happens when we have like just\xa0\n
593
00:53:51,349 --> 00:53:57,860
I'm literally going to print print. Okay. So now\xa0\n
594
00:53:57,860 --> 00:54:03,860
what is the program going to run? So if we type\xa0\n
595
00:54:03,860 --> 00:54:07,400
we still going to get this print out here? Or are\xa0\n
596
00:54:07,400 --> 00:54:11,480
and see, okay, so in this case, I typed Tim. So\xa0\n
597
00:54:11,480 --> 00:54:16,849
it says print, okay? Now the reason that happens\xa0\n
598
00:54:16,849 --> 00:54:20,929
right? So we're just going to execute simply\xa0\n
599
00:54:20,929 --> 00:54:27,649
right? If I type, like Hi, it's still going to\xa0\n
600
00:54:27,650 --> 00:54:31,940
It didn't go through this if block but this is\xa0\n
601
00:54:31,940 --> 00:54:36,679
or whatever. So that executes. Okay, so that's\xa0\n
602
00:54:36,679 --> 00:54:43,819
you else and elsket rest start with else. So else\xa0\n
603
00:54:43,820 --> 00:54:50,330
and else if or and if so, like the start of\xa0\n
604
00:54:50,329 --> 00:54:54,500
can't just have it like alone. It has to come\xa0\n
605
00:54:54,500 --> 00:54:58,280
which we're going to go into in a second. Okay.\xa0\n
606
00:54:58,280 --> 00:55:03,290
like to put the else like this Has the closing\xa0\n
607
00:55:03,289 --> 00:55:09,170
to do it like this. Some people like to do it like\xa0\n
608
00:55:09,170 --> 00:55:13,250
fine. Just make sure that your curly brace doesn't\xa0\n
609
00:55:13,250 --> 00:55:16,699
because that's kind of hard to read. Okay. So\xa0\n
610
00:55:16,699 --> 00:55:22,279
print statement, and I'm going to put it in my elf\xa0\n
611
00:55:22,280 --> 00:55:27,290
if this happens, that's fine. We're going to go\xa0\n
612
00:55:27,289 --> 00:55:33,619
we'll move down to the end of the block. So we'll\xa0\n
613
00:55:33,619 --> 00:55:39,949
this doesn't happen, so other words, or else, then\xa0\n
614
00:55:39,949 --> 00:55:44,659
Tim or print, we're never printing both because\xa0\n
615
00:55:44,659 --> 00:55:51,049
so let's test this out. If I type Tim, we you type\xa0\n
616
00:55:51,050 --> 00:55:56,600
random letters, and I hit Enter, you get print.\xa0\n
617
00:55:56,599 --> 00:56:01,099
this condition is not true, right? Okay, so that's\xa0\n
618
00:56:01,099 --> 00:56:05,630
about that anymore. The next one I'm going to\xa0\n
619
00:56:05,630 --> 00:56:13,190
add multiple if conditions in one kind of block.\xa0\n
620
00:56:13,190 --> 00:56:19,909
And now it's the exact same syntax as regular if\xa0\n
621
00:56:19,909 --> 00:56:26,779
And obviously, since this is an else it has to\xa0\n
622
00:56:26,780 --> 00:56:31,310
have as many of these else ifs as you want. Now,\xa0\n
623
00:56:31,309 --> 00:56:39,639
s dot equals, and in this case, let's just say\xa0\n
624
00:56:39,639 --> 00:56:47,230
system, dot out, dot print, ln, and we'll just say\xa0\n
625
00:56:47,230 --> 00:56:51,579
Hello. Okay, so again, the way this is gonna work,\xa0\n
626
00:56:51,579 --> 00:56:56,319
we're gonna get our scanner input, we get\xa0\n
627
00:56:56,320 --> 00:57:01,450
if it is we're gonna print this, and then we're\xa0\n
628
00:57:01,449 --> 00:57:05,349
we're not going to even bother checking if it's\xa0\n
629
00:57:05,349 --> 00:57:11,199
then we know that we shouldn't bother looking at\xa0\n
630
00:57:11,199 --> 00:57:14,799
what we're going to do is we're going to go\xa0\n
631
00:57:14,800 --> 00:57:19,630
that's our next block, is it equal to Hello,\xa0\n
632
00:57:19,630 --> 00:57:22,390
we're gonna move on with our lives, you're gonna\xa0\n
633
00:57:22,389 --> 00:57:27,400
going to the else. Okay? Now, if it's not equal to\xa0\n
634
00:57:27,400 --> 00:57:31,180
And we're just simply going to print print,\xa0\n
635
00:57:31,179 --> 00:57:36,219
going to happen. If you print anything other than\xa0\n
636
00:57:36,219 --> 00:57:42,819
so let's try this out. And let's type Hello.\xa0\n
637
00:57:42,820 --> 00:57:49,510
if I print type anything else in here, like some\xa0\n
638
00:57:49,510 --> 00:57:55,390
how that works. Now I can show you I can add as\xa0\n
639
00:57:55,389 --> 00:58:01,000
simply paste it down here, gonna have another LCF.\xa0\n
640
00:58:01,000 --> 00:58:06,130
I could type Hello. And we could keep going.\xa0\n
641
00:58:06,130 --> 00:58:09,940
know that whenever you have a kind of a block\xa0\n
642
00:58:09,940 --> 00:58:15,880
if statement. And it does actually doesn't have to\xa0\n
643
00:58:15,880 --> 00:58:21,369
last thing so if you have any else ifs else will\xa0\n
644
00:58:21,369 --> 00:58:27,219
and then try typing like that's, that's not\xa0\n
645
00:58:27,219 --> 00:58:32,649
that's perfectly fine. So now I have if we type\xa0\n
646
00:58:32,650 --> 00:58:36,490
And let's type none of them. Let's, let's type a\xa0\n
647
00:58:36,489 --> 00:58:42,909
screen because we don't have that l statement.\xa0\n
648
00:58:42,909 --> 00:58:47,529
right we went through wasn't equal to Tim. It\xa0\n
649
00:58:47,530 --> 00:58:53,840
I want to show you this. This is a bad example.\xa0\n
650
00:58:53,840 --> 00:58:58,280
Hello here. Which one are we going to print? So\xa0\n
651
00:58:58,280 --> 00:59:03,650
things. We're not going to print more than one.\xa0\n
652
00:59:03,650 --> 00:59:10,579
let's test it out. If I type Hello in here, we\xa0\n
653
00:59:10,579 --> 00:59:15,289
is because this else if is above this one, and\xa0\n
654
00:59:15,289 --> 00:59:21,019
at when we type something in just the way I kind\xa0\n
655
00:59:21,019 --> 00:59:25,159
high here, we're like, Okay, well that happened.\xa0\n
656
00:59:25,159 --> 00:59:30,319
move on. Okay, straightforward. Now again, I could\xa0\n
657
00:59:30,320 --> 00:59:34,880
typing like do a bunch of stuff, just understand\xa0\n
658
00:59:34,880 --> 00:59:38,539
need to know stuff. Like we could just do an IF\xa0\n
659
00:59:38,539 --> 00:59:43,639
like an if statement or block starting it has to\xa0\n
660
00:59:43,639 --> 00:59:49,219
you want. And the last thing has to be an else.\xa0\n
661
00:59:49,219 --> 00:59:55,039
else there. So anyways, I think that's all I'm\xa0\n
662
00:59:55,039 --> 00:59:58,789
they're pretty straightforward. Any condition can\xa0\n
663
00:59:58,789 --> 01:00:03,860
like you could have a really long chain\xa0\n
664
01:00:03,860 --> 01:00:07,190
you could have any condition like it doesn't\xa0\n
665
01:00:07,190 --> 01:00:11,420
value, you could also literally just type\xa0\n
666
01:00:14,599 --> 01:00:20,029
In this video, we're going to be kind of taking\xa0\n
667
01:00:20,030 --> 01:00:24,680
that we've already learned summarizing that,\xa0\n
668
01:00:24,679 --> 01:00:28,969
you guys really understand all of that. And we're\xa0\n
669
01:00:28,969 --> 01:00:34,309
how you can kind of add things within other things\xa0\n
670
01:00:34,309 --> 01:00:38,000
variables. And the way I'm going to do this\xa0\n
671
01:00:38,000 --> 01:00:42,380
it's going to do is it's going to ask the user to\xa0\n
672
01:00:42,380 --> 01:00:45,890
going to do certain things with that, we're going\xa0\n
673
01:00:45,889 --> 01:00:49,759
like on a roller coaster, like if you're 13 or\xa0\n
674
01:00:49,760 --> 01:00:53,600
going to do something like that. Okay, so I'm\xa0\n
675
01:00:53,599 --> 01:00:57,949
because we want to get the user's age. But um,\xa0\n
676
01:00:57,949 --> 01:01:03,469
going to print a line to the screen here. So\xa0\n
677
01:01:03,469 --> 01:01:11,359
and so print ln. And in this case, I will just\xa0\n
678
01:01:11,360 --> 01:01:16,730
it should, if I'm doing this correctly, make\xa0\n
679
01:01:16,730 --> 01:01:20,420
line. Okay, you'll you'll see when we do that in\xa0\n
680
01:01:20,420 --> 01:01:23,659
just going to kind of start typing, and we'll go\xa0\n
681
01:01:23,659 --> 01:01:29,809
and we're actually just going to convert this\xa0\n
682
01:01:29,809 --> 01:01:37,610
so using that parse into that I was talking about,\xa0\n
683
01:01:37,610 --> 01:01:44,300
I always forget how to do this integer dot\xa0\n
684
01:01:44,300 --> 01:01:49,039
so we're going to convert whatever they type\xa0\n
685
01:01:49,039 --> 01:01:57,079
to assume that they type in an integer. So we'll\xa0\n
686
01:01:57,079 --> 01:02:09,529
we will simply print System dot out dot print,\xa0\n
687
01:02:09,530 --> 01:02:14,750
if they're not older than 13, that must mean\xa0\n
688
01:02:14,750 --> 01:02:20,780
So in this case, we will simply print that they\xa0\n
689
01:02:20,780 --> 01:02:29,060
you cannot write exclamation point. Okay, pretty\xa0\n
690
01:02:29,059 --> 01:02:35,269
this work. So let's test it out. input your age\xa0\n
691
01:02:35,269 --> 01:02:42,170
input your age 43. You can ride awesome. Okay,\xa0\n
692
01:02:42,170 --> 01:02:46,880
what I'm going to do is I am going to add a elsif\xa0\n
693
01:02:46,880 --> 01:02:52,369
that we're looking at. So I'm going to say now I\xa0\n
694
01:02:52,369 --> 01:02:57,440
either an adult, a teenager, or just like younger\xa0\n
695
01:02:57,440 --> 01:03:01,820
call those? Whatever, younger than teenagers.\xa0\n
696
01:03:01,820 --> 01:03:09,559
I want to print you are an adult, okay? Now\xa0\n
697
01:03:09,559 --> 01:03:15,139
we want to check if they are less than 18. So or\xa0\n
698
01:03:15,139 --> 01:03:20,329
way, that's gonna make sense here in a second. So\xa0\n
699
01:03:20,329 --> 01:03:26,569
we know it's less than 18. So all we actually\xa0\n
700
01:03:26,570 --> 01:03:32,450
right? We're greater or older than or equal to 13?\xa0\n
701
01:03:32,449 --> 01:03:38,119
reason we don't have to check if they are, what\xa0\n
702
01:03:38,119 --> 01:03:43,039
is because we already know that they're gonna\xa0\n
703
01:03:43,039 --> 01:03:47,509
within that range. So I already butchered that\xa0\n
704
01:03:47,510 --> 01:03:56,360
dot print, ln. And in this case, we'll just say\xa0\n
705
01:03:56,360 --> 01:04:00,289
this last case, well, we know they're not older\xa0\n
706
01:04:00,289 --> 01:04:07,519
than or equal to 30. And that meaning they must\xa0\n
707
01:04:07,519 --> 01:04:14,030
adult, okay, like that. So let's test our program\xa0\n
708
01:04:14,030 --> 01:04:19,519
input an age of 14, we get you are a teenager.\xa0\n
709
01:04:19,519 --> 01:04:27,650
age of 19. Get you're an adult. And if we input an\xa0\n
710
01:04:27,650 --> 01:04:32,869
adult. Now, I want to show you what happens if\xa0\n
711
01:04:32,869 --> 01:04:38,690
do like negative 98? You are not a teenager or an\xa0\n
712
01:04:38,690 --> 01:04:43,550
that's not greater than or equal to 13. It's not\xa0\n
713
01:04:43,550 --> 01:04:49,820
a teenager or an adult. Okay. Now, that is pretty\xa0\n
714
01:04:49,820 --> 01:04:55,430
is how we can ask like another question or how we\xa0\n
715
01:04:55,429 --> 01:05:02,419
here is I want to say, if they're 18, and only\xa0\n
716
01:05:02,420 --> 01:05:07,369
What should the question be? I want to ask them\xa0\n
717
01:05:07,369 --> 01:05:12,619
going to do now exactly what I've done up here,\xa0\n
718
01:05:12,619 --> 01:05:16,279
So if this happens, we're going to do this and\xa0\n
719
01:05:16,280 --> 01:05:21,830
gonna say SC, or we'll say, string is Windows to\xa0\n
720
01:05:21,829 --> 01:05:30,110
guess Kazumi food Yeah, we'll say string. Food\xa0\n
721
01:05:30,110 --> 01:05:33,650
And what I'm going to do is I'm going to print\xa0\n
722
01:05:33,650 --> 01:05:41,840
just copy this in a second. And in this case, I'll\xa0\n
723
01:05:41,840 --> 01:05:45,800
do is I want to check what their favorite food is.\xa0\n
724
01:05:45,800 --> 01:05:50,810
I'll say mine too. Otherwise, we'll say that's\xa0\n
725
01:05:50,809 --> 01:05:59,000
we'll say if, and we have our conditioning here,\xa0\n
726
01:05:59,000 --> 01:06:11,000
we'll simply type pizza. Right? Then we will\xa0\n
727
01:06:11,000 --> 01:06:20,809
mine. Wow, inside of the coats, hopefully. Say\xa0\n
728
01:06:20,809 --> 01:06:29,029
we'll do is we'll simply type system, dot out dot\xa0\n
729
01:06:29,030 --> 01:06:34,760
Okay? So this is showing you now it looks a bit\xa0\n
730
01:06:34,760 --> 01:06:39,050
statements and else statements, we can do things\xa0\n
731
01:06:39,050 --> 01:06:45,110
that this works. So if I type, I'm 19. It's gonna\xa0\n
732
01:06:45,110 --> 01:06:50,840
let's try pizza, says mine too. Awesome. That's\xa0\n
733
01:06:50,840 --> 01:06:54,829
like for, it just tells me I'm not a teenager,\xa0\n
734
01:06:54,829 --> 01:06:59,389
happening inside of this if statement, or this\xa0\n
735
01:06:59,389 --> 01:07:04,069
And that allows us to do some neat things. And\xa0\n
736
01:07:04,070 --> 01:07:08,990
putting a statement inside of another statement,\xa0\n
737
01:07:08,989 --> 01:07:12,949
So I just wanted to show that to you. Because\xa0\n
738
01:07:12,949 --> 01:07:16,639
they don't understand that you're able to do that,\xa0\n
739
01:07:16,639 --> 01:07:21,170
again, if I want to ask another question, I could\xa0\n
740
01:07:24,469 --> 01:07:32,599
What is an array? Well, an array is a collection,\xa0\n
741
01:07:32,599 --> 01:07:37,579
rather than having like a variable equal to one,\xa0\n
742
01:07:37,579 --> 01:07:42,440
different values in there that you can index\xa0\n
743
01:07:42,440 --> 01:07:46,490
talking about them here, if you're a little bit\xa0\n
744
01:07:46,489 --> 01:07:50,839
you have to declare the type that you want your\xa0\n
745
01:07:50,840 --> 01:07:55,039
at least right now have to be the same type. So in\xa0\n
746
01:07:55,039 --> 01:07:59,539
And to declare that this is going to be an array,\xa0\n
747
01:07:59,539 --> 01:08:05,000
in square brackets, the name of your array in this\xa0\n
748
01:08:05,000 --> 01:08:10,639
and then in this case, you're going to say new\xa0\n
749
01:08:10,639 --> 01:08:15,980
brackets, you have to define how many elements or\xa0\n
750
01:08:15,980 --> 01:08:20,359
I'm just gonna say five. Okay, so you can\xa0\n
751
01:08:20,359 --> 01:08:25,939
just because we're not using new AR. But yeah,\xa0\n
752
01:08:25,939 --> 01:08:30,859
it to be, you type the type. So if I wanted to\xa0\n
753
01:08:30,859 --> 01:08:37,309
would have to be the same string like that. Okay,\xa0\n
754
01:08:37,310 --> 01:08:43,100
and then the type square brackets how\xa0\n
755
01:08:43,100 --> 01:08:48,020
there's another way to declare this, I'll show\xa0\n
756
01:08:48,020 --> 01:08:52,040
like you can't change this length. So you have to\xa0\n
757
01:08:52,039 --> 01:08:56,449
you know how many elements you want to have.\xa0\n
758
01:08:56,449 --> 01:09:01,159
zero, then there's no point in using it. You can't\xa0\n
759
01:09:01,159 --> 01:09:06,289
okay? And what it's going to do is it's going\xa0\n
760
01:09:06,289 --> 01:09:11,899
no, so they have no value, but they exist, like\xa0\n
761
01:09:11,899 --> 01:09:16,429
right now. Okay? Well, you can kind of think of it\xa0\n
762
01:09:16,430 --> 01:09:20,960
are old gonna hold something, but they're not yet\xa0\n
763
01:09:20,960 --> 01:09:25,520
So we're gonna keep the string array for now.\xa0\n
764
01:09:25,520 --> 01:09:31,520
and change values and print them out and see\xa0\n
765
01:09:31,520 --> 01:09:36,530
index things in an array and array is going to be\xa0\n
766
01:09:36,529 --> 01:09:40,609
so I'm just gonna type some stuff out and just\xa0\n
767
01:09:40,609 --> 01:09:52,729
have Hello. I need double quotes. Hi, Tim. Maybe I\xa0\n
768
01:09:52,729 --> 01:09:58,489
Now these are the five values in my string array.\xa0\n
769
01:09:58,489 --> 01:10:04,849
showing you an example. Now the way that we start\xa0\n
770
01:10:04,850 --> 01:10:09,350
this, every element in our array is going to have\xa0\n
771
01:10:09,350 --> 01:10:14,120
number that represents its position. So in this\xa0\n
772
01:10:14,119 --> 01:10:20,119
is position two, and this would be position five.\xa0\n
773
01:10:20,119 --> 01:10:24,170
position one, it would give me Hello. But the\xa0\n
774
01:10:24,170 --> 01:10:29,000
we actually start counting at zero, meaning\xa0\n
775
01:10:29,000 --> 01:10:36,140
actually going to be position zero. And that means\xa0\n
776
01:10:36,140 --> 01:10:40,640
this case, five, the last position in my array is\xa0\n
777
01:10:40,640 --> 01:10:45,619
four, so Joe would be position four. And these\xa0\n
778
01:10:45,619 --> 01:10:50,989
index one is high, index two is Tim. And this\xa0\n
779
01:10:50,989 --> 01:10:56,899
without having to know their value, we just know\xa0\n
780
01:10:56,899 --> 01:11:03,139
That's how we count in computers. Okay, so how can\xa0\n
781
01:11:03,140 --> 01:11:10,369
I'm going to create a variable and just say\xa0\n
782
01:11:10,369 --> 01:11:15,920
get like value two in my array. So first of all,\xa0\n
783
01:11:15,920 --> 01:11:21,199
we'll do that in a second. But how I would do that\xa0\n
784
01:11:21,199 --> 01:11:27,470
brackets and then in here, I put the position. So\xa0\n
785
01:11:27,470 --> 01:11:32,659
the first or second position I will see anyways,\xa0\n
786
01:11:32,659 --> 01:11:37,550
the second value in my array, because remember, we\xa0\n
787
01:11:37,550 --> 01:11:42,170
be zero, and the last value would be four. Now\xa0\n
788
01:11:42,170 --> 01:11:47,090
start adding things into my array. So the way that\xa0\n
789
01:11:47,090 --> 01:11:51,909
we've declared an array and we set it has length\xa0\n
790
01:11:51,909 --> 01:11:55,149
exists, or those buckets, there's not holding\xa0\n
791
01:11:55,149 --> 01:12:01,779
say new AR zero is equal to, and in this case,\xa0\n
792
01:12:02,500 --> 01:12:09,010
put our semicolon, there we go. We've just set\xa0\n
793
01:12:09,010 --> 01:12:14,289
Okay, so now if I copy this a few times, I can\xa0\n
794
01:12:14,289 --> 01:12:24,100
I did 012, and three, and here, I can just change\xa0\n
795
01:12:24,100 --> 01:12:29,320
And we can add one more, but we don't have to. So\xa0\n
796
01:12:29,319 --> 01:12:37,869
of it. And new AR four is equal to what we call it\xa0\n
797
01:12:37,869 --> 01:12:44,800
Okay, jus like that. Alright, so it may say string\xa0\n
798
01:12:44,800 --> 01:12:51,579
equal to Joe. So to print this out to the screen,\xa0\n
799
01:12:51,579 --> 01:12:57,760
this case, I will say x, and let's see what we\xa0\n
800
01:12:57,760 --> 01:13:04,270
these into the array. Now if I just comment this\xa0\n
801
01:13:04,270 --> 01:13:09,940
we do a new AR for let's see what we get, we get\xa0\n
802
01:13:09,939 --> 01:13:15,699
we initialize this array, we set it of a length of\xa0\n
803
01:13:15,699 --> 01:13:19,210
we've got five containers, five buckets, they're\xa0\n
804
01:13:19,208 --> 01:13:24,038
are yet. Alright. So if we haven't set a value\xa0\n
805
01:13:24,039 --> 01:13:27,880
well, we don't know what it is. So we're just\xa0\n
806
01:13:27,880 --> 01:13:34,329
right now. Okay. So yeah, so those are, that's\xa0\n
807
01:13:34,329 --> 01:13:38,050
I'm going to create another array and show you a\xa0\n
808
01:13:38,050 --> 01:13:44,050
gonna like statically type in numbers, okay,\xa0\n
809
01:13:44,050 --> 01:13:48,520
edge to save me from doing all these quotation\xa0\n
810
01:13:48,520 --> 01:13:53,350
to new it square brackets. Or actually, we don't\xa0\n
811
01:13:53,350 --> 01:13:58,720
we're just gonna put two curly braces. And in\xa0\n
812
01:13:58,720 --> 01:14:05,320
this case, this is now my number array. So I put\xa0\n
813
01:14:05,319 --> 01:14:12,819
354, six and six. Now again, just to recap, two\xa0\n
814
01:14:12,819 --> 01:14:18,159
Because that's where we start counting. And now,\xa0\n
815
01:14:18,159 --> 01:14:26,829
error, I'm going to say nums four, which should\xa0\n
816
01:14:26,829 --> 01:14:32,890
this has to be an int, my bad. index equals lumps\xa0\n
817
01:14:32,890 --> 01:14:37,450
value six. So that's another way to create an\xa0\n
818
01:14:37,449 --> 01:14:43,449
all of the numbers like that, okay. And obviously,\xa0\n
819
01:14:43,449 --> 01:14:49,809
we could do string we do float, we do double,\xa0\n
820
01:14:49,810 --> 01:14:59,500
equal to and then in here, like 2.0 3.0 There you\xa0\n
821
01:14:59,500 --> 01:15:05,319
well, you need But that works. Okay, we now have a\xa0\n
822
01:15:05,319 --> 01:15:12,849
one, we have 3.0. And yeah, so arrays can get\xa0\n
823
01:15:12,850 --> 01:15:17,829
thing to be using for a lot of example cases. But\xa0\n
824
01:15:17,829 --> 01:15:21,819
videos, I'm going to be talking about collections,\xa0\n
825
01:15:21,819 --> 01:15:26,409
things rather than like indexing elements like\xa0\n
826
01:15:26,409 --> 01:15:32,109
on those. But for now, I would just want to\xa0\n
827
01:15:35,579 --> 01:15:40,890
So in this video, I'm going to be talking about\xa0\n
828
01:15:40,890 --> 01:15:44,490
of every programming language. And\xa0\n
829
01:15:44,489 --> 01:15:49,920
I can almost guarantee you that any program you\xa0\n
830
01:15:49,920 --> 01:15:55,079
a for loop is allows us to kind of automate a\xa0\n
831
01:15:55,079 --> 01:15:59,640
typically when you use a for loop, you're using\xa0\n
832
01:15:59,640 --> 01:16:04,020
to do something or like a condition is going\xa0\n
833
01:16:04,020 --> 01:16:07,140
opposed to what we're going to talk about in\xa0\n
834
01:16:07,140 --> 01:16:10,800
you're not really sure how long it's going to go\xa0\n
835
01:16:10,800 --> 01:16:16,470
but we'll talk about that when we get to it.\xa0\n
836
01:16:16,470 --> 01:16:20,760
the for loop can really like solve for us,\xa0\n
837
01:16:20,760 --> 01:16:27,750
simple example. And you guys will see in a second\xa0\n
838
01:16:27,750 --> 01:16:30,659
that I want to add one, and then I want to add\xa0\n
839
01:16:31,170 --> 01:16:35,940
and four, and five and six, and like an infinite\xa0\n
840
01:16:35,939 --> 01:16:43,289
Well, we could do like x plus equals one, we could\xa0\n
841
01:16:43,289 --> 01:16:47,970
things to x. And we could just keep copying and\xa0\n
842
01:16:47,970 --> 01:16:52,860
that's terribly inefficient in terms of a typing\xa0\n
843
01:16:52,859 --> 01:16:56,819
what if every time we want the program, we want\xa0\n
844
01:16:56,819 --> 01:17:03,449
like a pattern like this to x? Well, then we would\xa0\n
845
01:17:03,449 --> 01:17:07,829
right, so this is where for loop can kind of come\xa0\n
846
01:17:07,829 --> 01:17:12,809
going to type it out, and then we will talk about\xa0\n
847
01:17:12,810 --> 01:17:17,970
here and in here, we're gonna put three things\xa0\n
848
01:17:17,970 --> 01:17:23,640
going to first start off by declaring a variable.\xa0\n
849
01:17:23,640 --> 01:17:28,619
zero, okay? Now this can be called whatever you\xa0\n
850
01:17:28,619 --> 01:17:34,199
x, but you know, let's just use AI. And then what\xa0\n
851
01:17:34,199 --> 01:17:39,389
a semicolon, and then the next thing you're gonna\xa0\n
852
01:17:39,390 --> 01:17:42,360
gonna do this and then talk about because it's\xa0\n
853
01:17:42,359 --> 01:17:50,829
all work together, less than or equal to 10. And\xa0\n
854
01:17:50,829 --> 01:17:56,409
actually, is I first started by declaring a\xa0\n
855
01:17:56,409 --> 01:18:00,460
we're going to do this while i is less than or\xa0\n
856
01:18:00,460 --> 01:18:06,369
So pretty much the way this works, is every time\xa0\n
857
01:18:06,369 --> 01:18:12,130
here, is gonna have one added to it. So this is\xa0\n
858
01:18:12,130 --> 01:18:16,390
the end of your for loop. So this is what you're\xa0\n
859
01:18:16,390 --> 01:18:23,829
here, every time you run the loop. Now this here\xa0\n
860
01:18:23,829 --> 01:18:28,449
many times a loop is gonna run. So in our case,\xa0\n
861
01:18:28,449 --> 01:18:34,119
than or equal to the value 10, meaning we're going\xa0\n
862
01:18:34,119 --> 01:18:38,890
we're going to run this loop, then we're going to\xa0\n
863
01:18:38,890 --> 01:18:42,640
we doing? We're adding one to AI, then we're gonna\xa0\n
864
01:18:42,640 --> 01:18:46,300
we're gonna say, well, is one less than equal\xa0\n
865
01:18:46,300 --> 01:18:49,960
through, and we're gonna continue looping through\xa0\n
866
01:18:49,960 --> 01:18:56,350
to i, it's equal to 1111. Well, that's greater\xa0\n
867
01:18:56,350 --> 01:19:01,300
guys will see when I start printing stuff to the\xa0\n
868
01:19:01,300 --> 01:19:06,850
was a decent explanation of the way to do this.\xa0\n
869
01:19:06,850 --> 01:19:09,850
out here and I'm going to tell you right, now\xa0\n
870
01:19:09,850 --> 01:19:14,650
at zero. So the first loop here, where I come\xa0\n
871
01:19:14,649 --> 01:19:18,909
next loop, we come up, we add one, two, I check\xa0\n
872
01:19:18,909 --> 01:19:25,359
We're at one, and we're going to print from zero\xa0\n
873
01:19:25,359 --> 01:19:31,630
the way up to 10. Okay, that's how the for loop\xa0\n
874
01:19:31,630 --> 01:19:38,289
little curly braces 10 times, or 11 times in\xa0\n
875
01:19:38,291 --> 01:19:42,041
we can change this increment, we can change this\xa0\n
876
01:19:42,041 --> 01:19:48,371
do in this for loop. So here we say for int i\xa0\n
877
01:19:48,369 --> 01:19:52,479
and I can start at the value five and now we're\xa0\n
878
01:19:52,479 --> 01:19:59,799
looping 123456 times, right? We're printing six\xa0\n
879
01:19:59,800 --> 01:20:04,960
that If I tried to do something like i equals\xa0\n
880
01:20:04,960 --> 01:20:09,670
the screen. And that's because 11, well, that's\xa0\n
881
01:20:09,670 --> 01:20:14,649
even run one time, right. So let's go back, and\xa0\n
882
01:20:14,649 --> 01:20:21,489
can do in terms of incrementing. So to increment\xa0\n
883
01:20:21,489 --> 01:20:24,460
we want. So in this case, if I do five, we started\xa0\n
884
01:20:25,840 --> 01:20:31,000
add five again. So we get 05, and 10. And you can\xa0\n
885
01:20:31,000 --> 01:20:36,039
same thing here with the condition. These can\xa0\n
886
01:20:36,039 --> 01:20:41,739
tell you that. But if I do something like int\xa0\n
887
01:20:41,739 --> 01:20:46,569
right, and we can add that integer to it, we\xa0\n
888
01:20:46,569 --> 01:20:50,799
equal to this could be greater than this can be\xa0\n
889
01:20:50,800 --> 01:20:56,710
quickly go over one thing that a lot of people\xa0\n
890
01:20:56,710 --> 01:21:00,670
when we're going to stop and when we're going to\xa0\n
891
01:21:00,670 --> 01:21:05,649
this means we're going to start at this value. And\xa0\n
892
01:21:05,649 --> 01:21:13,359
to stop but include 10, meaning that I will hit\xa0\n
893
01:21:13,359 --> 01:21:18,369
if I remove this equal sign, this is only going\xa0\n
894
01:21:18,369 --> 01:21:23,500
that if I is 10, well, 10 is not less than 10. So\xa0\n
895
01:21:23,500 --> 01:21:28,899
you can see we only get up to the value nine. Now\xa0\n
896
01:21:28,899 --> 01:21:33,609
we typically want to do with loops is we want to\xa0\n
897
01:21:33,609 --> 01:21:38,109
typically that data is in the form of an array.\xa0\n
898
01:21:38,109 --> 01:21:43,719
I'm going to create an array, so an integer\xa0\n
899
01:21:43,720 --> 01:21:50,530
just give it some values here. So like 157345,\xa0\n
900
01:21:50,529 --> 01:21:56,409
what do I want to do? If or how am I going to do\xa0\n
901
01:21:56,409 --> 01:22:00,340
at look at these values, and maybe check them\xa0\n
902
01:22:00,340 --> 01:22:05,800
or something like that? Well, the way that I can\xa0\n
903
01:22:05,800 --> 01:22:14,650
is I could count the length of the reg and say,\xa0\n
904
01:22:14,649 --> 01:22:19,779
than six year. But a more useful way to do this\xa0\n
905
01:22:19,779 --> 01:22:25,509
way that I can do that is just to do a arc dot\xa0\n
906
01:22:25,510 --> 01:22:31,030
sorry. So we'll just do this in this way, say the\xa0\n
907
01:22:31,029 --> 01:22:35,469
them in an array, we don't know how many elements\xa0\n
908
01:22:35,470 --> 01:22:40,180
length so that we can change this loop and this\xa0\n
909
01:22:40,180 --> 01:22:45,909
Because we're just simply getting the length of\xa0\n
910
01:22:45,909 --> 01:22:50,739
you guys realized this would cause us an issue.\xa0\n
911
01:22:50,739 --> 01:22:55,689
array, right? But it's going to allow us to get i\xa0\n
912
01:22:55,689 --> 01:23:02,859
array. Now what happens if I try to do this arr\xa0\n
913
01:23:02,859 --> 01:23:07,329
that that will actually crash our program. And\xa0\n
914
01:23:07,329 --> 01:23:11,680
our last element in the array is actually going\xa0\n
915
01:23:11,680 --> 01:23:18,039
all the way to the length minus one, which is\xa0\n
916
01:23:18,039 --> 01:23:22,810
what I'm going to do now, is I'm just going to\xa0\n
917
01:23:22,810 --> 01:23:27,490
I'm just gonna say if the value is equal to five,\xa0\n
918
01:23:27,489 --> 01:23:35,769
I'm gonna say if arr index i is equal to the value\xa0\n
919
01:23:35,770 --> 01:23:44,020
dot out dot print, ln, I just realized this comma\xa0\n
920
01:23:44,020 --> 01:23:47,800
to print the value. So in this case, we could\xa0\n
921
01:23:47,800 --> 01:23:50,860
or we could just type five because we know\xa0\n
922
01:23:50,859 --> 01:23:58,089
do found a five exclamation point, okay, that's\xa0\n
923
01:23:58,090 --> 01:24:03,610
reason this is gonna work is because we're looping\xa0\n
924
01:24:03,609 --> 01:24:07,719
but not including the length of the array, make\xa0\n
925
01:24:07,720 --> 01:24:11,440
gonna get a crash, okay? So that way, we're going\xa0\n
926
01:24:11,439 --> 01:24:15,250
we're going to check its value. And then if we\xa0\n
927
01:24:15,250 --> 01:24:20,710
if this works. found five and found a five. Now\xa0\n
928
01:24:20,710 --> 01:24:27,670
I found this five, I could say found a five at\xa0\n
929
01:24:27,670 --> 01:24:31,369
can put pi. And what this is going to do is it's\xa0\n
930
01:24:31,369 --> 01:24:35,989
into a string for us and print it out with this\xa0\n
931
01:24:35,989 --> 01:24:38,689
so they don't get smushed together. But it says\xa0\n
932
01:24:38,689 --> 01:24:45,169
index five and we know this is true. Index\xa0\n
933
01:24:45,170 --> 01:24:50,420
a really simple way that we can loop through\xa0\n
934
01:24:54,069 --> 01:24:58,090
Well, I'm going to be showing you a different kind\xa0\n
935
01:24:58,090 --> 01:25:03,039
this is going to allow us to loop through the\xa0\n
936
01:25:03,039 --> 01:25:07,630
and do something with those elements, I'm also\xa0\n
937
01:25:07,630 --> 01:25:12,940
out of the loop at certain points. So if the\xa0\n
938
01:25:12,939 --> 01:25:16,779
get out of the loop the way that we can do that,\xa0\n
939
01:25:16,779 --> 01:25:23,349
of where we use loops. So let's go ahead and get\xa0\n
940
01:25:23,350 --> 01:25:30,460
here one's name names, and one is named AR, I just\xa0\n
941
01:25:30,460 --> 01:25:34,960
for right now. Okay, so what I first want to do\xa0\n
942
01:25:34,960 --> 01:25:40,899
and the way I did that was by having a variable\xa0\n
943
01:25:40,899 --> 01:25:48,159
greater than the length of the list? And then once\xa0\n
944
01:25:48,159 --> 01:25:53,079
right? Okay. So an easier way to do this, is to\xa0\n
945
01:25:53,079 --> 01:25:59,319
the same exact syntax, except in these brackets,\xa0\n
946
01:25:59,319 --> 01:26:03,699
I'm going to do if I want to loop through every\xa0\n
947
01:26:03,699 --> 01:26:12,189
this, I can say for element colon arr. Now what\xa0\n
948
01:26:12,189 --> 01:26:17,079
sorry, string element, or I can't say string\xa0\n
949
01:26:17,079 --> 01:26:24,789
in our array. So what I'm doing now is I'm saying\xa0\n
950
01:26:24,789 --> 01:26:29,500
what we're going to do is we're going to declare a\xa0\n
951
01:26:29,500 --> 01:26:36,189
equal to the next element in our array. So in this\xa0\n
952
01:26:36,189 --> 01:26:39,639
equal to one, and then elements going to be equal\xa0\n
953
01:26:39,640 --> 01:26:43,360
and then three, and then four, and then five.\xa0\n
954
01:26:43,359 --> 01:26:48,489
like print out the element, or look at certain\xa0\n
955
01:26:48,489 --> 01:26:53,170
like a counter variable i and then index all of\xa0\n
956
01:26:53,170 --> 01:26:56,350
know the length of the array, or we don't want\xa0\n
957
01:26:56,350 --> 01:27:03,340
going to go from start to end. Okay. Now, I'm\xa0\n
958
01:27:03,340 --> 01:27:09,140
example to really understand this. But the first\xa0\n
959
01:27:09,140 --> 01:27:13,940
out all these elements to show you that is indeed\xa0\n
960
01:27:13,939 --> 01:27:18,589
okay. And we'll just print this to the screen and\xa0\n
961
01:27:18,590 --> 01:27:24,170
157345, right, starting at the beginning going\xa0\n
962
01:27:24,170 --> 01:27:30,470
again, we're just grabbing the elements in order,\xa0\n
963
01:27:30,470 --> 01:27:36,800
a lot of times when you want to do with this is\xa0\n
964
01:27:36,800 --> 01:27:41,449
want the index as well. So you want the element\xa0\n
965
01:27:41,449 --> 01:27:45,019
we used in the last video where we just have a\xa0\n
966
01:27:45,020 --> 01:27:51,710
and the element because we can do like arr of\xa0\n
967
01:27:51,710 --> 01:27:57,500
typically do this is with like an outside counter\xa0\n
968
01:27:57,500 --> 01:28:01,039
you how this works. So what we're gonna start\xa0\n
969
01:28:01,039 --> 01:28:07,819
int count equals zero. And then within this loop,\xa0\n
970
01:28:07,819 --> 01:28:13,219
every time that we run the loop, we're adding\xa0\n
971
01:28:13,220 --> 01:28:19,159
the index of the element. So if I print out the\xa0\n
972
01:28:19,159 --> 01:28:25,430
space plus our count, you can see that this is\xa0\n
973
01:28:25,430 --> 01:28:30,320
here says one is that index 05 index one, and it\xa0\n
974
01:28:30,319 --> 01:28:33,769
us. And that's a really easy way to do that.\xa0\n
975
01:28:33,770 --> 01:28:37,160
sense for this example case, but I just wanted\xa0\n
976
01:28:37,159 --> 01:28:42,139
where you want both the element and the index,\xa0\n
977
01:28:42,140 --> 01:28:47,360
this with this colon. Okay. So again, when you're\xa0\n
978
01:28:47,359 --> 01:28:55,159
because it's going through for each element in\xa0\n
979
01:28:55,159 --> 01:29:01,550
so the next thing that I want to do is I want\xa0\n
980
01:29:01,550 --> 01:29:08,750
for loop. So right here, for example, we have a,\xa0\n
981
01:29:08,750 --> 01:29:12,350
right, like all these elements are null,\xa0\n
982
01:29:12,350 --> 01:29:15,710
that we would go about doing this, and this is\xa0\n
983
01:29:15,710 --> 01:29:22,640
while I'm showing you this is we create a variable\xa0\n
984
01:29:22,640 --> 01:29:29,450
well, i is less than and then names dot length,\xa0\n
985
01:29:29,449 --> 01:29:33,649
simply add one to it. So this is the exact same\xa0\n
986
01:29:33,649 --> 01:29:38,359
how we can actually add the elements because it's\xa0\n
987
01:29:38,359 --> 01:29:44,539
here is I'm actually going to use the scanner to\xa0\n
988
01:29:44,539 --> 01:29:55,789
user. So I'm just going to say scanner SC equals\xa0\n
989
01:29:55,789 --> 01:30:00,590
and actually think I should probably not declare\xa0\n
990
01:30:00,590 --> 01:30:12,289
just going to use the scanner, right? So we'll\xa0\n
991
01:30:12,289 --> 01:30:17,390
this. And this way, every time we run the loop,\xa0\n
992
01:30:17,390 --> 01:30:23,930
know what, let's also just print out here, system,\xa0\n
993
01:30:23,930 --> 01:30:30,110
I should let us do print not ln, we'll say, input\xa0\n
994
01:30:30,109 --> 01:30:33,319
Okay, so input, we're getting input. And now\xa0\n
995
01:30:33,319 --> 01:30:39,439
user's input into our array. So how can I do this?\xa0\n
996
01:30:39,439 --> 01:30:47,089
is equal to input, right? So we're just declaring\xa0\n
997
01:30:47,090 --> 01:30:53,180
so whatever value by well, that value in the list\xa0\n
998
01:30:53,180 --> 01:30:57,260
an array I'm going to use to Python is going to be\xa0\n
999
01:30:57,260 --> 01:31:02,449
to print out the entire array, what we can do is\xa0\n
1000
01:31:02,449 --> 01:31:07,579
and then this time, it's going to be a for each\xa0\n
1001
01:31:09,170 --> 01:31:19,579
string, and, and names, okay, then we will simply\xa0\n
1002
01:31:19,579 --> 01:31:24,649
print every value of n. Okay, so let's two good\xa0\n
1003
01:31:24,649 --> 01:31:29,839
everything's working. So we run this input, I'm\xa0\n
1004
01:31:29,840 --> 01:31:38,900
that, Tim, Bob. Joe, Bill. And then there we go.\xa0\n
1005
01:31:38,899 --> 01:31:47,899
Bob, Joe. And Bill. Awesome. There we go. So that\xa0\n
1006
01:31:47,899 --> 01:31:53,569
so now what I want to show you guys is how we can\xa0\n
1007
01:31:53,569 --> 01:31:56,929
and we're going through, and we're doing\xa0\n
1008
01:31:56,930 --> 01:32:01,310
where are like, so the loop is gonna keep\xa0\n
1009
01:32:01,310 --> 01:32:07,789
or whatnot. Okay, then we want to break out of it.\xa0\n
1010
01:32:07,789 --> 01:32:13,939
it in the middle of looping? Well, there is this\xa0\n
1011
01:32:13,939 --> 01:32:20,960
does, is whenever this is encountered inside of a\xa0\n
1012
01:32:20,960 --> 01:32:25,640
case, what would happen is, since I have break\xa0\n
1013
01:32:25,640 --> 01:32:30,800
then we just break. And this would only happen one\xa0\n
1014
01:32:30,800 --> 01:32:37,220
stuff said, this loop would only happen once. Now,\xa0\n
1015
01:32:37,220 --> 01:32:42,860
how we can break out based on like a certain\xa0\n
1016
01:32:42,859 --> 01:32:47,539
word end. Or what do you call it? The word Tim,\xa0\n
1017
01:32:47,539 --> 01:32:50,630
if we encounter like the word Tim, while\xa0\n
1018
01:32:50,630 --> 01:32:54,380
then we just want to break out like we don't want\xa0\n
1019
01:32:54,380 --> 01:32:57,980
break out. So the way that I can do this right now\xa0\n
1020
01:32:57,979 --> 01:33:02,479
but we'll break after Tim Okay, so what I'm gonna\xa0\n
1021
01:33:02,479 --> 01:33:09,349
and equals equals or not equals equals dot equals,\xa0\n
1022
01:33:09,350 --> 01:33:15,530
in here, then what we're going to do is we're\xa0\n
1023
01:33:15,529 --> 01:33:20,449
we encounter Tim, we're simply breaking into the\xa0\n
1024
01:33:20,449 --> 01:33:26,659
the names. So if I run this string, this console\xa0\n
1025
01:33:26,659 --> 01:33:33,019
name. And then we say, Tim, and I'll just show you\xa0\n
1026
01:33:33,020 --> 01:33:39,230
we get Hello, name and Tim. And these other two\xa0\n
1027
01:33:39,229 --> 01:33:45,289
we hit m, and n is equal to 10, we simply break,\xa0\n
1028
01:33:45,289 --> 01:33:49,189
a really easy way to just break out of the loop.\xa0\n
1029
01:33:49,189 --> 01:33:53,960
we do in what do you call it the next video.\xa0\n
1030
01:33:53,960 --> 01:33:59,359
to be using a lot like you only use this if you\xa0\n
1031
01:33:59,359 --> 01:34:05,479
conditions work the way they should, and have the\xa0\n
1032
01:34:05,479 --> 01:34:09,829
you know what I mean? So just try not to use this\xa0\n
1033
01:34:09,829 --> 01:34:14,600
with using it, people just are frowned upon it in\xa0\n
1034
01:34:18,479 --> 01:34:22,709
We're gonna be talking about while loops. Now,\xa0\n
1035
01:34:22,710 --> 01:34:27,329
anything you do with the for loop, you can\xa0\n
1036
01:34:27,329 --> 01:34:31,559
they do have different use cases in terms of\xa0\n
1037
01:34:31,560 --> 01:34:35,520
anything you do with the for loop, you can do with\xa0\n
1038
01:34:35,520 --> 01:34:39,390
you can do with the for loop, they're completely\xa0\n
1039
01:34:39,390 --> 01:34:44,400
them in programming, you'd still be able to do\xa0\n
1040
01:34:44,399 --> 01:34:50,129
nice to code, that's the right word for it, or\xa0\n
1041
01:34:50,130 --> 01:34:54,630
loop is going to work when you typically don't\xa0\n
1042
01:34:54,630 --> 01:34:59,220
something. So it's kind of like a question.\xa0\n
1043
01:34:59,220 --> 01:35:04,230
condition. But you're not really sure like, if a\xa0\n
1044
01:35:04,229 --> 01:35:08,519
it a set amount of times a while loop is it could\xa0\n
1045
01:35:08,520 --> 01:35:13,170
okay, something like that. So what we're gonna do\xa0\n
1046
01:35:13,170 --> 01:35:17,460
one up, and then we'll just talk about exactly\xa0\n
1047
01:35:17,460 --> 01:35:22,829
while loop to do is I want it to just continually\xa0\n
1048
01:35:22,829 --> 01:35:27,659
me like a certain word or like one or two words.\xa0\n
1049
01:35:27,659 --> 01:35:36,510
gonna say, let's see, maybe just get an answer\xa0\n
1050
01:35:36,510 --> 01:35:41,670
like this. Okay? And what I'm gonna do is I'm\xa0\n
1051
01:35:41,670 --> 01:35:48,600
the number 10. Okay, so all I can do this as you\xa0\n
1052
01:35:48,600 --> 01:35:53,430
these brackets is going to be your condition. Now,\xa0\n
1053
01:35:53,430 --> 01:35:59,039
the first few videos, because they go a lot with\xa0\n
1054
01:35:59,039 --> 01:36:04,079
this condition is true, then we're going to run\xa0\n
1055
01:36:04,079 --> 01:36:15,809
x does not equal 10. Okay. Yeah, exactly. That's\xa0\n
1056
01:36:15,810 --> 01:36:21,090
continue to do this. Otherwise, we will continue\xa0\n
1057
01:36:21,090 --> 01:36:27,630
to get the INT in here, because every time that we\xa0\n
1058
01:36:27,630 --> 01:36:33,029
in this case, we already have X, fine, we just do\xa0\n
1059
01:36:33,029 --> 01:36:40,409
10, I'm simply going to tell them like type in 10.\xa0\n
1060
01:36:40,409 --> 01:36:46,889
I will just say, type 10 dot, dot, dot. And\xa0\n
1061
01:36:46,890 --> 01:36:53,310
because I like to do this, we'll just do system\xa0\n
1062
01:36:53,310 --> 01:36:59,910
say type a number. Cesar knows what we're looking\xa0\n
1063
01:36:59,909 --> 01:37:06,569
print this here. And it should just be print, not\xa0\n
1064
01:37:06,569 --> 01:37:09,779
the way this is gonna work is we're just\xa0\n
1065
01:37:09,779 --> 01:37:15,059
this until eventually the user types in\xa0\n
1066
01:37:15,060 --> 01:37:21,060
and we will not do this anymore. So let's run this\xa0\n
1067
01:37:21,060 --> 01:37:26,430
data, type a number, type five doesn't work, type\xa0\n
1068
01:37:26,430 --> 01:37:31,409
and it no longer asked us for that number. Now,\xa0\n
1069
01:37:31,409 --> 01:37:35,639
this condition is true. Do everything that's\xa0\n
1070
01:37:35,640 --> 01:37:40,829
about while loops. Now again, like we can what\xa0\n
1071
01:37:40,829 --> 01:37:44,609
loops with while loops, because we can also count\xa0\n
1072
01:37:44,609 --> 01:37:49,439
I could do something like int count equals zero.\xa0\n
1073
01:37:49,439 --> 01:37:54,629
just say count plus plus. And then maybe at the\xa0\n
1074
01:37:54,630 --> 01:37:59,159
how many times they messed up. Okay, what am\xa0\n
1075
01:37:59,159 --> 01:38:13,139
And in this case, we'll just say you tried, tired,\xa0\n
1076
01:38:13,140 --> 01:38:19,590
make sure we add a little space here. Alright, so\xa0\n
1077
01:38:19,590 --> 01:38:25,739
you tried three times until like, eventually, you\xa0\n
1078
01:38:25,739 --> 01:38:30,179
to do stuff with while loops. Now, you guys\xa0\n
1079
01:38:30,840 --> 01:38:36,510
these lines are repeated up here. So I have this\xa0\n
1080
01:38:36,510 --> 01:38:41,159
this without repeating those lines? Because\xa0\n
1081
01:38:41,159 --> 01:38:45,059
wanted to ask a ton of different questions and\xa0\n
1082
01:38:45,060 --> 01:38:50,220
the same section of code appearing multiple times.\xa0\n
1083
01:38:50,220 --> 01:38:54,930
loop. So what I'm going to do is I'm just going\xa0\n
1084
01:38:54,930 --> 01:39:00,450
a do while loop. And it's pretty much what it says\xa0\n
1085
01:39:00,449 --> 01:39:06,000
And you'll see how it works in just a second.\xa0\n
1086
01:39:06,000 --> 01:39:12,869
and now everything in this brackets is what is\xa0\n
1087
01:39:12,869 --> 01:39:19,349
down here is true. So the condition here is going\xa0\n
1088
01:39:19,350 --> 01:39:24,030
going to do everything in here. So now you can see\xa0\n
1089
01:39:24,029 --> 01:39:27,989
I'm going to simply do is I'm going to take this,\xa0\n
1090
01:39:27,989 --> 01:39:32,399
So we're not going to redefine that every time.\xa0\n
1091
01:39:32,399 --> 01:39:40,589
this is going to allow us to do now is x does not\xa0\n
1092
01:39:40,590 --> 01:39:47,940
do this. int x and then x. Okay, perfect. There\xa0\n
1093
01:39:47,939 --> 01:39:53,399
But what this is going to allow us to do is we're\xa0\n
1094
01:39:53,399 --> 01:39:58,079
this is going to happen once because we're going\xa0\n
1095
01:39:58,079 --> 01:40:01,800
So we're automatically going to do this once which\xa0\n
1096
01:40:01,800 --> 01:40:07,710
down below. So we do that. And then we check the\xa0\n
1097
01:40:07,710 --> 01:40:12,420
And if it's not, then we will break. So we can\xa0\n
1098
01:40:12,420 --> 01:40:19,289
let's do five, let's do negative 00. Number, okay,\xa0\n
1099
01:40:19,289 --> 01:40:25,140
and everything is working fine. And that\xa0\n
1100
01:40:25,140 --> 01:40:29,430
if you wanted to set one up to look like a for\xa0\n
1101
01:40:29,430 --> 01:40:34,920
variable in this case, say like index equals zero,\xa0\n
1102
01:40:34,920 --> 01:40:43,230
and you say, x is less than or equal to 10. And\xa0\n
1103
01:40:43,229 --> 01:40:48,389
or plus equals two, or whatever value you want to\xa0\n
1104
01:40:48,390 --> 01:40:52,079
do in the for loop underneath your increment.\xa0\n
1105
01:40:52,079 --> 01:40:55,319
put it at the end. So at the end of the loop,\xa0\n
1106
01:40:58,619 --> 01:41:05,039
Now in this video, I'm going to be talking about\xa0\n
1107
01:41:05,041 --> 01:41:10,650
something known as the collection interface from\xa0\n
1108
01:41:10,649 --> 01:41:16,109
correct me if that's wrong, but I think that's\xa0\n
1109
01:41:16,109 --> 01:41:21,119
I'm just going to talk about really the basics\xa0\n
1110
01:41:21,119 --> 01:41:26,489
and lists. I know, I'm probably gonna get some\xa0\n
1111
01:41:26,489 --> 01:41:30,840
didn't talk about a lot of this, you didn't. But\xa0\n
1112
01:41:30,840 --> 01:41:34,949
Because it's very difficult to understand, if\xa0\n
1113
01:41:34,949 --> 01:41:40,439
which in our case, we don't. So I'm just going to\xa0\n
1114
01:41:40,439 --> 01:41:45,960
in a very basic standard implementation of them.\xa0\n
1115
01:41:45,960 --> 01:41:49,980
you're programming stuff, like a lot of Java\xa0\n
1116
01:41:49,979 --> 01:41:55,529
these, because they're really complicated.\xa0\n
1117
01:41:55,529 --> 01:42:01,229
things. So for example, with an array, what I\xa0\n
1118
01:42:01,229 --> 01:42:05,519
had to set the size of the array, like you had to\xa0\n
1119
01:42:05,520 --> 01:42:11,340
to do that with a set or with a list. And that's\xa0\n
1120
01:42:11,340 --> 01:42:15,119
we're gonna be adding things into per se a list or\xa0\n
1121
01:42:15,119 --> 01:42:21,960
be adding. So we can't define like an array of\xa0\n
1122
01:42:21,960 --> 01:42:25,590
actually just get started, we're gonna talk about\xa0\n
1123
01:42:25,590 --> 01:42:30,029
just gonna create a set, and I'm just gonna type\xa0\n
1124
01:42:30,029 --> 01:42:43,889
doing, I'm just going to call this set t equal\xa0\n
1125
01:42:43,890 --> 01:42:47,730
already probably looks confusing. And if you're\xa0\n
1126
01:42:47,729 --> 01:42:52,379
lines. Now, what we should do to get rid of these\xa0\n
1127
01:42:52,380 --> 01:42:58,289
click Import set by like clicking on whatever it\xa0\n
1128
01:42:58,291 --> 01:43:03,811
this Id just literally type import Java dot util\xa0\n
1129
01:43:03,810 --> 01:43:10,701
click on it and import it, just because this isn't\xa0\n
1130
01:43:10,699 --> 01:43:17,300
Alright, so we have a set. Now what is a set?\xa0\n
1131
01:43:17,300 --> 01:43:24,770
unordered elements that are unique, meaning that a\xa0\n
1132
01:43:24,770 --> 01:43:29,210
doesn't know where that element exists. So you can\xa0\n
1133
01:43:29,210 --> 01:43:34,340
and you kind of just throw things into it. And\xa0\n
1134
01:43:34,340 --> 01:43:40,130
knows that they exist there. Now you also have to\xa0\n
1135
01:43:40,130 --> 01:43:45,409
example, I've created this integer set. And this\xa0\n
1136
01:43:45,409 --> 01:43:49,939
set. In these little like greater than sign\xa0\n
1137
01:43:49,939 --> 01:43:56,210
if you're talking HTML type integer, and I have\xa0\n
1138
01:43:56,210 --> 01:44:01,310
hash set. Now you don't have to understand what a\xa0\n
1139
01:44:01,310 --> 01:44:06,260
implementation of a set. And then same thing, the\xa0\n
1140
01:44:06,260 --> 01:44:11,329
Now inside of these brackets, if you had another\xa0\n
1141
01:44:11,329 --> 01:44:18,649
called like W, I could put w in here. And assuming\xa0\n
1142
01:44:18,649 --> 01:44:22,819
of the elements from W and start with that and\xa0\n
1143
01:44:22,819 --> 01:44:27,979
Okay. So to add things to set, I'm just gonna\xa0\n
1144
01:44:27,979 --> 01:44:32,750
You simply type dot add, so I'm going to say T\xa0\n
1145
01:44:32,750 --> 01:44:38,479
And we'll just copy this and we'll add like a few\xa0\n
1146
01:44:38,479 --> 01:44:44,869
seven, and what five again, and add nine. Okay?\xa0\n
1147
01:44:44,869 --> 01:44:50,119
this set out to show you what it looks like. Now\xa0\n
1148
01:44:50,119 --> 01:44:55,550
elements. Okay, so let's print this out. And you\xa0\n
1149
01:44:55,550 --> 01:45:01,340
notice that this odd right here actually didn't do\xa0\n
1150
01:45:01,340 --> 01:45:07,279
a five in our set, when we try to add another five\xa0\n
1151
01:45:07,279 --> 01:45:12,679
and it just doesn't add it. Alright, now I'm gonna\xa0\n
1152
01:45:12,680 --> 01:45:19,520
negative negative zero, negative eight, alright\xa0\n
1153
01:45:19,520 --> 01:45:25,440
have any specific order. Now, see, when I printed\xa0\n
1154
01:45:25,439 --> 01:45:28,589
so you think that should be the order that we\xa0\n
1155
01:45:28,590 --> 01:45:34,590
or something like that. That doesn't happen with a\xa0\n
1156
01:45:34,590 --> 01:45:40,920
because again, we're just a bubble, we just know\xa0\n
1157
01:45:40,920 --> 01:45:47,609
or how many times they exist, we just care if they\xa0\n
1158
01:45:47,609 --> 01:45:51,329
and this is typically something you want\xa0\n
1159
01:45:51,329 --> 01:45:57,029
checking if something exists, that's why you use a\xa0\n
1160
01:45:57,029 --> 01:46:03,329
named contains, and then any element in here that\xa0\n
1161
01:46:03,329 --> 01:46:09,090
is contained in the set, and it's going to be able\xa0\n
1162
01:46:09,090 --> 01:46:14,579
explain to you why sets are so fast. But just know\xa0\n
1163
01:46:14,579 --> 01:46:20,789
set, you can do that very quickly, like very fast,\xa0\n
1164
01:46:20,789 --> 01:46:25,079
the set is, the set could be 2 million elements,\xa0\n
1165
01:46:25,079 --> 01:46:30,300
same amount of time to look if something exists\xa0\n
1166
01:46:30,300 --> 01:46:34,980
removing things from the set that happens almost\xa0\n
1167
01:46:34,979 --> 01:46:38,909
the array gets, the longer it's going to take us\xa0\n
1168
01:46:38,909 --> 01:46:42,720
just, we have to understand that. So what I'm\xa0\n
1169
01:46:42,720 --> 01:46:48,930
call Boolean, x is equal to this. And what I'm\xa0\n
1170
01:46:48,930 --> 01:46:55,800
x. Now let's see if that is contained. And in\xa0\n
1171
01:46:55,800 --> 01:47:01,440
if I do something like zero, then obviously we\xa0\n
1172
01:47:01,439 --> 01:47:08,759
we can type T dot remove, or set name dot remove,\xa0\n
1173
01:47:08,760 --> 01:47:13,440
remove. So in this case, we want to remove like\xa0\n
1174
01:47:13,439 --> 01:47:19,139
print my set, so in this case, t, which get five,\xa0\n
1175
01:47:19,140 --> 01:47:25,590
those are kind of like the standard operations,\xa0\n
1176
01:47:25,590 --> 01:47:30,150
okay, so there's one more, or there's a few more,\xa0\n
1177
01:47:30,149 --> 01:47:35,670
clear an entire set by just doing dot clear. So\xa0\n
1178
01:47:35,670 --> 01:47:42,970
To see if a set is empty, you can do.is empty, and\xa0\n
1179
01:47:42,970 --> 01:47:48,490
or not, to get the length of the set, you can do\xa0\n
1180
01:47:48,489 --> 01:47:58,090
so in this case, value, size, change this to an\xa0\n
1181
01:47:58,090 --> 01:48:02,739
three. So like, again, if we had nothing in there,\xa0\n
1182
01:48:02,739 --> 01:48:08,949
kind of like similar in the sense that you can\xa0\n
1183
01:48:08,949 --> 01:48:15,460
a hash set. A hash set is like the standard set.\xa0\n
1184
01:48:15,460 --> 01:48:24,369
to you. Now they also have a tree set. And we also\xa0\n
1185
01:48:24,369 --> 01:48:28,599
things, they're gonna pop up here, I'm not really\xa0\n
1186
01:48:28,600 --> 01:48:34,060
gonna kind of show you the way a tree set works.\xa0\n
1187
01:48:34,060 --> 01:48:39,789
you can only have the or a hash set, sorry that\xa0\n
1188
01:48:39,789 --> 01:48:44,199
actually ordered and they're ordered in a tree\xa0\n
1189
01:48:44,199 --> 01:48:48,399
this means just know that it's like it shows\xa0\n
1190
01:48:48,399 --> 01:48:54,729
just want to read this error. Tree set cannot be\xa0\n
1191
01:48:54,729 --> 01:49:01,599
well, let's just try this. That still worked.\xa0\n
1192
01:49:01,600 --> 01:49:06,880
me there. But Teresa is going to actually\xa0\n
1193
01:49:06,880 --> 01:49:11,500
you can see that we actually have an order\xa0\n
1194
01:49:11,500 --> 01:49:19,029
and seven. Now like arrays, like we can't just\xa0\n
1195
01:49:19,029 --> 01:49:24,550
like that doesn't work doing that, like we were\xa0\n
1196
01:49:24,550 --> 01:49:31,180
out, or when we look through the set, it maintains\xa0\n
1197
01:49:31,180 --> 01:49:37,270
really explain to you. Now linked hash sets are\xa0\n
1198
01:49:37,270 --> 01:49:43,630
to import this up there. It's linked hash set. And\xa0\n
1199
01:49:43,630 --> 01:49:48,909
certain operations. So I'm not I don't really\xa0\n
1200
01:49:48,909 --> 01:49:52,269
feel like I'm already confusing you guys, but\xa0\n
1201
01:49:52,270 --> 01:49:56,950
like operations and speed and time complexity.\xa0\n
1202
01:49:56,949 --> 01:50:04,720
and a tree hash set or tree set. Whatever I typed,\xa0\n
1203
01:50:04,720 --> 01:50:08,560
worry if this is a bit confusing, like, we're,\xa0\n
1204
01:50:08,560 --> 01:50:12,190
I just want to show you cuz I feel like you\xa0\n
1205
01:50:12,189 --> 01:50:17,379
your projects or whatnot if you're learning this\xa0\n
1206
01:50:17,380 --> 01:50:21,730
these are easier to understand, don't worry. But\xa0\n
1207
01:50:21,729 --> 01:50:26,529
what we're going to do is we're going to type\xa0\n
1208
01:50:26,529 --> 01:50:31,869
case, I'm just gonna give my integer type. And\xa0\n
1209
01:50:31,869 --> 01:50:36,550
just that's important that we need to use integer\xa0\n
1210
01:50:36,550 --> 01:50:43,090
I'm going to call this one Tega and equals\xa0\n
1211
01:50:43,090 --> 01:50:48,579
and we'll put brackets and there we go. Now we're\xa0\n
1212
01:50:48,579 --> 01:50:54,309
up there. And we now have an A list. And what\xa0\n
1213
01:50:54,310 --> 01:51:00,670
think of it as the exact same thing as an array,\xa0\n
1214
01:51:00,670 --> 01:51:06,159
so we can add things to it, we can remove things\xa0\n
1215
01:51:06,159 --> 01:51:10,539
or the end of the list, sorry, we can add another\xa0\n
1216
01:51:10,539 --> 01:51:17,979
like a dynamically sized array. These have pretty\xa0\n
1217
01:51:17,979 --> 01:51:24,849
things, you can do t dot add. And you can add like\xa0\n
1218
01:51:24,850 --> 01:51:31,030
that works fine. To remove things T dot remove.\xa0\n
1219
01:51:31,029 --> 01:51:34,329
we can actually index things with the list\xa0\n
1220
01:51:34,329 --> 01:51:41,890
it's not going to just care that it exists like\xa0\n
1221
01:51:41,890 --> 01:51:47,350
and then we can give an index, right? So even it's\xa0\n
1222
01:51:47,350 --> 01:51:53,800
I do dot index zero, then that would give me one,\xa0\n
1223
01:51:53,800 --> 01:51:58,659
put thing to put something or to set something on\xa0\n
1224
01:51:58,659 --> 01:52:06,880
and you type the index and the element. So I want\xa0\n
1225
01:52:06,880 --> 01:52:13,930
then that's where I would do it, index one is\xa0\n
1226
01:52:13,930 --> 01:52:21,070
you what it looks like. Okay, sorry, that's we\xa0\n
1227
01:52:21,069 --> 01:52:25,389
something. So to set something like this, sorry,\xa0\n
1228
01:52:25,390 --> 01:52:31,180
index. I forgot I didn't add that. So I'm just\xa0\n
1229
01:52:31,180 --> 01:52:37,030
is what this set actually does is you have to\xa0\n
1230
01:52:37,029 --> 01:52:41,769
And this is going to change that index for you.\xa0\n
1231
01:52:41,770 --> 01:52:45,640
And before I was trying to set one, when we didn't\xa0\n
1232
01:52:45,640 --> 01:52:50,590
there we go. So now that works. We've changed\xa0\n
1233
01:52:50,590 --> 01:52:54,610
right. So that's the way that that works. I've got\xa0\n
1234
01:52:54,609 --> 01:53:02,109
few of these set. Yeah, okay, so that's the basic\xa0\n
1235
01:53:02,109 --> 01:53:07,960
we can do t dot empty, or is empty. And this\xa0\n
1236
01:53:07,960 --> 01:53:14,199
list. And what this allows us to do is get from\xa0\n
1237
01:53:14,199 --> 01:53:19,179
argument, yeah, so we just need an int. So this is\xa0\n
1238
01:53:19,180 --> 01:53:28,150
So say I add like these a bunch of times. Okay,\xa0\n
1239
01:53:28,149 --> 01:53:33,460
do is I want to get from like index one to index\xa0\n
1240
01:53:33,460 --> 01:53:41,680
let's just take this and put this here instead. So\xa0\n
1241
01:53:41,680 --> 01:53:49,570
out and see what we get. So we get here now is\xa0\n
1242
01:53:49,569 --> 01:53:54,309
has what do you call it, like six elements in it\xa0\n
1243
01:53:55,239 --> 01:54:01,989
not including three. So if I type like 124, then\xa0\n
1244
01:54:01,989 --> 01:54:07,269
we get five one and two, because that's from from\xa0\n
1245
01:54:07,270 --> 01:54:12,760
four. That's what we're grabbing, we're getting\xa0\n
1246
01:54:12,760 --> 01:54:20,469
Now, this is ArrayList. We also have linked list.\xa0\n
1247
01:54:20,470 --> 01:54:27,940
really explain to you just understand that it is\xa0\n
1248
01:54:27,939 --> 01:54:31,539
So for any of you to understand the difference\xa0\n
1249
01:54:31,539 --> 01:54:37,060
And you guys, I recommend you to play with\xa0\n
1250
01:54:37,060 --> 01:54:42,160
we're coming up on about 15 minutes now almost.\xa0\n
1251
01:54:42,159 --> 01:54:46,630
with sets and lists. Now I know this video\xa0\n
1252
01:54:46,630 --> 01:54:51,100
lot of stuff that I wasn't able to explain to you\xa0\n
1253
01:54:51,100 --> 01:54:56,560
to do something and you don't know how long you\xa0\n
1254
01:54:56,560 --> 01:55:00,789
You don't know how long you want it to be. It's\xa0\n
1255
01:55:00,789 --> 01:55:06,039
you would just use an ArrayList the way that I\xa0\n
1256
01:55:06,039 --> 01:55:10,449
because then you can add things, you can get\xa0\n
1257
01:55:10,449 --> 01:55:15,250
to worry about like having a designated length.\xa0\n
1258
01:55:15,250 --> 01:55:21,640
how many times something exists or where it\xa0\n
1259
01:55:21,640 --> 01:55:27,400
reason a set is better is because it's simpler.\xa0\n
1260
01:55:27,399 --> 01:55:35,859
terms of like a computer efficiency standpoint,\xa0\n
1261
01:55:35,859 --> 01:55:42,159
be talking about hash maps, or like Java maps. The\xa0\n
1262
01:55:42,159 --> 01:55:47,590
different implementations of maps, similar as to\xa0\n
1263
01:55:47,590 --> 01:55:53,140
and like ArrayList, and all that stuff. So\xa0\n
1264
01:55:53,140 --> 01:55:57,340
you can think of them as dictionaries. And I'm\xa0\n
1265
01:55:57,340 --> 01:56:03,279
So a hashmap, a tree map, and what was the last\xa0\n
1266
01:56:03,279 --> 01:56:08,710
sorry, just forgot about that one. So pretty much\xa0\n
1267
01:56:08,710 --> 01:56:14,170
languages, they're typically called dictionaries,\xa0\n
1268
01:56:14,170 --> 01:56:17,380
to create a map, and I'm just gonna do this, and\xa0\n
1269
01:56:17,380 --> 01:56:26,260
just gonna create a map M is going to equal to new\xa0\n
1270
01:56:26,260 --> 01:56:31,180
syntax, now to we have to import this. So I'm just\xa0\n
1271
01:56:31,180 --> 01:56:37,119
it, we have to import map as well. So we'll import\xa0\n
1272
01:56:37,119 --> 01:56:42,789
up now for us. Okay, so now that we have that, I\xa0\n
1273
01:56:42,791 --> 01:56:49,211
like I said, is a key value pair, meaning that\xa0\n
1274
01:56:49,210 --> 01:56:54,039
sun, so you can index things. But instead of\xa0\n
1275
01:56:54,041 --> 01:56:59,440
keys. Now keys can be anything that you want. A\xa0\n
1276
01:56:59,439 --> 01:57:02,469
actually, I'm not sure if it could be an array,\xa0\n
1277
01:57:02,470 --> 01:57:07,510
it can be a char, it can be a float, what like\xa0\n
1278
01:57:07,510 --> 01:57:13,750
And that key links us to a value. So the easiest\xa0\n
1279
01:57:13,750 --> 01:57:21,340
and then to talk about what's really happening. So\xa0\n
1280
01:57:21,340 --> 01:57:27,760
what you do is you have to specify a key, and\xa0\n
1281
01:57:27,760 --> 01:57:32,020
map is, in this case, m dot put, and then you\xa0\n
1282
01:57:32,020 --> 01:57:39,340
for my key, I'm going to type Tim, and it is going\xa0\n
1283
01:57:39,340 --> 01:57:44,770
the value is five. So I put that in there. And\xa0\n
1284
01:57:44,770 --> 01:57:52,081
print this out to the screen. Because I think it\xa0\n
1285
01:57:52,079 --> 01:57:58,260
am I saying System dot out dot print ln Sorry,\xa0\n
1286
01:57:58,260 --> 01:58:04,260
see what we get. So in this case, you can see we\xa0\n
1287
01:58:04,260 --> 01:58:10,500
meaning that if we're to index Tim, we get the\xa0\n
1288
01:58:10,500 --> 01:58:15,119
actually get a value based on a key, the way\xa0\n
1289
01:58:15,119 --> 01:58:21,630
next to your map, are actually you can't do like\xa0\n
1290
01:58:21,630 --> 01:58:27,900
I'm still used to the Python syntax here, guys,\xa0\n
1291
01:58:27,899 --> 01:58:33,779
in here. So in this case, I'm going to put Tim as\xa0\n
1292
01:58:33,779 --> 01:58:37,889
what we're going to get out to the screen. In this\xa0\n
1293
01:58:37,890 --> 01:58:44,220
the key Tim leads us to the value five. Now to\xa0\n
1294
01:58:44,220 --> 01:58:49,289
right. So we do Tim we could do like Joe, and Joe\xa0\n
1295
01:58:49,289 --> 01:58:55,019
to another string. And that string could be like,\xa0\n
1296
01:58:55,020 --> 01:59:01,710
we want. Like we can have the the key one and or\xa0\n
1297
01:59:01,710 --> 01:59:08,039
and now if I just print em out, you'll see that we\xa0\n
1298
01:59:08,039 --> 01:59:16,619
get Joe equals x Tim equals 511 equals 999. Okay,\xa0\n
1299
01:59:16,619 --> 01:59:21,449
or don't type, whatever you want to call it,\xa0\n
1300
01:59:21,449 --> 01:59:28,349
to overriding to getting happens in constant time.\xa0\n
1301
01:59:28,350 --> 01:59:31,800
you don't really have to understand what that\xa0\n
1302
01:59:31,800 --> 01:59:37,800
know that this does happen in constant time. Now\xa0\n
1303
01:59:37,800 --> 01:59:44,789
and the what was the other map talked about linked\xa0\n
1304
01:59:44,789 --> 01:59:49,140
the differences between them. So with a hash map,\xa0\n
1305
01:59:49,140 --> 01:59:56,070
show you this one does not retain an order. So all\xa0\n
1306
01:59:56,069 --> 02:00:00,778
unique keys meaning that if I try to add another\xa0\n
1307
02:00:00,779 --> 02:00:06,659
998. Instead of adding another key that's equal to\xa0\n
1308
02:00:06,659 --> 02:00:11,789
key that is 11. So in this case, you can see that\xa0\n
1309
02:00:11,789 --> 02:00:17,850
have the same keys existing in the map. But you\xa0\n
1310
02:00:17,850 --> 02:00:22,620
Okay, so sorry, that kind of got me off track.\xa0\n
1311
02:00:22,619 --> 02:00:28,140
hashmap does not guarantee the order in which\xa0\n
1312
02:00:28,140 --> 02:00:34,980
Tim, and then I added Joe, and then I added 11.\xa0\n
1313
02:00:34,979 --> 02:00:40,319
any kind of sorted order, because how do we sort\xa0\n
1314
02:00:40,319 --> 02:00:45,869
It's not in the order that we added it in. So what\xa0\n
1315
02:00:45,869 --> 02:00:50,519
is why this hashmap is extremely fast, because\xa0\n
1316
02:00:50,520 --> 02:00:55,110
when they go in. So just know that if you're\xa0\n
1317
02:00:55,109 --> 02:00:59,670
you can iterate through maps, and I'm going to\xa0\n
1318
02:00:59,670 --> 02:01:06,270
the correct order. Okay. Now, the next map that\xa0\n
1319
02:01:06,270 --> 02:01:12,870
now this tree map is what we're gonna have to\xa0\n
1320
02:01:12,869 --> 02:01:17,369
or the tree set, or whatever one I showed you in\xa0\n
1321
02:01:17,369 --> 02:01:21,779
it's actually going to keep it in a sorted order.\xa0\n
1322
02:01:21,779 --> 02:01:25,109
kind of sort we're going to get. Okay, so we\xa0\n
1323
02:01:25,109 --> 02:01:30,689
a good area to run into. Whenever we're using a\xa0\n
1324
02:01:30,689 --> 02:01:36,719
to be the same, meaning that the keys have to be\xa0\n
1325
02:01:36,720 --> 02:01:41,340
I'm gonna just gonna see if I remove this, if this\xa0\n
1326
02:01:41,340 --> 02:01:47,340
we do get in a sorted order, we get Joe and then\xa0\n
1327
02:01:47,340 --> 02:01:51,779
that's where it's going to sort strings. So if I\xa0\n
1328
02:01:51,779 --> 02:01:58,109
it's even true on a key value, I'll literally\xa0\n
1329
02:01:58,109 --> 02:02:05,099
can't set equal we have a comma. What's our air\xa0\n
1330
02:02:05,100 --> 02:02:09,450
so we'll run this. There we go. So you see, we get\xa0\n
1331
02:02:09,449 --> 02:02:14,069
in the alphabet. So that's going to show up for\xa0\n
1332
02:02:14,069 --> 02:02:18,929
And that means that the data types for the keys\xa0\n
1333
02:02:18,930 --> 02:02:22,289
numbers, we can use strings using whatever data\xa0\n
1334
02:02:22,289 --> 02:02:30,269
same for that map. Now, the other type is a linked\xa0\n
1335
02:02:30,270 --> 02:02:37,860
list in that it keeps the same order that you add\xa0\n
1336
02:02:37,859 --> 02:02:42,539
you can see we get Tim Joe and then a and that's\xa0\n
1337
02:02:42,539 --> 02:02:47,069
in which we added elements. So it's gonna say,\xa0\n
1338
02:02:47,069 --> 02:02:51,420
be the first thing that we show. And then Joe,\xa0\n
1339
02:02:51,420 --> 02:02:54,720
second, and then a, this is gonna be the third\xa0\n
1340
02:02:54,720 --> 02:03:00,210
them in. And those are the only main differences\xa0\n
1341
02:03:00,210 --> 02:03:04,590
run out, that you have to kind of understand\xa0\n
1342
02:03:04,590 --> 02:03:08,550
anything, you're just gonna be using a hashmap,\xa0\n
1343
02:03:08,550 --> 02:03:13,380
or a tree hash map, or tree map, whatever it's\xa0\n
1344
02:03:13,380 --> 02:03:18,930
be doing right now. So what I'm going to do now,\xa0\n
1345
02:03:18,930 --> 02:03:23,460
can kind of clear the maps, how we can like remove\xa0\n
1346
02:03:23,460 --> 02:03:29,939
do. So what we can do to get all the key values\xa0\n
1347
02:03:29,939 --> 02:03:36,419
Actually, I'll just show this one first. Well\xa0\n
1348
02:03:36,420 --> 02:03:42,840
are going to be really useful to you. And dot\xa0\n
1349
02:03:42,840 --> 02:03:49,470
contains values not available for type map. Hmm,\xa0\n
1350
02:03:49,470 --> 02:03:54,480
so we just have to put something there. Okay.\xa0\n
1351
02:03:54,479 --> 02:03:59,819
we're just going to put like any value on so in\xa0\n
1352
02:03:59,819 --> 02:04:04,679
is actually going to check for us if this value\xa0\n
1353
02:04:04,680 --> 02:04:09,720
all these these second elements here. And they\xa0\n
1354
02:04:09,720 --> 02:04:14,610
it's going to tell us if b exists. Now we can do\xa0\n
1355
02:04:14,609 --> 02:04:20,789
useful. And I'll show you why in a second contains\xa0\n
1356
02:04:20,789 --> 02:04:25,260
contains the key five, right and that will give us\xa0\n
1357
02:04:25,260 --> 02:04:32,010
with sets and lists in the last video. Okay.\xa0\n
1358
02:04:32,010 --> 02:04:38,430
if I try to do something like m dot get, and I\xa0\n
1359
02:04:38,430 --> 02:04:42,840
does not exist, the value five exists, but the\xa0\n
1360
02:04:42,840 --> 02:04:47,699
when I run the program. m dot get five actually\xa0\n
1361
02:04:47,699 --> 02:04:56,309
Because I'm curious if this is gonna crash. Let's\xa0\n
1362
02:04:56,310 --> 02:05:02,880
so this isn't gonna actually crash for us. If we\xa0\n
1363
02:05:02,880 --> 02:05:08,400
not exist in the map, but it's going to return us\xa0\n
1364
02:05:08,399 --> 02:05:14,009
map. That's actually interesting. I didn't know\xa0\n
1365
02:05:14,010 --> 02:05:18,630
or from a dictionary, and it doesn't exist, you\xa0\n
1366
02:05:18,630 --> 02:05:25,500
know. Anyways, I guess another method I could\xa0\n
1367
02:05:25,500 --> 02:05:31,710
this is going to do is it actually just prints out\xa0\n
1368
02:05:31,708 --> 02:05:38,938
and I simply print it down here, we get m dot\xa0\n
1369
02:05:38,939 --> 02:05:42,899
b, and five, which are all these and you can\xa0\n
1370
02:05:42,899 --> 02:05:49,649
it's important to remember, values, let's see\xa0\n
1371
02:05:49,649 --> 02:05:54,269
clear so I just got a text document beside me cuz\xa0\n
1372
02:05:54,270 --> 02:05:58,260
forget which ones. So Am I clear? Obviously,\xa0\n
1373
02:05:58,260 --> 02:06:05,010
what do you call it the map. So we get an empty\xa0\n
1374
02:06:05,010 --> 02:06:13,020
this one like that is simply just going to tell us\xa0\n
1375
02:06:13,020 --> 02:06:18,270
how much time we had 10 minutes. So I actually I\xa0\n
1376
02:06:18,270 --> 02:06:23,700
maps. But if you want to think about this, and\xa0\n
1377
02:06:23,699 --> 02:06:30,059
that I just showed you be good exercise. And that\xa0\n
1378
02:06:30,060 --> 02:06:38,550
count all of those characters into a map. So\xa0\n
1379
02:06:38,550 --> 02:06:45,800
and then the value for that key is equal to the\xa0\n
1380
02:06:45,800 --> 02:06:49,789
times that character occurs, and try to do that\xa0\n
1381
02:06:49,789 --> 02:06:53,090
well, then you're definitely learning and you're\xa0\n
1382
02:06:56,810 --> 02:07:00,800
What I'm going to be doing is showing you some\xa0\n
1383
02:07:00,800 --> 02:07:04,340
and how you can do that with the information\xa0\n
1384
02:07:04,340 --> 02:07:08,900
everything in now, mixing it all together, and\xa0\n
1385
02:07:08,899 --> 02:07:14,509
way to kind of like apply all the knowledge that\xa0\n
1386
02:07:14,510 --> 02:07:19,159
computer problems. Because a lot of the time\xa0\n
1387
02:07:19,159 --> 02:07:23,930
you don't know how to kind of mix it all together.\xa0\n
1388
02:07:23,930 --> 02:07:27,020
I'm also going to be showing you some like useful\xa0\n
1389
02:07:27,020 --> 02:07:32,390
to talk about in previous videos. So yeah, that's\xa0\n
1390
02:07:32,390 --> 02:07:39,230
last video, I mentioned that a good exercise to\xa0\n
1391
02:07:39,229 --> 02:07:43,519
and you want to count or like a sentence or a\xa0\n
1392
02:07:43,520 --> 02:07:47,570
store them in like a hashmap and have the letter\xa0\n
1393
02:07:47,569 --> 02:07:53,000
appear. So I figured for any of you guys that\xa0\n
1394
02:07:53,000 --> 02:07:56,899
I would show you a solution here quickly to doing\xa0\n
1395
02:07:56,899 --> 02:08:00,949
make sure you pay attention, because this is\xa0\n
1396
02:08:00,949 --> 02:08:05,210
understand kind of how maps work and how you can\xa0\n
1397
02:08:05,210 --> 02:08:11,989
is I'm just going to create a string, let's\xa0\n
1398
02:08:11,989 --> 02:08:21,920
my name is Tim. And I am Cool. All right,\xa0\n
1399
02:08:21,920 --> 02:08:26,329
going to do that just because we're going to\xa0\n
1400
02:08:26,329 --> 02:08:30,019
human way to count this would be to go through\xa0\n
1401
02:08:30,020 --> 02:08:33,590
okay, so I have an L how many times the L appear.\xa0\n
1402
02:08:33,590 --> 02:08:38,390
for loops, like very efficiently in computing.\xa0\n
1403
02:08:38,390 --> 02:08:43,250
what we're going to do is we're going to loop\xa0\n
1404
02:08:43,250 --> 02:08:49,250
this is because if I try to do like for char\xa0\n
1405
02:08:49,250 --> 02:08:56,600
right. And in str you see we get this red line,\xa0\n
1406
02:08:56,600 --> 02:09:01,340
that we can do this is actually a cool method and\xa0\n
1407
02:09:01,340 --> 02:09:08,810
string into a character array for us. And the way\xa0\n
1408
02:09:08,810 --> 02:09:14,660
array. And this is if I literally just print this\xa0\n
1409
02:09:14,659 --> 02:09:22,309
System dot out dot print ln is simply just going\xa0\n
1410
02:09:22,310 --> 02:09:28,010
into a character array for us. So let's just run\xa0\n
1411
02:09:28,010 --> 02:09:32,000
printing this entire thing, but it's actually\xa0\n
1412
02:09:32,000 --> 02:09:40,100
loop through it. So you'll see in a second. Okay,\xa0\n
1413
02:09:40,100 --> 02:09:46,070
I'm going to see if that key already exists in\xa0\n
1414
02:09:46,069 --> 02:09:49,969
because that value is gonna be how many times it\xa0\n
1415
02:09:49,970 --> 02:09:53,869
m it already exists in the map, I'm just gonna\xa0\n
1416
02:09:53,869 --> 02:09:59,930
a new value. And you'll see what I mean here in\xa0\n
1417
02:09:59,930 --> 02:10:10,880
Key of x, then what I'm going to do is I'm going\xa0\n
1418
02:10:10,880 --> 02:10:16,400
and then the key is going to be x. And then what\xa0\n
1419
02:10:17,090 --> 02:10:27,500
cast int, if I need this, forgetting all my\xa0\n
1420
02:10:27,500 --> 02:10:34,069
should be interesting one second, saying I have to\xa0\n
1421
02:10:34,069 --> 02:10:38,719
I don't think we actually need to do this, but\xa0\n
1422
02:10:38,720 --> 02:10:44,869
and then we'll say, dot quotes. And for the key\xa0\n
1423
02:10:44,869 --> 02:10:51,229
character. And we're gonna say old plus one. Now,\xa0\n
1424
02:10:51,229 --> 02:10:55,939
the amount, so that's going to go up by one\xa0\n
1425
02:10:55,939 --> 02:11:00,889
what we're going to do is we're going to put\xa0\n
1426
02:11:00,890 --> 02:11:04,310
is going to be one because we just found the\xa0\n
1427
02:11:04,310 --> 02:11:10,550
is going to be x standing for the letter. And\xa0\n
1428
02:11:10,550 --> 02:11:15,560
to see the counts of all these letters. So to do\xa0\n
1429
02:11:15,560 --> 02:11:21,350
we're going to print the line, and we're just\xa0\n
1430
02:11:21,350 --> 02:11:24,460
this fast, and you might not really understand\xa0\n
1431
02:11:24,460 --> 02:11:30,220
through every letter in this string, we're going\xa0\n
1432
02:11:30,220 --> 02:11:35,710
map contains that letter already. So as a key,\xa0\n
1433
02:11:35,710 --> 02:11:39,760
simply going to add in a key, and it's going to be\xa0\n
1434
02:11:39,760 --> 02:11:45,340
of one. Because we just found it occurs one time,\xa0\n
1435
02:11:45,340 --> 02:11:50,289
if that key does exist, what we're going to do is\xa0\n
1436
02:11:50,289 --> 02:11:54,399
we're going to add one to that previous count and\xa0\n
1437
02:11:54,399 --> 02:12:00,579
it goes up to five. Pretty straightforward. So\xa0\n
1438
02:12:00,579 --> 02:12:04,659
there's eight spaces, we get a, there's three AC,\xa0\n
1439
02:12:04,659 --> 02:12:08,019
an account all of the different letters for\xa0\n
1440
02:12:08,020 --> 02:12:13,420
we could go through and count them like\xa0\n
1441
02:12:13,420 --> 02:12:19,329
it does look as though that is correct. So yeah,\xa0\n
1442
02:12:19,329 --> 02:12:23,829
it's really useful. And there's a lot of cases in\xa0\n
1443
02:12:23,829 --> 02:12:27,519
so the next thing I want to show you guys is\xa0\n
1444
02:12:27,520 --> 02:12:31,720
this is really just gonna take like 10 seconds.\xa0\n
1445
02:12:31,720 --> 02:12:36,820
you probably already guessed, but it's literally\xa0\n
1446
02:12:36,819 --> 02:12:41,229
So I just felt like I had to say this, because\xa0\n
1447
02:12:41,229 --> 02:12:45,729
forgot to say it. So to remove an element, you\xa0\n
1448
02:12:45,729 --> 02:12:51,039
want to remove like all the spaces, which actually\xa0\n
1449
02:12:51,039 --> 02:12:58,479
then if I do that. Interesting why it's not\xa0\n
1450
02:12:58,479 --> 02:13:03,699
it's because it's not because of character. My bad\xa0\n
1451
02:13:03,699 --> 02:13:09,010
space is different. Yeah, so that it actually\xa0\n
1452
02:13:09,010 --> 02:13:15,880
or from our map, whatever. Okay. Now, the next\xa0\n
1453
02:13:15,880 --> 02:13:20,199
sorting is something you typically want to do on\xa0\n
1454
02:13:20,199 --> 02:13:25,239
and I'm going to create a new array, an\xa0\n
1455
02:13:25,239 --> 02:13:29,889
with cases do like three, and let's do a\xa0\n
1456
02:13:29,890 --> 02:13:37,900
can get this to sort for us. Let's do negative\xa0\n
1457
02:13:37,899 --> 02:13:45,129
actually really easy, all we have to do is just\xa0\n
1458
02:13:45,130 --> 02:13:51,250
it takes two arguments. Now the first argument is\xa0\n
1459
02:13:51,250 --> 02:13:56,380
x, and then the other two arguments are\xa0\n
1460
02:13:56,380 --> 02:14:02,980
three arguments not to what these arguments do is\xa0\n
1461
02:14:02,979 --> 02:14:07,629
let's say, like this part of the list that's\xa0\n
1462
02:14:07,630 --> 02:14:11,500
way that we would do that is we would type one\xa0\n
1463
02:14:11,500 --> 02:14:19,270
we were going to 71234567. Funny enough, we will\xa0\n
1464
02:14:19,270 --> 02:14:24,850
but the thing is, it's going to work up but not\xa0\n
1465
02:14:24,850 --> 02:14:31,150
going to that seven, but it's only going to sort\xa0\n
1466
02:14:31,149 --> 02:14:37,449
this does, and I believe is actually just changes\xa0\n
1467
02:14:37,449 --> 02:14:44,199
Arrays dot sort, we just say Arrays dot sort. And\xa0\n
1468
02:14:44,199 --> 02:14:52,059
dot print ln, and we can print x. And let's see if\xa0\n
1469
02:14:52,060 --> 02:14:57,100
us. Okay, so we actually, man of course, we can't\xa0\n
1470
02:14:57,100 --> 02:15:01,300
loop to print these out just because when we try\xa0\n
1471
02:15:01,300 --> 02:15:10,690
or we get that message because that's the memory\xa0\n
1472
02:15:10,689 --> 02:15:18,099
and then we'll simply just print out I, it's got\xa0\n
1473
02:15:18,100 --> 02:15:23,800
instead of printing, ln, we're just gonna print.\xa0\n
1474
02:15:23,800 --> 02:15:29,440
separated. Okay, so let's run that. So there we\xa0\n
1475
02:15:29,439 --> 02:15:35,019
of the list for us, right? So we got 1234567, you\xa0\n
1476
02:15:35,020 --> 02:15:38,590
99 was not touched. Now, if you want to sort the\xa0\n
1477
02:15:38,590 --> 02:15:43,600
these indexes, you can just put x, in this case,\xa0\n
1478
02:15:43,600 --> 02:15:49,030
all the way up to eight. And yeah, so you could\xa0\n
1479
02:15:49,029 --> 02:15:53,750
or whatever, okay. And you can see, it's only\xa0\n
1480
02:15:53,750 --> 02:15:59,779
list for us, or in the array for us. So that's a\xa0\n
1481
02:15:59,779 --> 02:16:05,149
actually, in quite easily using just Arrays\xa0\n
1482
02:16:05,149 --> 02:16:10,879
like x equals Arrays dot sort. Because what it's\xa0\n
1483
02:16:10,880 --> 02:16:16,400
elements of x and swap them around, rather than\xa0\n
1484
02:16:20,369 --> 02:16:24,930
Where you're going to be introducing object\xa0\n
1485
02:16:24,930 --> 02:16:29,610
objects are and getting a little bit into\xa0\n
1486
02:16:29,609 --> 02:16:36,179
thing to really talk about is what is an object.\xa0\n
1487
02:16:36,180 --> 02:16:40,680
certain data type. So we know we have data\xa0\n
1488
02:16:40,680 --> 02:16:45,990
like all kinds of different things that we can\xa0\n
1489
02:16:45,989 --> 02:16:51,420
whatever, or hash map all that stuff, okay. And\xa0\n
1490
02:16:51,420 --> 02:16:55,649
classes if you want to say that. So whenever we\xa0\n
1491
02:16:55,649 --> 02:17:02,279
like scanner, SC equals new scanner, essentially,\xa0\n
1492
02:17:02,280 --> 02:17:08,130
to a scanner object, okay. And whenever we create\xa0\n
1493
02:17:08,129 --> 02:17:14,789
x equals five, we're essentially saying x\xa0\n
1494
02:17:14,790 --> 02:17:21,120
okay? These objects are what allow us to have\xa0\n
1495
02:17:21,120 --> 02:17:27,450
So you know how we can add integers together, or\xa0\n
1496
02:17:27,450 --> 02:17:31,800
and we can have like a bunch of different methods\xa0\n
1497
02:17:31,799 --> 02:17:38,009
object that we're using. So, for example, we\xa0\n
1498
02:17:38,010 --> 02:17:44,430
so SC is equal to a new scanner object that's\xa0\n
1499
02:17:44,430 --> 02:17:52,380
only use this dot next method on SC because it is\xa0\n
1500
02:17:52,379 --> 02:17:57,150
a little semi colon here, you can see that we're\xa0\n
1501
02:17:57,149 --> 02:18:03,149
int, because well, that method doesn't exist for\xa0\n
1502
02:18:03,149 --> 02:18:07,829
kind of understand what objects are essentially,\xa0\n
1503
02:18:07,829 --> 02:18:13,920
even just doing like string like, str equals,\xa0\n
1504
02:18:13,920 --> 02:18:21,060
str is actually equal to a string object with\xa0\n
1505
02:18:21,060 --> 02:18:25,139
the different types of objects, we have different\xa0\n
1506
02:18:25,139 --> 02:18:29,940
with the methods we can call in, that's just kind\xa0\n
1507
02:18:29,940 --> 02:18:36,019
create like objects and whatnot, that are specific\xa0\n
1508
02:18:36,020 --> 02:18:40,130
videos, okay, so it'll all start to come together.\xa0\n
1509
02:18:40,129 --> 02:18:44,539
things objects, essentially, that's like you have\xa0\n
1510
02:18:44,540 --> 02:18:48,590
something, you're creating an object of that\xa0\n
1511
02:18:48,590 --> 02:18:53,059
for now. So now let's talk about methods. So\xa0\n
1512
02:18:53,059 --> 02:18:58,939
are because I think I went through a very brief\xa0\n
1513
02:18:58,939 --> 02:19:04,519
essentially, methods are anything that you call on\xa0\n
1514
02:19:04,520 --> 02:19:08,541
to clarify, when instances when we're creating\xa0\n
1515
02:19:08,540 --> 02:19:14,960
we can say that we're creating FC is now an object\xa0\n
1516
02:19:14,959 --> 02:19:20,839
instance of scanner of like the type of scanner,\xa0\n
1517
02:19:20,840 --> 02:19:26,510
instance, instead of object, they're very similar.\xa0\n
1518
02:19:26,510 --> 02:19:33,649
when we call this dot next method, we call it\xa0\n
1519
02:19:33,648 --> 02:19:39,739
pointing to our scanner object. So our scanner\xa0\n
1520
02:19:39,739 --> 02:19:44,299
showed you before, if I tried to call that on, for\xa0\n
1521
02:19:44,299 --> 02:19:51,079
that doesn't work because that object doesn't\xa0\n
1522
02:19:51,079 --> 02:19:54,920
is anything really that's just like a dot, and\xa0\n
1523
02:19:54,920 --> 02:20:00,710
brackets, for example, if we had like, an array\xa0\n
1524
02:20:00,709 --> 02:20:04,818
just another string probably should have deleted\xa0\n
1525
02:20:04,818 --> 02:20:10,849
equals Hello. And I can do something like H dot\xa0\n
1526
02:20:10,850 --> 02:20:17,149
to us the length of the string. And again, this\xa0\n
1527
02:20:17,148 --> 02:20:21,888
not going to work on our SC, because well, what\xa0\n
1528
02:20:21,889 --> 02:20:25,911
can see that we're getting this red line here. And\xa0\n
1529
02:20:25,909 --> 02:20:31,489
this length method is not defined for a scanner\xa0\n
1530
02:20:31,489 --> 02:20:35,959
call methods. And you guys have already seen a lot\xa0\n
1531
02:20:35,959 --> 02:20:40,789
on different objects and different data types.\xa0\n
1532
02:20:40,790 --> 02:20:46,670
and objects, data types are kind of like what the\xa0\n
1533
02:20:46,670 --> 02:20:51,200
in in future videos. Just want to clarify in\xa0\n
1534
02:20:51,200 --> 02:20:55,849
can we create our own methods? Well, currently,\xa0\n
1535
02:20:55,850 --> 02:21:01,579
we're going to be creating methods inside of this\xa0\n
1536
02:21:01,579 --> 02:21:05,569
because it is it contains this method. And\xa0\n
1537
02:21:05,569 --> 02:21:10,909
this method automatically runs whenever we run the\xa0\n
1538
02:21:10,909 --> 02:21:15,619
we're going to have in classes we create in future\xa0\n
1539
02:21:15,620 --> 02:21:20,900
per se. But this is a method because a method is\xa0\n
1540
02:21:20,899 --> 02:21:27,079
the class is what's going to define like our data\xa0\n
1541
02:21:27,079 --> 02:21:33,739
now, there's actually somewhere that says public\xa0\n
1542
02:21:33,739 --> 02:21:39,079
So if you do like brackets like this, it has a ton\xa0\n
1543
02:21:39,079 --> 02:21:45,049
that we can use by calling them from within this\xa0\n
1544
02:21:45,049 --> 02:21:50,090
method within this main class, what we can do,\xa0\n
1545
02:21:50,090 --> 02:21:54,020
going to do for now, I'm going to show you why we\xa0\n
1546
02:21:54,020 --> 02:22:00,470
but it's a bit advanced right now. We're something\xa0\n
1547
02:22:00,469 --> 02:22:06,889
return type we want, which we'll talk about in\xa0\n
1548
02:22:06,889 --> 02:22:12,920
of our method. So in this case, I'm gonna say\xa0\n
1549
02:22:12,920 --> 02:22:17,569
Tim has your parameters, again, talk about that\xa0\n
1550
02:22:17,569 --> 02:22:25,129
in here. In this case, I'm just gonna say system,\xa0\n
1551
02:22:25,129 --> 02:22:31,939
you call up, it just says Tim, like that. Okay. So\xa0\n
1552
02:22:31,939 --> 02:22:37,370
method that we can call from anywhere within this\xa0\n
1553
02:22:37,370 --> 02:22:43,400
well. So what we need to do to call this method\xa0\n
1554
02:22:43,399 --> 02:22:50,329
type the method name since case by type Tim. And I\xa0\n
1555
02:22:50,329 --> 02:22:57,889
you see that we get is it running? one second\xa0\n
1556
02:22:57,889 --> 02:23:02,789
wasn't working, because we have this SC dot next\xa0\n
1557
02:23:02,790 --> 02:23:07,440
out for right now. And we will run this one\xa0\n
1558
02:23:07,440 --> 02:23:11,280
the screen. Now I know, I didn't really explain\xa0\n
1559
02:23:11,280 --> 02:23:16,980
what I've done here is I've created kind of like a\xa0\n
1560
02:23:16,979 --> 02:23:21,239
other programming languages, you might see this\xa0\n
1561
02:23:21,239 --> 02:23:25,799
means here is it returns nothing, okay, because\xa0\n
1562
02:23:25,799 --> 02:23:28,829
which I'm going to show or sorry, functions\xa0\n
1563
02:23:28,829 --> 02:23:32,940
to show you in just a second. So this stands\xa0\n
1564
02:23:32,940 --> 02:23:36,270
we're just going to do something in here. So in\xa0\n
1565
02:23:36,271 --> 02:23:42,031
screen. All right, now we have Tim. And this is\xa0\n
1566
02:23:42,030 --> 02:23:48,540
here to trigger this to run, right. So if I wanted\xa0\n
1567
02:23:48,540 --> 02:23:55,110
to print whatever string I passed to Tim, well,\xa0\n
1568
02:23:55,110 --> 02:24:01,469
and then let's just say str like that. And now\xa0\n
1569
02:24:01,469 --> 02:24:06,270
we have to actually pass it one piece of\xa0\n
1570
02:24:06,271 --> 02:24:13,170
be a string. Okay, so I'm going to show you right\xa0\n
1571
02:24:13,170 --> 02:24:18,060
here like this, okay, and we run the program. Now\xa0\n
1572
02:24:18,060 --> 02:24:24,270
like with a bunch of M's can see if we run this\xa0\n
1573
02:24:24,271 --> 02:24:30,061
this is called a parameter. So str is a parameter\xa0\n
1574
02:24:30,060 --> 02:24:36,810
call this function, we have to type in arguments\xa0\n
1575
02:24:36,810 --> 02:24:42,090
going to be when we get to the method. So anything\xa0\n
1576
02:24:42,090 --> 02:24:46,409
what this is known as where we're like triggering\xa0\n
1577
02:24:46,409 --> 02:24:52,530
so Tim is an argument. When we call this what's\xa0\n
1578
02:24:52,530 --> 02:24:58,110
saying like str equals Tim like the other\xa0\n
1579
02:24:58,110 --> 02:25:03,060
simply going to print to the screen. Whatever\xa0\n
1580
02:25:03,060 --> 02:25:08,400
right? Now we can actually do multiple parameters\xa0\n
1581
02:25:08,399 --> 02:25:12,690
I wanted to pass two pieces of information every\xa0\n
1582
02:25:12,690 --> 02:25:19,950
and X, okay? And now it means that I have to pass\xa0\n
1583
02:25:19,950 --> 02:25:24,510
that means we have to type an integer in here.\xa0\n
1584
02:25:24,510 --> 02:25:32,309
to do now we're going to say four. And we'll say\xa0\n
1585
02:25:32,309 --> 02:25:40,680
say i plus plus, we're just going to print this\xa0\n
1586
02:25:40,680 --> 02:25:44,790
okay, so System dot out dot print line, what's\xa0\n
1587
02:25:44,790 --> 02:25:50,190
got to do that, sorry. Okay, so now we pass an\xa0\n
1588
02:25:50,190 --> 02:25:55,168
to do is simply print this as many times as like\xa0\n
1589
02:25:55,170 --> 02:26:00,059
that we now we get Tim four times to the screen.\xa0\n
1590
02:26:00,059 --> 02:26:04,889
in here, the two arguments are Tim and four. And\xa0\n
1591
02:26:04,889 --> 02:26:10,740
x. And when we pass our information in str gets\xa0\n
1592
02:26:10,739 --> 02:26:17,010
and then in here, we can now use those values by\xa0\n
1593
02:26:17,010 --> 02:26:21,930
so I hope that makes sense. Now, in terms of this\xa0\n
1594
02:26:21,930 --> 02:26:28,079
next video. For right now, all this means is that\xa0\n
1595
02:26:28,079 --> 02:26:32,280
which is kind of what we're doing here, when we're\xa0\n
1596
02:26:32,280 --> 02:26:37,950
object that's like a class main, which you'll\xa0\n
1597
02:26:37,950 --> 02:26:42,120
how we can create our own methods. Again, we can\xa0\n
1598
02:26:42,120 --> 02:26:44,700
I wanted to talk about now. So all I'm going\xa0\n
1599
02:26:44,700 --> 02:26:50,579
I'm going to say this is public static. And in\xa0\n
1600
02:26:50,579 --> 02:26:54,209
whoever's calling this Okay, or wherever this\xa0\n
1601
02:26:54,209 --> 02:26:57,209
because this is what I'm going to return and\xa0\n
1602
02:26:57,209 --> 02:27:02,699
the method is going to give back to us. And I'm\xa0\n
1603
02:27:02,700 --> 02:27:08,370
going to take an integer x as our one parameter\xa0\n
1604
02:27:08,370 --> 02:27:13,590
return Yeah, okay. So you can see, it's already\xa0\n
1605
02:27:13,590 --> 02:27:20,191
a value in this method, because we typed in the\xa0\n
1606
02:27:20,190 --> 02:27:27,299
I'm going to do here is I'm simply going to return\xa0\n
1607
02:27:27,299 --> 02:27:33,599
is it's just taking a value x, and it's adding to\xa0\n
1608
02:27:33,600 --> 02:27:38,430
wherever we call it. So let's just do something\xa0\n
1609
02:27:38,430 --> 02:27:45,809
I'm going to say, system, dot out, dot print, ln,\xa0\n
1610
02:27:45,809 --> 02:27:50,309
then give it a number, in this case, six. Now, you\xa0\n
1611
02:27:50,309 --> 02:27:56,489
But essentially, what's happening here is we're\xa0\n
1612
02:27:56,488 --> 02:28:01,709
our argument is six, it's coming in here, and the\xa0\n
1613
02:28:01,709 --> 02:28:07,589
to return so back to wherever we call this x plus\xa0\n
1614
02:28:07,590 --> 02:28:12,059
a value, and we go, and we bring it up here. And\xa0\n
1615
02:28:12,059 --> 02:28:16,289
going to print eight to the screen. And you can\xa0\n
1616
02:28:16,290 --> 02:28:20,069
obviously, in methods like this, you're probably\xa0\n
1617
02:28:20,068 --> 02:28:25,318
adding to that shows you how we can return values.\xa0\n
1618
02:28:25,318 --> 02:28:33,420
like a string value. So public static string,\xa0\n
1619
02:28:33,420 --> 02:28:39,540
because I don't really know what to do. And\xa0\n
1620
02:28:39,540 --> 02:28:44,550
we have to return a string value. So what we could\xa0\n
1621
02:28:44,549 --> 02:28:50,488
point. But I think I need to put that in double\xa0\n
1622
02:28:50,488 --> 02:28:54,388
now is we're adding an exclamation point to\xa0\n
1623
02:28:54,389 --> 02:29:01,859
that. So if I call str here. Okay, so we'll I\xa0\n
1624
02:29:01,859 --> 02:29:07,500
we'll do str. And then inside our brackets, we'll\xa0\n
1625
02:29:07,500 --> 02:29:12,809
an exclamation point. And indeed it does. And\xa0\n
1626
02:29:17,079 --> 02:29:20,739
going to be going over classes when we talk\xa0\n
1627
02:29:20,739 --> 02:29:27,099
constructor methods, all that fun stuff, creating\xa0\n
1628
02:29:27,100 --> 02:29:31,871
to be kind of an advanced video. Don't if you've\xa0\n
1629
02:29:31,870 --> 02:29:35,380
able to follow along with it. But just know that\xa0\n
1630
02:29:35,379 --> 02:29:39,579
of Java. So if you guys don't understand this,\xa0\n
1631
02:29:39,579 --> 02:29:43,989
ask me some questions, leave a comment down below.\xa0\n
1632
02:29:43,989 --> 02:29:48,369
have to understand this before you can really\xa0\n
1633
02:29:48,370 --> 02:29:52,960
for kind of all languages, but Java, especially\xa0\n
1634
02:29:52,959 --> 02:29:57,938
to understand classes and how to create classes.\xa0\n
1635
02:29:57,939 --> 02:30:03,159
so far, we've been working in this class. Hold me\xa0\n
1636
02:30:03,159 --> 02:30:08,680
class, all it's doing for us, is just running\xa0\n
1637
02:30:08,680 --> 02:30:13,420
And that's what we have this public static void\xa0\n
1638
02:30:13,420 --> 02:30:18,760
we click this little green Run button. Okay, so\xa0\n
1639
02:30:18,760 --> 02:30:23,979
have some methods that I've added in here that we\xa0\n
1640
02:30:23,978 --> 02:30:28,449
I'm going to do now is I'm going to create my\xa0\n
1641
02:30:28,450 --> 02:30:32,529
going to start coding. So to do this, we're going\xa0\n
1642
02:30:32,529 --> 02:30:36,639
tutorial, one for me, and I'm going to go new and\xa0\n
1643
02:30:36,639 --> 02:30:41,529
now I'm going to give my class a name. Now, for\xa0\n
1644
02:30:41,529 --> 02:30:46,179
And yeah, you guys can create whatever you want.\xa0\n
1645
02:30:46,180 --> 02:30:51,280
since you guys are most likely new to classes.\xa0\n
1646
02:30:51,279 --> 02:30:55,899
public class dog. And you can see we open up in\xa0\n
1647
02:30:55,898 --> 02:30:59,920
in Java, we have to actually create a new file\xa0\n
1648
02:30:59,920 --> 02:31:04,690
makes it really easy to navigate between different\xa0\n
1649
02:31:04,689 --> 02:31:09,609
just have all your classes in one file. Okay, so\xa0\n
1650
02:31:09,609 --> 02:31:15,009
class dog. So what does this What does this mean?\xa0\n
1651
02:31:15,010 --> 02:31:20,319
data type. And whenever we create an instance of a\xa0\n
1652
02:31:20,318 --> 02:31:24,308
doing is we're just using all the information\xa0\n
1653
02:31:24,309 --> 02:31:29,740
you can almost think of it as like a blueprint\xa0\n
1654
02:31:29,739 --> 02:31:33,879
fall for us? Like, why are they useful? So I'm\xa0\n
1655
02:31:33,879 --> 02:31:39,310
right? So I want to create five dogs, okay, I want\xa0\n
1656
02:31:39,310 --> 02:31:45,490
I want each dog to have an age. And I want to,\xa0\n
1657
02:31:45,489 --> 02:31:51,309
print out each dog's name and age and like a nice\xa0\n
1658
02:31:51,310 --> 02:31:56,920
do that. If we went back into main here, what we\xa0\n
1659
02:31:56,920 --> 02:32:01,569
here is we could just type a bunch of answer you\xa0\n
1660
02:32:01,569 --> 02:32:06,369
and that's dog one's age, we say int dog two,\xa0\n
1661
02:32:06,370 --> 02:32:11,710
create 10 variables, five for the age and five\xa0\n
1662
02:32:11,709 --> 02:32:15,760
we could print out each one each time. But\xa0\n
1663
02:32:15,761 --> 02:32:21,101
I wanted to have like 10,000 dogs? Well, what\xa0\n
1664
02:32:21,101 --> 02:32:26,320
like lists to create or lists or raised to create\xa0\n
1665
02:32:26,319 --> 02:32:30,639
it doesn't look as good in our actual coding. So\xa0\n
1666
02:32:30,640 --> 02:32:36,789
and you'll see how we can kind of accomplish this\xa0\n
1667
02:32:36,790 --> 02:32:42,700
have attributes, okay? Now attributes are kind of\xa0\n
1668
02:32:42,700 --> 02:32:47,471
this case, we want to have two attributes in our\xa0\n
1669
02:32:47,470 --> 02:32:51,190
the age to create our attributes. And so the first\xa0\n
1670
02:32:51,190 --> 02:32:55,899
right at the top of our class, we're going to type\xa0\n
1671
02:32:55,899 --> 02:33:00,850
data types. In this case, we can say string, and\xa0\n
1672
02:33:00,851 --> 02:33:03,911
name, okay, and this all we have to do, we're\xa0\n
1673
02:33:03,909 --> 02:33:08,829
we're going to have the attribute name, and\xa0\n
1674
02:33:08,829 --> 02:33:15,819
on in our program. Okay, we can also do private\xa0\n
1675
02:33:15,819 --> 02:33:20,260
is going to obviously represent the dog's age.\xa0\n
1676
02:33:20,261 --> 02:33:25,960
we would, again, type private. And we could keep\xa0\n
1677
02:33:25,959 --> 02:33:31,839
is this private keyword? And why do we have public\xa0\n
1678
02:33:31,840 --> 02:33:37,659
keyword does is it ensures that this name and\xa0\n
1679
02:33:37,659 --> 02:33:42,769
meaning that if I tried to do something over\xa0\n
1680
02:33:42,770 --> 02:33:47,060
from this class, I wouldn't be allowed to do that.\xa0\n
1681
02:33:47,059 --> 02:33:52,369
attribute, you can't access that. Why do we do\xa0\n
1682
02:33:52,369 --> 02:33:57,590
but we can also create public attributes as well\xa0\n
1683
02:33:57,590 --> 02:34:01,908
if I wanted my things to be public, I could put\xa0\n
1684
02:34:01,908 --> 02:34:06,859
we're going to use private, and it's best practice\xa0\n
1685
02:34:06,859 --> 02:34:11,689
for methods, which you'll see in a minute. Okay.\xa0\n
1686
02:34:11,689 --> 02:34:16,068
constructor method. Now this, you typically\xa0\n
1687
02:34:16,068 --> 02:34:22,099
create multiple, what this is going to do is it is\xa0\n
1688
02:34:22,100 --> 02:34:26,960
dog class. And the way we create this constructor,\xa0\n
1689
02:34:26,959 --> 02:34:32,898
class is we're going to do public. And we're just\xa0\n
1690
02:34:32,898 --> 02:34:38,209
so excuse me as a public dog, like this, okay.\xa0\n
1691
02:34:38,209 --> 02:34:42,799
everything's fine. And in here, we're going to\xa0\n
1692
02:34:42,799 --> 02:34:48,590
need to be passed in whenever we're creating a\xa0\n
1693
02:34:48,590 --> 02:34:52,549
nothing in here, when you create a dog object, all\xa0\n
1694
02:34:52,549 --> 02:34:56,479
object. You don't need to give any information and\xa0\n
1695
02:34:56,478 --> 02:35:02,000
to create an age and a name with our dogs. So what\xa0\n
1696
02:35:02,000 --> 02:35:08,180
and int, age, okay, just meaning that whenever we\xa0\n
1697
02:35:08,180 --> 02:35:13,729
and we need to give it an age. Now what I'm going\xa0\n
1698
02:35:13,728 --> 02:35:18,828
attributes equal to whatever we pass in. Okay? So\xa0\n
1699
02:35:18,828 --> 02:35:23,930
keyword and it's, the keyword is this, it's kind\xa0\n
1700
02:35:23,930 --> 02:35:27,590
just like saying this is a keyword and pointing\xa0\n
1701
02:35:27,590 --> 02:35:33,799
then I'm doing this dot name is going to be equal\xa0\n
1702
02:35:33,799 --> 02:35:42,319
age. So what is this, this this keyword actually\xa0\n
1703
02:35:42,318 --> 02:35:48,859
the class, okay? So when we type this, it is going\xa0\n
1704
02:35:48,859 --> 02:35:53,269
private attributes. And in this case, we have an\xa0\n
1705
02:35:53,270 --> 02:35:58,069
reference things that are a part of the specific\xa0\n
1706
02:35:58,068 --> 02:36:01,968
okay, and I'm going to explain more and more\xa0\n
1707
02:36:01,969 --> 02:36:09,019
in like small steps. Okay. So now that I have this\xa0\n
1708
02:36:09,020 --> 02:36:12,979
one more method, and then we can actually start\xa0\n
1709
02:36:12,978 --> 02:36:16,519
going to do now is I'm going to create another\xa0\n
1710
02:36:16,520 --> 02:36:20,748
I'm not going to return anything, so I'm going\xa0\n
1711
02:36:20,748 --> 02:36:25,248
speak. And what this is going to do is it is\xa0\n
1712
02:36:25,248 --> 02:36:33,289
to the screen. So I'm gonna say system, dot out,\xa0\n
1713
02:36:33,289 --> 02:36:37,998
all we're gonna do is we're gonna say I am, and I\xa0\n
1714
02:36:37,998 --> 02:36:49,818
we'll say this dot name, okay? And we'll say plus,\xa0\n
1715
02:36:49,818 --> 02:36:59,629
plus years old, okay? So suddenly gonna say like\xa0\n
1716
02:36:59,629 --> 02:37:05,208
years old, not great grammar, but that's fine. So\xa0\n
1717
02:37:05,209 --> 02:37:10,550
Or how do we use this class? Well, from our main\xa0\n
1718
02:37:10,549 --> 02:37:14,208
you know, we can delete all these, we don't need\xa0\n
1719
02:37:14,209 --> 02:37:19,850
we can actually create a object and to do that of\xa0\n
1720
02:37:19,850 --> 02:37:25,578
and we're gonna give it a name. In this case,\xa0\n
1721
02:37:25,578 --> 02:37:33,228
And then remember that we have to give dog some\xa0\n
1722
02:37:33,228 --> 02:37:36,769
have the name, and we have the age. So what we\xa0\n
1723
02:37:36,770 --> 02:37:42,110
age. In this case, we can type 10. And I'm going\xa0\n
1724
02:37:42,109 --> 02:37:46,849
we're looking good. So our dog's name\xa0\n
1725
02:37:46,850 --> 02:37:50,569
so that's great. Let's run the program, make\xa0\n
1726
02:37:50,568 --> 02:37:56,988
what I want to do is I want to use that\xa0\n
1727
02:37:56,988 --> 02:38:00,349
I'm going to do is I'm going to type Tim, which\xa0\n
1728
02:38:00,350 --> 02:38:09,140
dot speak like this, okay, semicolon. And let's\xa0\n
1729
02:38:09,139 --> 02:38:16,038
I am four years old. So the way that this worked,\xa0\n
1730
02:38:16,039 --> 02:38:22,130
and the instance was named Tim, and it referenced\xa0\n
1731
02:38:22,129 --> 02:38:26,448
instance, we said, okay, so this instance, this\xa0\n
1732
02:38:26,449 --> 02:38:31,489
and a name of Tim. All right. So it stored that\xa0\n
1733
02:38:31,488 --> 02:38:36,379
our private int. And then later on, when we\xa0\n
1734
02:38:36,379 --> 02:38:39,889
Okay, well give me the instance you're calling\xa0\n
1735
02:38:39,889 --> 02:38:44,389
we're gonna say okay, so Tim, what's Tim's name?\xa0\n
1736
02:38:44,389 --> 02:38:49,489
Tim, what's its age, its age. That's four. So\xa0\n
1737
02:38:49,488 --> 02:38:54,799
create multiple dog objects. So let's copy this\xa0\n
1738
02:38:54,799 --> 02:39:02,868
dog objects. I'm gonna say this is Bill, and he\xa0\n
1739
02:39:02,869 --> 02:39:11,449
11. Okay, let's copy this and keep naming the\xa0\n
1740
02:39:11,449 --> 02:39:16,970
and then we can simply call the speak methods on\xa0\n
1741
02:39:16,969 --> 02:39:21,319
Alright. And just to prove something, I'm gonna\xa0\n
1742
02:39:21,318 --> 02:39:26,509
why I do that in just a second. Okay, so let's run\xa0\n
1743
02:39:26,510 --> 02:39:31,850
I'm Bill I'm seven. Then go on and you can read\xa0\n
1744
02:39:31,850 --> 02:39:37,309
again, it still retains its age and its name.\xa0\n
1745
02:39:37,309 --> 02:39:43,519
Like this is not one variable. We actually now\xa0\n
1746
02:39:43,520 --> 02:39:48,530
we have bill we have Bob. And there's specific to\xa0\n
1747
02:39:48,529 --> 02:39:54,349
object okay. So that means that we can hold like\xa0\n
1748
02:39:54,350 --> 02:40:01,670
and we can have like infinite amount of instances\xa0\n
1749
02:40:01,670 --> 02:40:05,539
I think I'm going to talk about quickly. I\xa0\n
1750
02:40:05,539 --> 02:40:10,100
Let's create some more methods in here and see\xa0\n
1751
02:40:10,100 --> 02:40:13,789
about constructors because we're only at like,\xa0\n
1752
02:40:13,789 --> 02:40:19,641
going to create a another method. And I'm going to\xa0\n
1753
02:40:19,640 --> 02:40:26,720
And in this case, we'll say int, get H. All right.\xa0\n
1754
02:40:26,720 --> 02:40:32,180
the age to, let's see a return statement to\xa0\n
1755
02:40:32,181 --> 02:40:38,181
all we'll say it will return this dot h. Now,\xa0\n
1756
02:40:38,181 --> 02:40:41,271
I want to get the age of one of my dogs, right?\xa0\n
1757
02:40:41,271 --> 02:40:46,161
I don't know what it is I want the age. Well, we\xa0\n
1758
02:40:46,159 --> 02:40:51,709
we'd be able to do like Tim dot age, right? Now\xa0\n
1759
02:40:51,709 --> 02:40:57,379
lines. And it says the field dog dot age is not\xa0\n
1760
02:40:57,379 --> 02:41:02,959
So it's not letting us see it from over here\xa0\n
1761
02:41:02,959 --> 02:41:07,760
method only within this class, can we actually\xa0\n
1762
02:41:07,761 --> 02:41:14,120
what we can do is we can call Tim dot get age like\xa0\n
1763
02:41:14,120 --> 02:41:22,850
we say like, and x equals, I'm gonna say system,\xa0\n
1764
02:41:22,851 --> 02:41:29,871
So now if we run this, we can see that we get\xa0\n
1765
02:41:29,870 --> 02:41:34,280
of the screen. Now we can actually do the same\xa0\n
1766
02:41:34,280 --> 02:41:38,420
change the age at some point, maybe Tim got a year\xa0\n
1767
02:41:38,420 --> 02:41:42,021
another method in here, this case, we're going\xa0\n
1768
02:41:42,021 --> 02:41:45,261
and we don't need to enter this time, because\xa0\n
1769
02:41:45,261 --> 02:41:51,470
going to return to say public void. And we'll say,\xa0\n
1770
02:41:51,470 --> 02:41:57,500
because we need to know what we're going to set it\xa0\n
1771
02:41:57,500 --> 02:42:00,979
just like we've done up here, is the exact same\xa0\n
1772
02:42:00,979 --> 02:42:06,889
the method set age. So now, if I want to change\xa0\n
1773
02:42:06,890 --> 02:42:14,480
set age, and we'll give it a value of 10. Then\xa0\n
1774
02:42:14,479 --> 02:42:21,588
What's gonna happen now sorry, guys, I'm a bit\xa0\n
1775
02:42:21,590 --> 02:42:30,750
I'm going to do is, oh, what's your air timeouts\xa0\n
1776
02:42:30,750 --> 02:42:39,181
second here, sorry, public, let's try this. Insert\xa0\n
1777
02:42:39,181 --> 02:42:43,710
here. Oh, okay. That's why I can't do I can't set\xa0\n
1778
02:42:43,709 --> 02:42:48,959
age by about on that guys. We do speak, we can\xa0\n
1779
02:42:48,959 --> 02:42:53,909
and we've changed from the age of four. So that's\xa0\n
1780
02:42:53,909 --> 02:43:00,809
later on within the the class. Okay. Now I want to\xa0\n
1781
02:43:00,810 --> 02:43:07,020
and show you what this is. Okay, so I'm gonna\xa0\n
1782
02:43:07,021 --> 02:43:12,061
it. Okay. And we're going to call this add to it,\xa0\n
1783
02:43:12,060 --> 02:43:16,379
but just, it's just an example. Okay. And in here,\xa0\n
1784
02:43:16,379 --> 02:43:22,470
but we're going to return we're going to\xa0\n
1785
02:43:22,470 --> 02:43:29,579
this is a private method, meaning that it\xa0\n
1786
02:43:29,579 --> 02:43:36,450
So say I wanted to use this add to, maybe I\xa0\n
1787
02:43:36,450 --> 02:43:42,780
and just do a little semi colon. And there we go.\xa0\n
1788
02:43:42,780 --> 02:43:48,000
no issues with that. Okay. And that's how you use\xa0\n
1789
02:43:48,000 --> 02:43:54,120
I can easily every time we initiate the dog, call\xa0\n
1790
02:43:54,120 --> 02:43:57,511
class, you don't need to do like something dot\xa0\n
1791
02:43:57,511 --> 02:44:03,361
really visible within here, right? Now, what would\xa0\n
1792
02:44:03,360 --> 02:44:09,600
so add two, so we'll say Tim, dot add two like\xa0\n
1793
02:44:09,601 --> 02:44:15,150
a red line and says, This is not visible, you\xa0\n
1794
02:44:18,799 --> 02:44:23,238
So in today's video, we're going to be going over\xa0\n
1795
02:44:23,238 --> 02:44:29,209
this is going to be how we can inherit methods\xa0\n
1796
02:44:29,209 --> 02:44:33,919
new class, and then override methods and all kinds\xa0\n
1797
02:44:33,920 --> 02:44:40,940
save you a ton of time. And yeah, so let's get\xa0\n
1798
02:44:40,939 --> 02:44:45,648
this dog class that we created in the last video.\xa0\n
1799
02:44:45,648 --> 02:44:51,558
at least in this video, the problem is, I want to\xa0\n
1800
02:44:51,559 --> 02:44:58,129
class, except in the speak method here. Instead of\xa0\n
1801
02:44:58,129 --> 02:45:02,238
name is what I write right Just want to change\xa0\n
1802
02:45:02,238 --> 02:45:07,578
But other than that, I want all of this to be\xa0\n
1803
02:45:07,578 --> 02:45:13,158
is, well, we just take all this, copy it, put it\xa0\n
1804
02:45:13,158 --> 02:45:18,019
this to be what we want. Well, we could do that,\xa0\n
1805
02:45:18,020 --> 02:45:23,329
are like 1000s, and 1000s, of lines long, ideally,\xa0\n
1806
02:45:23,328 --> 02:45:27,049
typing like the same thing a bunch of times,\xa0\n
1807
02:45:27,049 --> 02:45:30,769
read. So what we're gonna do is we're going\xa0\n
1808
02:45:30,770 --> 02:45:34,970
going to create a new class, I'm gonna go new\xa0\n
1809
02:45:34,969 --> 02:45:41,179
cat, alright. And they'll just click Finish like\xa0\n
1810
02:45:41,180 --> 02:45:46,399
whenever we do this inheritance, what we can\xa0\n
1811
02:45:46,398 --> 02:45:51,439
all of the methods, everything from this dog\xa0\n
1812
02:45:51,439 --> 02:45:58,668
we can type extends, if we spell it correctly,\xa0\n
1813
02:45:58,670 --> 02:46:04,940
Now what this is going to do is it is going to\xa0\n
1814
02:46:04,939 --> 02:46:10,818
class. So this is known as our superclass because\xa0\n
1815
02:46:10,818 --> 02:46:16,340
known as our subclass. So we have, you can also\xa0\n
1816
02:46:16,340 --> 02:46:20,420
could be also called a parent class, all right.\xa0\n
1817
02:46:20,420 --> 02:46:23,568
getting everything from there, but then it's going\xa0\n
1818
02:46:23,568 --> 02:46:28,548
few methods to it. So typically, you start off\xa0\n
1819
02:46:28,549 --> 02:46:32,840
and then your child classes or your drug classes\xa0\n
1820
02:46:32,840 --> 02:46:36,319
same thing, just everyone likes to use different\xa0\n
1821
02:46:36,319 --> 02:46:41,809
modifications to them, and kind of work based\xa0\n
1822
02:46:41,810 --> 02:46:46,431
class. Okay. So what we need to do when we first\xa0\n
1823
02:46:46,431 --> 02:46:50,900
us, we need to use the constructor for dogs. So\xa0\n
1824
02:46:50,899 --> 02:46:55,369
the same constructor, otherwise, all this stuff.\xa0\n
1825
02:46:55,370 --> 02:47:00,440
to work unless we set up our class when we first\xa0\n
1826
02:47:00,440 --> 02:47:03,799
gonna do is I'm actually just going to click on\xa0\n
1827
02:47:03,799 --> 02:47:08,810
this constructor for us. Now, I could have typed\xa0\n
1828
02:47:08,810 --> 02:47:14,840
going to do. So since in our dog class, we get\xa0\n
1829
02:47:14,840 --> 02:47:20,271
we have a constructor inside of our cat class that\xa0\n
1830
02:47:20,271 --> 02:47:26,871
explicitly call our superclass constructor, which\xa0\n
1831
02:47:26,870 --> 02:47:32,510
this formation or this syntax super. And then we\xa0\n
1832
02:47:32,510 --> 02:47:37,070
doesn't stop us from being able to type in other\xa0\n
1833
02:47:37,069 --> 02:47:41,869
I could do something like int, and I don't know\xa0\n
1834
02:47:41,870 --> 02:47:46,400
should get, this works perfectly fine. And we can\xa0\n
1835
02:47:46,399 --> 02:47:55,309
So we say private, or no, I'll just say food.\xa0\n
1836
02:47:55,310 --> 02:48:01,970
here, we can go ahead, and we can just type this\xa0\n
1837
02:48:01,970 --> 02:48:05,869
perfectly fine. And now we're gonna have, since\xa0\n
1838
02:48:05,870 --> 02:48:10,971
we're gonna have name, and inside of this cat\xa0\n
1839
02:48:10,970 --> 02:48:17,390
works just fine. Okay. So just to know, let's\xa0\n
1840
02:48:17,390 --> 02:48:22,400
through pretty quickly. But all of these methods\xa0\n
1841
02:48:22,399 --> 02:48:26,809
cat class, because we'll we're inheriting we're\xa0\n
1842
02:48:26,810 --> 02:48:31,700
cat class when we first extend it, and do nothing\xa0\n
1843
02:48:31,700 --> 02:48:36,710
we start changing a few things in here, it's gonna\xa0\n
1844
02:48:36,709 --> 02:48:41,750
this functionality. So we still have the attribute\xa0\n
1845
02:48:41,750 --> 02:48:47,220
because we're gonna call this constructor method,\xa0\n
1846
02:48:47,220 --> 02:48:51,210
here. So we call this constructor. So we set up\xa0\n
1847
02:48:51,210 --> 02:48:55,081
we have get age, we have set age. Now before\xa0\n
1848
02:48:55,081 --> 02:48:58,921
you. So if I go to main here, and I just\xa0\n
1849
02:48:58,921 --> 02:49:04,200
CIM equals new cat. And remember, we have to give\xa0\n
1850
02:49:04,200 --> 02:49:08,640
because that's what we typed in. So for name, we\xa0\n
1851
02:49:08,640 --> 02:49:12,390
let's say they get 100. I don't know grams of food\xa0\n
1852
02:49:12,390 --> 02:49:19,860
Okay. Now I can use this speak method on Tim. So\xa0\n
1853
02:49:19,860 --> 02:49:25,560
in my cat class, there's no speak method. But\xa0\n
1854
02:49:25,560 --> 02:49:29,700
we can use it. So I'll prove again to you\xa0\n
1855
02:49:29,700 --> 02:49:34,950
and that works perfectly fine. So now remember\xa0\n
1856
02:49:34,950 --> 02:49:39,659
something else, I want to change it. So how can we\xa0\n
1857
02:49:39,659 --> 02:49:44,909
this is to just rewrite the method in here because\xa0\n
1858
02:49:44,909 --> 02:49:49,020
whatever's in the dog class. So the child class\xa0\n
1859
02:49:49,021 --> 02:49:53,820
Whenever there's something the same in here, it\xa0\n
1860
02:49:53,819 --> 02:50:01,171
whatever is in the dog class. So I do public, void\xa0\n
1861
02:50:01,171 --> 02:50:06,030
other one. All right, and in here, I change I do\xa0\n
1862
02:50:06,030 --> 02:50:15,600
just gonna say, system dot out, dot print ln. And\xa0\n
1863
02:50:15,601 --> 02:50:23,341
name is what to say plus this dot name. And you\xa0\n
1864
02:50:23,341 --> 02:50:32,640
get fed. Let's see here, plus this dot food.\xa0\n
1865
02:50:32,640 --> 02:50:38,460
what's the issue here? Change visibility of name\xa0\n
1866
02:50:38,460 --> 02:50:49,109
here. Okay, this just needs to be sorry, public\xa0\n
1867
02:50:49,110 --> 02:50:53,100
actually able to see these attributes, because\xa0\n
1868
02:50:53,101 --> 02:50:56,701
our cat class. So we just need to change them to\xa0\n
1869
02:50:56,700 --> 02:51:00,240
to use them within our speak method, we can also\xa0\n
1870
02:51:00,239 --> 02:51:04,199
to talk about near the end of this video. Okay, so\xa0\n
1871
02:51:04,200 --> 02:51:09,389
get into protected. But let's see what happens.\xa0\n
1872
02:51:09,389 --> 02:51:15,780
my name is Tim and I get fed 100. Okay. And that's\xa0\n
1873
02:51:15,780 --> 02:51:20,700
since we wrote it again, in our cat class, and\xa0\n
1874
02:51:20,700 --> 02:51:25,800
simply going to take this one, and we're going to\xa0\n
1875
02:51:25,799 --> 02:51:29,219
obviously, when we're doing inheritance,\xa0\n
1876
02:51:29,219 --> 02:51:32,939
we can add more stuff, and we do whatever we want,\xa0\n
1877
02:51:32,939 --> 02:51:39,960
say public void, I don't know, eat. And in this\xa0\n
1878
02:51:39,959 --> 02:51:46,589
like as how much they're eating. And we can say\xa0\n
1879
02:51:46,590 --> 02:51:51,960
subtract from it however much they ate. And then\xa0\n
1880
02:51:51,959 --> 02:51:55,349
going to be seen in the dog class, right? So we\xa0\n
1881
02:51:55,350 --> 02:51:59,850
all the stuff we do in the cat class is not going\xa0\n
1882
02:51:59,850 --> 02:52:05,340
dog does not extend cat, right. So it's kind of a\xa0\n
1883
02:52:05,340 --> 02:52:09,540
branches off and we could have other things extend\xa0\n
1884
02:52:09,540 --> 02:52:13,740
the cat class. And we can just keep going and\xa0\n
1885
02:52:13,739 --> 02:52:19,949
extending. Also known as like inheritance, right?\xa0\n
1886
02:52:19,950 --> 02:52:27,150
to show something called multiple constructors,\xa0\n
1887
02:52:27,149 --> 02:52:31,529
a class, we want to be able to pass it like a\xa0\n
1888
02:52:31,530 --> 02:52:37,349
class differently, right. So for example, my\xa0\n
1889
02:52:37,350 --> 02:52:42,540
if however, I only wanted to give it a name and\xa0\n
1890
02:52:42,540 --> 02:52:47,280
they don't have to be mutually exclusive, right?\xa0\n
1891
02:52:47,280 --> 02:52:51,960
set it up, or I could give it just two. And to\xa0\n
1892
02:52:51,959 --> 02:52:58,349
So I'm going to do the exact same thing as above,\xa0\n
1893
02:52:58,350 --> 02:53:03,871
out one of the parameters here. Okay, so Second\xa0\n
1894
02:53:03,870 --> 02:53:11,340
and name and H guy. And you'll see no red lines,\xa0\n
1895
02:53:11,340 --> 02:53:17,290
doing here is we're giving it another way to set\xa0\n
1896
02:53:17,290 --> 02:53:22,181
our attributes and set up the cat class. So we can\xa0\n
1897
02:53:22,181 --> 02:53:26,591
or three arguments, or we can call it using two.\xa0\n
1898
02:53:26,591 --> 02:53:31,691
using one, we're only using zero. So let's do\xa0\n
1899
02:53:31,690 --> 02:53:41,950
work. Okay, so if I do string name, and then int,\xa0\n
1900
02:53:41,950 --> 02:53:44,980
should just get rushed. actually get rid of this,\xa0\n
1901
02:53:44,979 --> 02:53:51,340
I'm going to give name. But what about age? What\xa0\n
1902
02:53:51,341 --> 02:53:57,819
know. How are we going to set it up? If they only\xa0\n
1903
02:53:57,819 --> 02:54:01,959
they don't give us an age, then we should just\xa0\n
1904
02:54:01,959 --> 02:54:06,699
let's do that I'm going to put in zero, just hard\xa0\n
1905
02:54:06,700 --> 02:54:10,631
for example, they only want to give us a name,\xa0\n
1906
02:54:10,630 --> 02:54:15,400
of zero, they want to give us a name. And in age,\xa0\n
1907
02:54:15,399 --> 02:54:19,209
should do in here, if they give us a name and age\xa0\n
1908
02:54:19,209 --> 02:54:24,130
don't know, maybe let's give it a default value of\xa0\n
1909
02:54:24,130 --> 02:54:28,930
eats, we're just going to assume that they eat 50.\xa0\n
1910
02:54:28,931 --> 02:54:33,281
know when I was like default parameters. If they\xa0\n
1911
02:54:33,280 --> 02:54:38,350
a value for that. So that everything still works\xa0\n
1912
02:54:38,351 --> 02:54:45,310
the three different ways that we can create a cat.\xa0\n
1913
02:54:45,310 --> 02:54:51,370
we'll give it a name. So we'll say Bob, and we'll\xa0\n
1914
02:54:51,370 --> 02:54:55,301
works fine. Again, this defines a cat right\xa0\n
1915
02:54:55,300 --> 02:54:59,739
So let's do this one more time. And in this case,\xa0\n
1916
02:54:59,739 --> 02:55:07,300
this One do, like the name Joe. Alright. And\xa0\n
1917
02:55:07,300 --> 02:55:14,619
like Bob speak. And we could do, Joe does speak.\xa0\n
1918
02:55:14,620 --> 02:55:21,341
can define a cat. Okay, so Meow, my name is Joe, I\xa0\n
1919
02:55:21,341 --> 02:55:25,940
on like that. So again, when we have one, now we\xa0\n
1920
02:55:25,939 --> 02:55:31,460
we should probably give them food as well. So we\xa0\n
1921
02:55:31,459 --> 02:55:35,659
default value for how much they get fit. So that\xa0\n
1922
02:55:35,659 --> 02:55:42,200
And now I'm going to talk about protected values.\xa0\n
1923
02:55:42,200 --> 02:55:48,050
similar to private and public. But they're, they\xa0\n
1924
02:55:48,049 --> 02:55:52,789
use the protected keyword instead of public\xa0\n
1925
02:55:52,790 --> 02:55:57,800
here in my dog class, I'm going to go up and\xa0\n
1926
02:55:57,799 --> 02:56:05,809
things that are within the same package, or are\xa0\n
1927
02:56:05,809 --> 02:56:11,029
pretty much like name. Okay, so that means any of\xa0\n
1928
02:56:11,029 --> 02:56:16,279
package are able to see this. But if I had another\xa0\n
1929
02:56:16,279 --> 02:56:21,170
Java programs, anything in there would not be able\xa0\n
1930
02:56:21,170 --> 02:56:28,068
what do you call it whenever we're creating\xa0\n
1931
02:56:28,068 --> 02:56:34,638
Wow. Okay. We're going to want to use a protected\xa0\n
1932
02:56:34,639 --> 02:56:40,250
our attributes so that we can change them access\xa0\n
1933
02:56:40,250 --> 02:56:44,689
for these methods, it's fine. They're public\xa0\n
1934
02:56:44,689 --> 02:56:50,148
well, if we didn't want another package to be able\xa0\n
1935
02:56:50,148 --> 02:56:53,808
right, if we create a private method here, I'm\xa0\n
1936
02:56:53,809 --> 02:56:58,370
if this is going to allow us to use this\xa0\n
1937
02:56:58,909 --> 02:57:08,420
let me know which one I changed. Get age.\xa0\n
1938
02:57:08,420 --> 02:57:13,670
this is gonna work. Yeah. So again, this is not\xa0\n
1939
02:57:13,670 --> 02:57:18,440
made it private, right? If we made that protected,\xa0\n
1940
02:57:18,439 --> 02:57:25,818
of the package. Now, I want to try this though,\xa0\n
1941
02:57:25,818 --> 02:57:33,619
our cat class. So if I do, for example, when I\xa0\n
1942
02:57:33,620 --> 02:57:38,120
so this isn't working as well. Which means\xa0\n
1943
02:57:38,120 --> 02:57:43,810
we have to make sure they're either public or\xa0\n
1944
02:57:43,810 --> 02:57:48,549
time you really get to create private methods\xa0\n
1945
02:57:48,549 --> 02:57:52,509
using the map that so for example, maybe you're\xa0\n
1946
02:57:52,510 --> 02:57:56,531
from within the class and you don't want anyone\xa0\n
1947
02:57:56,530 --> 02:57:59,950
you create a private method to do that, because\xa0\n
1948
02:58:03,899 --> 02:58:09,751
So in today's video, we're gonna be going over\xa0\n
1949
02:58:09,751 --> 02:58:14,791
So you may have seen that we've used static\xa0\n
1950
02:58:14,790 --> 02:58:20,609
actually, I'm going to delete all this. It says\xa0\n
1951
02:58:20,610 --> 02:58:24,090
I guess I haven't really explained what static\xa0\n
1952
02:58:24,091 --> 02:58:30,781
this video. So let's get started and talk about\xa0\n
1953
02:58:30,781 --> 02:58:35,850
called attributes games, we have these two\xa0\n
1954
02:58:35,851 --> 02:58:41,671
our dog. So when we created multiple dog objects,\xa0\n
1955
02:58:41,671 --> 02:58:46,021
and other dogs were not affected when we change\xa0\n
1956
02:58:46,021 --> 02:58:51,361
unless that dog was that obviously, right.\xa0\n
1957
02:58:51,360 --> 02:58:56,340
of different values that are specific to different\xa0\n
1958
02:58:56,341 --> 02:59:03,390
sometimes, we want to have variables that will\xa0\n
1959
02:59:03,390 --> 02:59:07,110
we can change them in one instance. And if we do\xa0\n
1960
02:59:07,110 --> 02:59:11,820
other. Now, those are known as class variables,\xa0\n
1961
02:59:11,820 --> 02:59:15,780
are like kind of attributes, okay? The way that\xa0\n
1962
02:59:15,781 --> 02:59:20,430
something like this. So yes, let's say protected\xa0\n
1963
02:59:20,431 --> 02:59:24,390
in my dog class, I deleted a bunch of stuff out\xa0\n
1964
02:59:24,390 --> 02:59:28,350
And I still have the cat class, but it's just\xa0\n
1965
02:59:28,351 --> 02:59:36,782
say protected static int count equals zero. Now,\xa0\n
1966
02:59:36,781 --> 02:59:42,631
doing here essentially is we're creating a class\xa0\n
1967
02:59:42,630 --> 02:59:47,100
which is protected. Okay, I know it's a lot\xa0\n
1968
02:59:47,101 --> 02:59:52,141
do so what this is actually going to do is it's\xa0\n
1969
02:59:52,140 --> 02:59:57,690
which means it's not going to change for each\xa0\n
1970
02:59:57,690 --> 03:00:03,270
it'll change like that. All together, right? So\xa0\n
1971
03:00:03,271 --> 03:00:07,861
this static keyword is going to allow us to do.\xa0\n
1972
03:00:07,860 --> 03:00:12,990
variable is a part of, we just care that it's a\xa0\n
1973
03:00:12,990 --> 03:00:19,379
this value x, well, I do need still need to call\xa0\n
1974
03:00:19,379 --> 03:00:24,180
then or actually, I'm gonna say plus equals one,\xa0\n
1975
03:00:24,181 --> 03:00:30,570
here, consist, I feel dogs should be accessed in\xa0\n
1976
03:00:30,569 --> 03:00:36,119
Okay, what I'm doing here, sorry, one second,\xa0\n
1977
03:00:36,120 --> 03:00:40,770
this count, because I want to keep track of how\xa0\n
1978
03:00:40,771 --> 03:00:44,911
know, like, see how many dogs have been created,\xa0\n
1979
03:00:44,909 --> 03:00:50,700
then figure that out. Alright. So what I'm doing\xa0\n
1980
03:00:50,700 --> 03:00:56,579
actually work, is I'm calling dog count. Because\xa0\n
1981
03:00:56,579 --> 03:00:59,879
static variable, class variable, whatever you\xa0\n
1982
03:00:59,879 --> 03:01:04,829
what instance I'm changing it on, because it's\xa0\n
1983
03:01:04,829 --> 03:01:09,420
actually use the name of the class to change it.\xa0\n
1984
03:01:09,420 --> 03:01:14,219
I'm not sure if you guys read that. It said we\xa0\n
1985
03:01:14,219 --> 03:01:20,159
it's a static variable. So I could, however, call\xa0\n
1986
03:01:20,159 --> 03:01:25,889
Because this will is an instance of the dog class\xa0\n
1987
03:01:25,890 --> 03:01:32,400
but it's much better to do dog count, like plus\xa0\n
1988
03:01:32,399 --> 03:01:36,539
you that this does indeed actually work. I'm not\xa0\n
1989
03:01:36,540 --> 03:01:47,220
objects here. Say a Tim or dog. Tim equals new.\xa0\n
1990
03:01:47,219 --> 03:01:54,570
say 10, and score nine for age. And we'll just\xa0\n
1991
03:01:54,569 --> 03:02:05,100
maybe, say, Bill, and that is new dog name. Bill,\xa0\n
1992
03:02:05,101 --> 03:02:10,111
is protected, I can actually access it from me.\xa0\n
1993
03:02:10,110 --> 03:02:18,210
to print count out first of all, is I'll prove to\xa0\n
1994
03:02:18,209 --> 03:02:24,419
keep thinking, we're in Python here. And I'll just\xa0\n
1995
03:02:24,420 --> 03:02:29,670
and just see what we get as a value First of all,\xa0\n
1996
03:02:29,670 --> 03:02:35,370
is indeed working, because well, when we added one\xa0\n
1997
03:02:35,370 --> 03:02:39,780
it would just be one. But anyways, and if I want\xa0\n
1998
03:02:39,780 --> 03:02:47,340
dog dot count, let's say equals like seven. Okay?\xa0\n
1999
03:02:47,340 --> 03:02:52,620
count, we get seven. Now I'll show you two. If I\xa0\n
2000
03:02:52,620 --> 03:02:57,840
answer. So you can see we get seven. Even though\xa0\n
2001
03:02:57,840 --> 03:03:02,941
count. Since it's a dog part of the dog class,\xa0\n
2002
03:03:02,940 --> 03:03:08,159
obviously, within 10 as well. Okay, so that's kind\xa0\n
2003
03:03:08,159 --> 03:03:12,959
talk about static methods. Okay, so this was a\xa0\n
2004
03:03:12,959 --> 03:03:16,469
a class variable just because it's what I'm used\xa0\n
2005
03:03:16,469 --> 03:03:21,329
we're gonna talk about static methods. And what\xa0\n
2006
03:03:21,329 --> 03:03:26,219
way that this works, but is a little different.\xa0\n
2007
03:03:26,219 --> 03:03:39,270
void, display, okay. And in here, all I'm going to\xa0\n
2008
03:03:39,271 --> 03:03:48,720
I'll just print. I am a doc. Okay. So what this is\xa0\n
2009
03:03:48,719 --> 03:03:54,449
in here, what's going to happen essentially, is\xa0\n
2010
03:03:54,450 --> 03:04:02,159
actually just call this on the dog class. So I\xa0\n
2011
03:04:02,159 --> 03:04:08,099
since it's a static method, this works fine. And\xa0\n
2012
03:04:08,100 --> 03:04:11,820
to if this was a regular method, so let's just\xa0\n
2013
03:04:11,819 --> 03:04:20,429
here. So public void, and we'll say, display to\xa0\n
2014
03:04:20,430 --> 03:04:24,451
it word for word in here, just to show you the\xa0\n
2015
03:04:24,450 --> 03:04:30,780
to do dog dot display too. You can see that we're\xa0\n
2016
03:04:30,780 --> 03:04:37,530
this static because we need an instance to call\xa0\n
2017
03:04:37,530 --> 03:04:43,009
create a dog object. And then we can use that\xa0\n
2018
03:04:43,010 --> 03:04:47,659
this dot display too. And that works fine because\xa0\n
2019
03:04:47,659 --> 03:04:53,000
this represents the instance that we're using. So\xa0\n
2020
03:04:53,000 --> 03:05:01,520
simply using dog but the thing was static is it\xa0\n
2021
03:05:01,520 --> 03:05:06,531
values are our attributes, right? So if I wanted\xa0\n
2022
03:05:06,530 --> 03:05:12,019
I can't do that for a static method like, I can't\xa0\n
2023
03:05:12,020 --> 03:05:17,300
work. Because if you think about it, well,\xa0\n
2024
03:05:17,299 --> 03:05:21,469
there's no instance, we're just simply calling\xa0\n
2025
03:05:21,469 --> 03:05:26,149
age to look for, or what name to look for. So the\xa0\n
2026
03:05:26,148 --> 03:05:29,838
care about the instance. And we just want to do\xa0\n
2027
03:05:29,840 --> 03:05:34,909
class. You can almost think of it as a function if\xa0\n
2028
03:05:34,909 --> 03:05:39,409
that is ideally how static works. So whenever you\xa0\n
2029
03:05:39,409 --> 03:05:43,728
about the like the instance, you don't care about\xa0\n
2030
03:05:43,728 --> 03:05:50,418
way you can call it without having an instance. So\xa0\n
2031
03:05:50,420 --> 03:05:54,680
I'll quickly go over what this void does one\xa0\n
2032
03:05:54,680 --> 03:05:59,300
in our functions, we can return values, when you\xa0\n
2033
03:05:59,299 --> 03:06:03,049
anything, we're just going to do something,\xa0\n
2034
03:06:03,049 --> 03:06:07,879
or in this case, printing something out to the\xa0\n
2035
03:06:07,879 --> 03:06:11,959
the user, but we're just not returning\xa0\n
2036
03:06:15,459 --> 03:06:21,219
So in today's video, we're gonna be going over\xa0\n
2037
03:06:21,219 --> 03:06:25,719
a string representation of different objects.\xa0\n
2038
03:06:25,719 --> 03:06:30,010
these are really useful. And I guarantee you guys\xa0\n
2039
03:06:30,010 --> 03:06:34,510
objects, like maybe like point objects, or like\xa0\n
2040
03:06:34,510 --> 03:06:40,149
to compare, without having to make things too\xa0\n
2041
03:06:40,148 --> 03:06:44,858
right. So what I'm going to do here, and what I've\xa0\n
2042
03:06:44,859 --> 03:06:48,279
set up. And this is just what we're going to work\xa0\n
2043
03:06:48,279 --> 03:06:52,329
in previous videos were already like finished, and\xa0\n
2044
03:06:52,329 --> 03:06:58,988
And currently the only attribute the student\xa0\n
2045
03:06:58,988 --> 03:07:02,769
I've just created a few different students.\xa0\n
2046
03:07:02,770 --> 03:07:07,210
out to the screen. So that's why I have that\xa0\n
2047
03:07:07,209 --> 03:07:12,039
we just create a name for a student. Now I just\xa0\n
2048
03:07:12,040 --> 03:07:18,640
like comparing objects intuitively right? So say\xa0\n
2049
03:07:18,639 --> 03:07:22,119
right? Like if I want to see if they were equal to\xa0\n
2050
03:07:22,120 --> 03:07:28,000
So what I would do is I'd say like Joe is equal\xa0\n
2051
03:07:28,000 --> 03:07:32,049
know, their names are not the same. So they're\xa0\n
2052
03:07:32,049 --> 03:07:37,329
that would be correct, but not for the reason that\xa0\n
2053
03:07:37,329 --> 03:07:42,430
have Joe and Bill compared to each other. So watch\xa0\n
2054
03:07:42,430 --> 03:07:45,790
right? So you'd think well, these would be\xa0\n
2055
03:07:45,790 --> 03:07:51,040
right? Because they have the same name. But watch\xa0\n
2056
03:07:51,040 --> 03:07:56,560
why is that? Exactly? Well, pretty much we\xa0\n
2057
03:07:56,559 --> 03:08:03,581
right? So like Joe, and Bill, the computer\xa0\n
2058
03:08:03,579 --> 03:08:09,789
what it does is it compares the actual object. And\xa0\n
2059
03:08:09,790 --> 03:08:14,470
a new object. And here we're creating another new\xa0\n
2060
03:08:14,469 --> 03:08:20,170
two different objects, like in memory, okay, so\xa0\n
2061
03:08:20,170 --> 03:08:25,898
entities. And they're completely unique. Although,\xa0\n
2062
03:08:25,898 --> 03:08:32,318
names, and we can do things. These need to be\xa0\n
2063
03:08:32,318 --> 03:08:36,670
actually saying, well, we're going to look and see\xa0\n
2064
03:08:36,670 --> 03:08:42,100
are not. Now that's useful in some cases, because\xa0\n
2065
03:08:42,100 --> 03:08:48,520
same object. But in other cases, we want to see if\xa0\n
2066
03:08:48,520 --> 03:08:54,190
So in this case, we probably want to compare the\xa0\n
2067
03:08:54,189 --> 03:09:00,009
same. And in that case, we would say, Well, yes,\xa0\n
2068
03:09:00,010 --> 03:09:04,360
Yes, they are, they are the same, right? When we\xa0\n
2069
03:09:04,359 --> 03:09:09,099
do now is I'll delete this. Let me show you how we\xa0\n
2070
03:09:09,100 --> 03:09:16,661
class, I'm going to add a method, okay. We'll call\xa0\n
2071
03:09:16,659 --> 03:09:23,289
we're gonna say equals, and then here, we're gonna\xa0\n
2072
03:09:23,290 --> 03:09:29,739
then we'll go like that. And there we are. So what\xa0\n
2073
03:09:29,738 --> 03:09:35,529
our students, okay, we're going to pass another\xa0\n
2074
03:09:35,529 --> 03:09:39,759
right? So we're going to call this dot equals on\xa0\n
2075
03:09:39,760 --> 03:09:43,510
going to give it another student, and then we're\xa0\n
2076
03:09:43,510 --> 03:09:48,130
say we're going to check the same? Well, we're\xa0\n
2077
03:09:48,129 --> 03:09:55,929
going to do is I'm going to say if, and then we'll\xa0\n
2078
03:09:55,930 --> 03:10:01,090
here as well. always forget about those. If this\xa0\n
2079
03:10:01,090 --> 03:10:08,920
other dot name, then what we'll do is we'll simply\xa0\n
2080
03:10:08,920 --> 03:10:15,909
names are not the same, what we will do is we\xa0\n
2081
03:10:15,909 --> 03:10:21,549
we need to do for our dot equals. So now, what's\xa0\n
2082
03:10:21,549 --> 03:10:25,000
we'll call this we'll check name, and then we'll\xa0\n
2083
03:10:25,000 --> 03:10:29,200
if it is, or if the same will return true,\xa0\n
2084
03:10:29,200 --> 03:10:36,130
try this out. So these two are the same names.\xa0\n
2085
03:10:36,129 --> 03:10:41,980
I guess we will put a bill. So let's run this.\xa0\n
2086
03:10:41,979 --> 03:10:49,329
if I change bill, back to say, Bill, then we\xa0\n
2087
03:10:49,329 --> 03:10:54,280
now we officially have something checking for\xa0\n
2088
03:10:54,280 --> 03:10:59,711
more kind of ones like this, like equals grade,\xa0\n
2089
03:10:59,710 --> 03:11:03,760
how we can check for equality between objects.\xa0\n
2090
03:11:03,761 --> 03:11:08,140
Obviously, if you had a student with a bunch more\xa0\n
2091
03:11:08,140 --> 03:11:12,940
other stuff like that, or like a last name, you\xa0\n
2092
03:11:12,940 --> 03:11:17,290
Or you can just kind of customly do it the way\xa0\n
2093
03:11:17,290 --> 03:11:24,011
the same, right? Okay, so the next thing I want to\xa0\n
2094
03:11:24,011 --> 03:11:28,570
than sign or less than sign, right? So I want to\xa0\n
2095
03:11:28,569 --> 03:11:33,969
greater than Tim. And we should intuitively like\xa0\n
2096
03:11:33,970 --> 03:11:38,230
can't really show you like a way to do it here cuz\xa0\n
2097
03:11:38,229 --> 03:11:44,500
than bill. Yeah, see, that just is undefined,\xa0\n
2098
03:11:44,500 --> 03:11:50,560
is we're going to use a method called compare to,\xa0\n
2099
03:11:50,560 --> 03:11:57,700
to, what do you call it, sir, we have to implement\xa0\n
2100
03:11:57,700 --> 03:12:03,280
at the top of our class, I'm gonna spell it\xa0\n
2101
03:12:03,280 --> 03:12:09,280
then in here, we're going to do student. Now what\xa0\n
2102
03:12:09,280 --> 03:12:14,230
is we're actually implementing something called\xa0\n
2103
03:12:14,229 --> 03:12:19,689
about in I think, like two videos from now. But\xa0\n
2104
03:12:19,690 --> 03:12:25,329
we have to use for the class to work. So when\xa0\n
2105
03:12:25,329 --> 03:12:31,931
we're allowed to bring in a method that is going\xa0\n
2106
03:12:31,931 --> 03:12:41,171
we'll do now, is we will say, public and actually,\xa0\n
2107
03:12:41,171 --> 03:12:48,790
ins and compare compared to, and then in brackets\xa0\n
2108
03:12:48,790 --> 03:12:55,860
this will be other, we'll put our brackets here\xa0\n
2109
03:12:55,860 --> 03:12:59,670
return some kind of integer. And I'll show you how\xa0\n
2110
03:12:59,670 --> 03:13:05,670
screen, so don't mess this up. Okay. What I'm\xa0\n
2111
03:13:05,670 --> 03:13:12,480
dot compare to, and in this case, we're going to\xa0\n
2112
03:13:12,479 --> 03:13:19,319
will be other dot name, okay. So essentially,\xa0\n
2113
03:13:19,319 --> 03:13:24,180
this name to this other name, and it's going to\xa0\n
2114
03:13:24,181 --> 03:13:29,670
away they are, right? So it's, it's kind of hard\xa0\n
2115
03:13:29,670 --> 03:13:37,441
it from over here. And you'll see what I mean.\xa0\n
2116
03:13:37,440 --> 03:13:46,620
to bill. Let's see what we get. We get a value of\xa0\n
2117
03:13:46,620 --> 03:13:51,240
bill by a distance of eight, meaning that\xa0\n
2118
03:13:51,239 --> 03:13:58,020
they are eight away, I believe, okay. So if we\xa0\n
2119
03:13:58,021 --> 03:14:03,331
we do is we check if this integer value returned\xa0\n
2120
03:14:03,329 --> 03:14:09,091
that's going to tell us true if Joe is greater\xa0\n
2121
03:14:09,091 --> 03:14:17,310
and we get true. Now, let's see if we compare Joe\xa0\n
2122
03:14:17,310 --> 03:14:22,770
alphabet, so we get a value of false, okay, and\xa0\n
2123
03:14:22,771 --> 03:14:27,000
can see exactly what we're actually getting as a\xa0\n
2124
03:14:27,000 --> 03:14:33,629
far away j is from T one, we're comparing them and\xa0\n
2125
03:14:33,629 --> 03:14:38,310
if we wanted to check if Joe was less than 10,\xa0\n
2126
03:14:38,310 --> 03:14:44,070
in this case, we get true. So that's a really easy\xa0\n
2127
03:14:44,069 --> 03:14:48,841
that compare to method Okay, so like this a public\xa0\n
2128
03:14:48,841 --> 03:14:55,170
implement comparable students. And then you can\xa0\n
2129
03:14:55,170 --> 03:15:00,420
the last thing I want to show is a string\xa0\n
2130
03:15:00,420 --> 03:15:04,620
what happens when I just want to print out\xa0\n
2131
03:15:04,620 --> 03:15:10,180
him. And maybe ideally, I'd like to see like\xa0\n
2132
03:15:10,180 --> 03:15:14,889
look what we get here, we get tutorial, one dot\xa0\n
2133
03:15:14,889 --> 03:15:21,340
What this is printing is actually the memory\xa0\n
2134
03:15:21,340 --> 03:15:26,111
are actually stored in memory, in RAM in like\xa0\n
2135
03:15:26,110 --> 03:15:29,889
you guys. But anyways, this is like the address\xa0\n
2136
03:15:29,889 --> 03:15:35,680
this is what it's actually using to find Tim and\xa0\n
2137
03:15:35,680 --> 03:15:41,800
us where it is in the tutorial one, like folder,\xa0\n
2138
03:15:41,799 --> 03:15:46,119
we this does not help us as programmers at all\xa0\n
2139
03:15:46,120 --> 03:15:51,820
and gives us some valuable information. So\xa0\n
2140
03:15:51,819 --> 03:15:57,879
nother method here, that's going to change this\xa0\n
2141
03:15:57,879 --> 03:16:05,259
but this is exactly what I'm going to use, we're\xa0\n
2142
03:16:05,260 --> 03:16:11,979
like this, okay. And what we're gonna do in here\xa0\n
2143
03:16:11,978 --> 03:16:18,728
of our object. So what we can do essentially, is\xa0\n
2144
03:16:18,728 --> 03:16:23,378
what we're going to use to represent our object.\xa0\n
2145
03:16:23,379 --> 03:16:28,299
like this, okay, and just follow me for one\xa0\n
2146
03:16:28,299 --> 03:16:34,929
and then we're gonna add this store name. And then\xa0\n
2147
03:16:34,930 --> 03:16:38,441
you'll see when I printed out to the screen,\xa0\n
2148
03:16:38,440 --> 03:16:45,370
then Tim. And this is just simply telling us that\xa0\n
2149
03:16:45,370 --> 03:16:50,019
and the name value is Tim. Okay. And we could\xa0\n
2150
03:16:50,020 --> 03:16:55,451
double brackets around this name, if we want\xa0\n
2151
03:16:55,450 --> 03:17:00,700
okay? Now for our purpose, I'm just going to\xa0\n
2152
03:17:00,700 --> 03:17:06,010
And you can see again, when we print this, it\xa0\n
2153
03:17:06,010 --> 03:17:12,430
I'm not actually calling this two string method,\xa0\n
2154
03:17:12,430 --> 03:17:17,409
Java actually knows that when we have this two\xa0\n
2155
03:17:17,409 --> 03:17:22,500
a string, right? So when we try to print it, it's\xa0\n
2156
03:17:22,500 --> 03:17:30,000
Okay. So now, what we can do is we also just\xa0\n
2157
03:17:30,000 --> 03:17:34,739
I could just call.to string like this, and I\xa0\n
2158
03:17:34,739 --> 03:17:40,530
the exact same way as before, you can see we get\xa0\n
2159
03:17:40,530 --> 03:17:44,309
however you'd like. In some cases, like say your\xa0\n
2160
03:17:44,309 --> 03:17:47,730
their name. And then after you have like an array\xa0\n
2161
03:17:51,549 --> 03:17:55,239
Now, inner classes are pretty, pretty easy,\xa0\n
2162
03:17:55,239 --> 03:18:00,190
class inside of another class or inside of a\xa0\n
2163
03:18:00,190 --> 03:18:04,450
go along. But since we already know all about\xa0\n
2164
03:18:04,450 --> 03:18:09,370
I'm not gonna explain too much of it, I'm just\xa0\n
2165
03:18:09,370 --> 03:18:15,400
of inner classes in different ways. So I'm gonna\xa0\n
2166
03:18:15,399 --> 03:18:19,479
that I've already created. can see on the side\xa0\n
2167
03:18:19,479 --> 03:18:26,469
intercourse right now, in a class is just gonna\xa0\n
2168
03:18:26,470 --> 03:18:34,000
make this a public void display. And in here, all\xa0\n
2169
03:18:34,000 --> 03:18:41,860
to the screen. So we know that we're actually in\xa0\n
2170
03:18:41,860 --> 03:18:51,460
inner class, okay? And what's our error here,\xa0\n
2171
03:18:51,459 --> 03:19:01,119
mistake somewhere here, one second guys. Oh,\xa0\n
2172
03:19:01,120 --> 03:19:06,971
know why I added those anyways. Okay, so this\xa0\n
2173
03:19:06,970 --> 03:19:11,409
I'm going to create another method that's going to\xa0\n
2174
03:19:11,409 --> 03:19:16,600
is actually contained within the outer class,\xa0\n
2175
03:19:16,601 --> 03:19:21,521
can only actually access it from within our class.\xa0\n
2176
03:19:21,521 --> 03:19:25,420
means we must need a method in our class to do\xa0\n
2177
03:19:25,420 --> 03:19:30,340
inner, and in here, we're going to take nothing,\xa0\n
2178
03:19:30,340 --> 03:19:37,181
instance of our inner class and just display Okay,\xa0\n
2179
03:19:37,181 --> 03:19:44,500
new inner class like that. Okay? And then all\xa0\n
2180
03:19:44,500 --> 03:19:51,129
make sure that this is working. Okay, so now our\xa0\n
2181
03:19:51,129 --> 03:19:56,289
have these void inner and all that does is create\xa0\n
2182
03:19:56,290 --> 03:20:01,540
screen. Again, note that this is private meaning\xa0\n
2183
03:20:01,540 --> 03:20:08,351
okay, so now if I go to my main dot java, I can\xa0\n
2184
03:20:08,351 --> 03:20:13,181
we can see this. So first of all, what I have to\xa0\n
2185
03:20:13,181 --> 03:20:22,181
call that inner class. So outer class out equals\xa0\n
2186
03:20:22,181 --> 03:20:28,091
that I don't have any constructors here, meaning\xa0\n
2187
03:20:28,091 --> 03:20:31,960
outer class or my inner class when I first call\xa0\n
2188
03:20:31,959 --> 03:20:36,699
brackets. Okay. So now if I want to see my inner\xa0\n
2189
03:20:36,700 --> 03:20:42,971
enter. Ok. So we'll call that method to create\xa0\n
2190
03:20:42,970 --> 03:20:48,671
run quickly here. And we can see we get this is\xa0\n
2191
03:20:48,671 --> 03:20:53,860
Now I'm just going to make this public. Now I'm\xa0\n
2192
03:20:53,860 --> 03:20:57,940
of the class. So right now what we need to do is\xa0\n
2193
03:20:57,940 --> 03:21:02,170
then we need to call the method inner, to be able\xa0\n
2194
03:21:02,171 --> 03:21:06,880
was private. But now that it's public, we should\xa0\n
2195
03:21:06,880 --> 03:21:13,390
class. So the way that we do that is we still\xa0\n
2196
03:21:13,390 --> 03:21:18,789
class is defined within outer class. So we need to\xa0\n
2197
03:21:18,790 --> 03:21:23,440
right? As we did that, we have outer class.\xa0\n
2198
03:21:23,440 --> 03:21:32,649
dot inner class, okay. And we'll just call this\xa0\n
2199
03:21:32,649 --> 03:21:40,059
going to be our instance of outer class dot. And\xa0\n
2200
03:21:40,060 --> 03:21:46,720
believe this is correct. But I guess we'll see\xa0\n
2201
03:21:46,720 --> 03:21:52,091
new new outer dot inner class. And let's see what\xa0\n
2202
03:21:52,091 --> 03:22:14,579
package out. Interesting one second, guys. Okay,\xa0\n
2203
03:22:14,579 --> 03:22:19,409
like this, what we need to do is we need to do dot\xa0\n
2204
03:22:19,409 --> 03:22:25,229
new instance inside of this right of outer class\xa0\n
2205
03:22:25,229 --> 03:22:30,809
we've created this i n, which is an object, which\xa0\n
2206
03:22:30,810 --> 03:22:38,820
n, which is an instance of inner class, right to\xa0\n
2207
03:22:38,819 --> 03:22:43,889
so if we run this, see, this is an inner class,\xa0\n
2208
03:22:43,890 --> 03:22:47,459
you can get access the in a class. Now, right?\xa0\n
2209
03:22:47,459 --> 03:22:51,839
would I do this, because now it's just like a ton\xa0\n
2210
03:22:51,840 --> 03:22:55,950
don't really care about like this instance, and\xa0\n
2211
03:22:55,950 --> 03:23:01,140
it. So in that case, this would make more sense to\xa0\n
2212
03:23:01,140 --> 03:23:06,629
methods than just one you're gonna be using. Okay?\xa0\n
2213
03:23:06,629 --> 03:23:13,170
show creating this kind of inner class. So I'm\xa0\n
2214
03:23:13,170 --> 03:23:17,191
actually create these inside of methods, which are\xa0\n
2215
03:23:17,190 --> 03:23:21,088
we want to use a class and we don't want to have\xa0\n
2216
03:23:21,090 --> 03:23:27,480
Okay. So we have this public void, enter. So I\xa0\n
2217
03:23:27,479 --> 03:23:32,250
don't even leave in a class right now. And let's\xa0\n
2218
03:23:32,250 --> 03:23:36,870
and I can say, we can do public private, in this\xa0\n
2219
03:23:36,870 --> 03:23:44,850
to class in a class. And then here, yes, that\xa0\n
2220
03:23:44,851 --> 03:23:52,050
So we'll say, public void display. And now that I\xa0\n
2221
03:23:52,049 --> 03:24:00,060
my other code, but whatever, get some practice\xa0\n
2222
03:24:00,060 --> 03:24:07,980
should probably be a T, we will just type inner\xa0\n
2223
03:24:07,979 --> 03:24:12,569
fine. Whenever we call this void inner, then we\xa0\n
2224
03:24:12,569 --> 03:24:18,539
an instance of it, and we're going to display it.\xa0\n
2225
03:24:18,540 --> 03:24:26,550
just kept all that code. That's fine. Why is this\xa0\n
2226
03:24:26,549 --> 03:24:38,309
new and outer class and brackets. And then in this\xa0\n
2227
03:24:38,309 --> 03:24:44,279
so now we can see what should happen is again,\xa0\n
2228
03:24:44,279 --> 03:24:49,619
and we get in our class. Now pretty much you can\xa0\n
2229
03:24:49,619 --> 03:24:54,239
saying this is public or private is just because\xa0\n
2230
03:24:54,238 --> 03:24:57,718
we're gonna have to call this void. So there's\xa0\n
2231
03:24:57,719 --> 03:25:03,750
like private or public But again, like if you\xa0\n
2232
03:25:03,750 --> 03:25:08,010
or Oh, actually saying you can't do that. So I\xa0\n
2233
03:25:08,010 --> 03:25:11,908
inside of this void, you're only gonna be able\xa0\n
2234
03:25:11,908 --> 03:25:16,769
in really giving it like a public or private\xa0\n
2235
03:25:16,770 --> 03:25:20,489
we can still do public and private methods,\xa0\n
2236
03:25:20,488 --> 03:25:24,658
be using those methods, right. So you can see\xa0\n
2237
03:25:24,658 --> 03:25:29,579
inside of the, the voids inside of inner,\xa0\n
2238
03:25:29,579 --> 03:25:34,350
it wouldn't work. Because this class is only\xa0\n
2239
03:25:38,579 --> 03:25:43,049
interfaces are either unique to Java, actually,\xa0\n
2240
03:25:43,049 --> 03:25:48,269
languages, but they're somewhat similar to\xa0\n
2241
03:25:48,270 --> 03:25:53,100
And anyways, you guys will see as we go through\xa0\n
2242
03:25:53,100 --> 03:25:57,121
they're an important part of Java, so we need to\xa0\n
2243
03:25:57,120 --> 03:26:00,420
is we're gonna create a new interface.\xa0\n
2244
03:26:00,420 --> 03:26:04,680
we're just gonna right click on tutorial one,\xa0\n
2245
03:26:04,680 --> 03:26:09,990
obviously, we're gonna click interface. Now,\xa0\n
2246
03:26:09,989 --> 03:26:14,760
example that I'm going to be doing. So we'll click\xa0\n
2247
03:26:14,760 --> 03:26:18,420
no like, you don't have to package generate\xa0\n
2248
03:26:18,420 --> 03:26:24,540
now we have an interface called vehicle. So\xa0\n
2249
03:26:24,540 --> 03:26:30,899
something that is completely abstract. Now, this\xa0\n
2250
03:26:30,898 --> 03:26:36,088
not actually going to like you can't create an\xa0\n
2251
03:26:36,090 --> 03:26:41,969
is to be inherited from. So if we have a class\xa0\n
2252
03:26:41,969 --> 03:26:47,459
car could implement the interface and use it.\xa0\n
2253
03:26:47,459 --> 03:26:52,949
interface it just here, so that we can implement\xa0\n
2254
03:26:52,950 --> 03:26:59,550
So inside of our interfaces, and you'll see\xa0\n
2255
03:26:59,549 --> 03:27:05,699
and we actually don't define anything inside the\xa0\n
2256
03:27:05,700 --> 03:27:10,380
a method in interface, and I'll just make one\xa0\n
2257
03:27:10,379 --> 03:27:18,029
void, speed up. And we'll take as a parameter\xa0\n
2258
03:27:18,030 --> 03:27:22,679
I don't put those, the brackets, I don't do\xa0\n
2259
03:27:22,680 --> 03:27:27,389
this. Now, you could see that this is completely\xa0\n
2260
03:27:27,389 --> 03:27:32,849
it just defines the fact that this method exists.\xa0\n
2261
03:27:32,850 --> 03:27:37,979
don't give it a value, that's kind of what we're\xa0\n
2262
03:27:37,978 --> 03:27:42,599
car class. And you'll kind of have to go through\xa0\n
2263
03:27:42,600 --> 03:27:47,281
when you create a method, just know that you don't\xa0\n
2264
03:27:47,280 --> 03:27:52,880
this method will exist in any of the classes that\xa0\n
2265
03:27:52,879 --> 03:27:58,278
methods here and already call it like a attribute.\xa0\n
2266
03:27:58,279 --> 03:28:02,959
interface because the easiest way to understand\xa0\n
2267
03:28:02,959 --> 03:28:11,390
gonna slow down. And we'll have to go change gear\xa0\n
2268
03:28:11,389 --> 03:28:17,449
gonna implement a vehicle from a car and you guys\xa0\n
2269
03:28:17,449 --> 03:28:22,459
and then I'm gonna add a attribute. Now, any\xa0\n
2270
03:28:22,459 --> 03:28:26,840
whatever you guys want to call them, they have\xa0\n
2271
03:28:26,840 --> 03:28:31,369
in the last video, but final means that it's\xa0\n
2272
03:28:31,369 --> 03:28:37,760
we can't change this value. So I'm going\xa0\n
2273
03:28:37,760 --> 03:28:43,550
just say five. Okay, actually, or let's just go\xa0\n
2274
03:28:43,549 --> 03:28:47,899
saying that each thing we're using is going to\xa0\n
2275
03:28:47,898 --> 03:28:53,958
interviews equals five, that still works, but it's\xa0\n
2276
03:28:53,959 --> 03:28:57,709
so just make sure whatever you're doing\xa0\n
2277
03:28:57,709 --> 03:29:02,060
to have like variables or whatever that you\xa0\n
2278
03:29:02,059 --> 03:29:06,769
they must be final. Okay. So right now, we've\xa0\n
2279
03:29:06,770 --> 03:29:11,810
which is just called gears. Okay, so how do we\xa0\n
2280
03:29:11,809 --> 03:29:17,719
that work? Well, the way we use it is we've typed\xa0\n
2281
03:29:17,719 --> 03:29:23,569
and then the name of the interface in this case,\xa0\n
2282
03:29:23,568 --> 03:29:26,629
getting a red line, we're getting an error.\xa0\n
2283
03:29:26,629 --> 03:29:31,998
implement it but car saying the type car must\xa0\n
2284
03:29:31,998 --> 03:29:37,969
so that means that since we've defined these three\xa0\n
2285
03:29:37,969 --> 03:29:44,448
we have to define them inside our car class. So\xa0\n
2286
03:29:44,449 --> 03:29:49,519
one of the interfaces, we have to define them,\xa0\n
2287
03:29:49,520 --> 03:29:53,450
And if we call them well, we have no idea what\xa0\n
2288
03:29:53,449 --> 03:29:57,590
right? So we're gonna have to create a void\xa0\n
2289
03:29:57,590 --> 03:30:06,290
void Change was calling viewers or gear.\xa0\n
2290
03:30:06,290 --> 03:30:12,380
and then it's gonna have to take one parameter. In\xa0\n
2291
03:30:12,379 --> 03:30:16,369
gear do we want to change? Okay? And then we're\xa0\n
2292
03:30:16,370 --> 03:30:24,260
private int gear, because we're going to define\xa0\n
2293
03:30:24,260 --> 03:30:29,150
so now we're gonna go to and make another the\xa0\n
2294
03:30:29,149 --> 03:30:35,808
we need speed up. So we'll say public void speed\xa0\n
2295
03:30:35,809 --> 03:30:40,581
speed are actually not speed, we're going to go\xa0\n
2296
03:30:40,579 --> 03:30:48,260
by, and then we'll do one more. So public void,\xa0\n
2297
03:30:48,260 --> 03:30:55,969
change. And there we go. So this now we're getting\xa0\n
2298
03:30:55,969 --> 03:31:00,409
methods that were abstract over here. Okay, now,\xa0\n
2299
03:31:00,409 --> 03:31:04,549
just like, if we wanted to use it, we could,\xa0\n
2300
03:31:04,549 --> 03:31:10,190
I'm actually gonna create another private int, I'm\xa0\n
2301
03:31:10,190 --> 03:31:15,110
now is I'm going to just just fill up these,\xa0\n
2302
03:31:15,110 --> 03:31:21,079
say when we change gear, we're just gonna say,\xa0\n
2303
03:31:21,079 --> 03:31:30,709
it to. And then for speed, I'm gonna say, this\xa0\n
2304
03:31:30,709 --> 03:31:40,219
and then down here, we'll say this speed minus\xa0\n
2305
03:31:40,219 --> 03:31:44,269
now what we're gonna do is we're actually just\xa0\n
2306
03:31:44,270 --> 03:31:49,550
works. So we've implemented the things we need to\xa0\n
2307
03:31:51,139 --> 03:31:53,930
going to do is we're going to just create another\xa0\n
2308
03:31:53,930 --> 03:32:00,920
like a display method so that we can display our\xa0\n
2309
03:32:00,920 --> 03:32:05,239
And inside of here, I'm just going to print out a\xa0\n
2310
03:32:05,239 --> 03:32:14,360
print, ln, and in this case, we'll just say, I am\xa0\n
2311
03:32:14,360 --> 03:32:22,940
let's say going and how fast we going we're going\xa0\n
2312
03:32:22,940 --> 03:32:31,145
little kilometers per hour, so let's do that. And\xa0\n
2313
03:32:31,146 --> 03:32:40,221
is. So this stuff stuck here. Perfect. Okay,\xa0\n
2314
03:32:40,220 --> 03:32:45,260
interface vehicle, okay, and we have our car. So\xa0\n
2315
03:32:45,260 --> 03:32:56,329
objects, we'll say car. I don't know, let's say,\xa0\n
2316
03:32:56,329 --> 03:33:03,890
what we're gonna do is we're gonna say car dot.\xa0\n
2317
03:33:03,890 --> 03:33:08,539
up, and let's maybe change it to 10, we'll add 10\xa0\n
2318
03:33:08,540 --> 03:33:13,550
have to make this speed default at like zero, and\xa0\n
2319
03:33:13,549 --> 03:33:18,049
Otherwise, you're gonna run into an air arshi\xa0\n
2320
03:33:18,049 --> 03:33:24,709
Can you just change that to one? Okay, perfect.\xa0\n
2321
03:33:24,709 --> 03:33:29,930
gear, and let's just change the gear to Okay. And\xa0\n
2322
03:33:29,931 --> 03:33:36,471
Ford dot display. Perfect. Okay, so let's run this\xa0\n
2323
03:33:36,469 --> 03:33:42,319
am a cargo in 10 kilometers an hour, and I am in\xa0\n
2324
03:33:42,319 --> 03:33:47,119
implemented all that stuff from our interface\xa0\n
2325
03:33:47,120 --> 03:33:52,820
some cool things, we can add into our interfaces\xa0\n
2326
03:33:52,819 --> 03:33:57,170
example, you've used a bunch of interfaces with\xa0\n
2327
03:33:57,170 --> 03:34:02,420
And now what you want to do is you want to add a\xa0\n
2328
03:34:02,420 --> 03:34:05,720
from it, well, what you could do is you could do\xa0\n
2329
03:34:05,720 --> 03:34:09,860
like this. And then you could go into every single\xa0\n
2330
03:34:09,860 --> 03:34:14,210
be whatever you want. But if you want the method\xa0\n
2331
03:34:14,209 --> 03:34:20,029
use something this is why interfaces are kind of\xa0\n
2332
03:34:20,030 --> 03:34:24,200
and then maybe in this case, void, and let's just\xa0\n
2333
03:34:24,200 --> 03:34:29,900
just to make it easy. What we'll do here is we'll\xa0\n
2334
03:34:29,899 --> 03:34:36,590
this from any of the classes that inherit our,\xa0\n
2335
03:34:36,591 --> 03:34:48,771
say system, dot out dot print, ln, in this case,\xa0\n
2336
03:34:48,771 --> 03:34:56,841
creative. How did I just spell system? And I okay,\xa0\n
2337
03:34:56,841 --> 03:35:02,450
System dot out dot print ln default method.\xa0\n
2338
03:35:02,450 --> 03:35:07,190
this car class, we can use that default method.\xa0\n
2339
03:35:07,190 --> 03:35:15,380
then we want to do the default, what we could do,\xa0\n
2340
03:35:15,380 --> 03:35:21,050
that actually works fine. So now that we have out\xa0\n
2341
03:35:21,050 --> 03:35:26,150
and we implemented, let's see what happens when we\xa0\n
2342
03:35:26,149 --> 03:35:31,940
our gear two, and then says default method. It's\xa0\n
2343
03:35:31,940 --> 03:35:37,610
of our interface. Now, I believe we can actually\xa0\n
2344
03:35:37,610 --> 03:35:44,810
as something that's not a static method, because\xa0\n
2345
03:35:44,810 --> 03:35:50,120
we can actually create static methods within our\xa0\n
2346
03:35:50,120 --> 03:35:53,240
Like, we don't have to have an instance to\xa0\n
2347
03:35:53,239 --> 03:35:58,100
just follow along for a second, as I'm going to\xa0\n
2348
03:35:58,101 --> 03:36:04,641
int, let's return something, let's change it up.\xa0\n
2349
03:36:04,640 --> 03:36:11,001
a keyword. And that's fine, we'll just do math.\xa0\n
2350
03:36:11,001 --> 03:36:17,181
do is we're just gonna return b plus not okay. I\xa0\n
2351
03:36:17,181 --> 03:36:22,400
just to prove a point. So now, saying, I'm in\xa0\n
2352
03:36:22,399 --> 03:36:28,639
we don't create a car object. And I want to use\xa0\n
2353
03:36:28,640 --> 03:36:34,880
what I can do is I can do vehicle, dot, and then\xa0\n
2354
03:36:34,880 --> 03:36:40,430
up here, this method dot math, give it a value,\xa0\n
2355
03:36:40,431 --> 03:36:46,560
variable. So we'll say x equals that. And then\xa0\n
2356
03:36:46,559 --> 03:36:52,379
actually getting as a value. In this case,\xa0\n
2357
03:36:52,379 --> 03:36:58,319
there we go. So let's see, you can create a static\xa0\n
2358
03:36:58,319 --> 03:37:02,279
you can kind of think of these as functions.\xa0\n
2359
03:37:02,280 --> 03:37:07,349
I'll just do one as an example. Because this is\xa0\n
2360
03:37:07,350 --> 03:37:14,521
call this math, okay, then inside here, you could\xa0\n
2361
03:37:14,521 --> 03:37:19,140
math operations for you. Like maybe you have the\xa0\n
2362
03:37:19,139 --> 03:37:23,610
like Euclidean distance, I don't know a bunch of\xa0\n
2363
03:37:23,610 --> 03:37:28,290
interface. And then when you want to access them,\xa0\n
2364
03:37:28,290 --> 03:37:34,530
dot maybe like square root like sq. RT, okay. And\xa0\n
2365
03:37:34,530 --> 03:37:39,750
I want to call functions, but they're really\xa0\n
2366
03:37:39,750 --> 03:37:44,010
easily. So that is a really good example\xa0\n
2367
03:37:47,359 --> 03:37:53,119
Now, enums are pretty much a collection of\xa0\n
2368
03:37:53,119 --> 03:37:57,739
can do things with those constants. And they\xa0\n
2369
03:37:57,738 --> 03:38:02,597
readable. And yeah, you guys will see when we\xa0\n
2370
03:38:02,599 --> 03:38:06,950
create an email. Now to do that it's similar to\xa0\n
2371
03:38:06,949 --> 03:38:12,019
go to your package, right click, we're gonna\xa0\n
2372
03:38:12,020 --> 03:38:18,620
going to name mine. Actually, I'm just gonna name\xa0\n
2373
03:38:18,619 --> 03:38:24,259
for this example. So again, the syntax here is\xa0\n
2374
03:38:24,259 --> 03:38:29,509
interface or whatever, right? So in here is where\xa0\n
2375
03:38:29,509 --> 03:38:34,638
this is really useful, because we don't have to\xa0\n
2376
03:38:34,638 --> 03:38:38,418
like we can literally just type whatever value\xa0\n
2377
03:38:38,418 --> 03:38:41,988
it's a string. So in my case, I'm going to\xa0\n
2378
03:38:41,988 --> 03:38:48,259
you don't have to go all caps, we're gonna\xa0\n
2379
03:38:48,259 --> 03:38:54,229
are the three constants, I'm going to store in my\xa0\n
2380
03:38:54,228 --> 03:38:58,757
that's literally all I'm going to do right now,\xa0\n
2381
03:38:58,759 --> 03:39:02,388
that we can reference from level and these are\xa0\n
2382
03:39:02,388 --> 03:39:06,168
you want. And just keep going with commas on and\xa0\n
2383
03:39:06,168 --> 03:39:10,759
It just makes them more readable if you do them.\xa0\n
2384
03:39:10,759 --> 03:39:14,838
now I'm going to show you how we can actually use\xa0\n
2385
03:39:14,838 --> 03:39:19,279
works. So to use this enum, we have to create a\xa0\n
2386
03:39:19,279 --> 03:39:28,879
say level, and we'll say LBL equals new. Actually,\xa0\n
2387
03:39:28,879 --> 03:39:34,338
say a high, low and medium. So my guess we'll just\xa0\n
2388
03:39:34,338 --> 03:39:40,520
can see it's all showing up in different colors.\xa0\n
2389
03:39:40,520 --> 03:39:46,969
as a constant, we can do certain things with it,\xa0\n
2390
03:39:46,968 --> 03:39:52,399
value your constant is like what value is levels.\xa0\n
2391
03:39:52,398 --> 03:40:00,558
like so. So I say like if elvio equals equals and\xa0\n
2392
03:40:00,559 --> 03:40:09,260
I guess. And we'll just work our way up to high. I\xa0\n
2393
03:40:09,260 --> 03:40:16,281
equals, and then level dots and medium. Okay,\xa0\n
2394
03:40:16,280 --> 03:40:21,710
else, because if it's not lower medium, it must\xa0\n
2395
03:40:21,709 --> 03:40:27,259
we'll just say system dot out, dot print, ln.\xa0\n
2396
03:40:27,260 --> 03:40:33,409
because I want to show what this does. Okay?\xa0\n
2397
03:40:34,879 --> 03:40:38,060
now we're just printing level each time. And\xa0\n
2398
03:40:38,060 --> 03:40:43,581
happens. So you see, we get low. So when we print\xa0\n
2399
03:40:43,579 --> 03:40:50,360
whatever the constant is that we have. And that's\xa0\n
2400
03:40:50,360 --> 03:40:54,290
So we can convert these into a string. And I'll\xa0\n
2401
03:40:54,290 --> 03:40:58,670
say we wanted to get this because right now like,\xa0\n
2402
03:40:58,670 --> 03:41:03,049
we don't really know what type it is, it's just\xa0\n
2403
03:41:03,049 --> 03:41:06,799
get this as a string value, if we wanted to do\xa0\n
2404
03:41:07,310 --> 03:41:16,520
string. So if I say string, we'll say E. Yen,\xa0\n
2405
03:41:16,521 --> 03:41:20,811
string. And that's just going to convert this to\xa0\n
2406
03:41:20,810 --> 03:41:25,789
operations or whatnot with that. All right, so\xa0\n
2407
03:41:25,790 --> 03:41:30,590
thing that you notice is we actually get all the\xa0\n
2408
03:41:30,590 --> 03:41:38,329
screen. So where do system dot out? dot print ln.\xa0\n
2409
03:41:38,329 --> 03:41:44,959
dot values. Yes, there we are. So we go level dot\xa0\n
2410
03:41:44,959 --> 03:41:50,419
you're going to see when we run this, now, it\xa0\n
2411
03:41:50,420 --> 03:41:54,441
the values. So when we try to print that we're\xa0\n
2412
03:41:54,440 --> 03:41:58,040
it. So once we have these values, so I'm actually\xa0\n
2413
03:41:58,040 --> 03:42:03,680
then iterate through it and print them out. What\xa0\n
2414
03:42:03,680 --> 03:42:10,820
is the way you have to do it, let's say arr is\xa0\n
2415
03:42:10,819 --> 03:42:14,449
working fine. So what we're gonna do now is we'll\xa0\n
2416
03:42:14,450 --> 03:42:21,500
how we can loop through all the different values.\xa0\n
2417
03:42:21,500 --> 03:42:33,709
level E, and then we'll say, in ARR, what we'll do\xa0\n
2418
03:42:33,709 --> 03:42:37,759
print out E, and then we can see all the different\xa0\n
2419
03:42:37,760 --> 03:42:41,570
here, and you see we get high, medium, low, and\xa0\n
2420
03:42:41,569 --> 03:42:45,978
doing this if statement here, okay. And that's how\xa0\n
2421
03:42:45,978 --> 03:42:50,179
that's really cool. But you might say, Okay, well,\xa0\n
2422
03:42:50,180 --> 03:42:54,590
Like we just have these constants? Well, there's\xa0\n
2423
03:42:54,590 --> 03:42:59,870
you know, add some methods, and some instructors\xa0\n
2424
03:42:59,870 --> 03:43:05,030
to certain values, kind of similar to like a hash\xa0\n
2425
03:43:05,030 --> 03:43:10,309
way that we can do that is we need to create first\xa0\n
2426
03:43:10,309 --> 03:43:19,430
in this case, I'm going to say private, and I'll\xa0\n
2427
03:43:19,430 --> 03:43:24,440
is going to just be a private value, that's just\xa0\n
2428
03:43:24,439 --> 03:43:29,960
low, medium, high value of all these levels.\xa0\n
2429
03:43:29,959 --> 03:43:34,429
we need to create a constructor for our IEM. And\xa0\n
2430
03:43:34,430 --> 03:43:45,170
gonna say public level in and then none. Okay? And\xa0\n
2431
03:43:45,170 --> 03:43:51,020
modifiers legal modifier for short only private\xa0\n
2432
03:43:51,020 --> 03:43:55,281
sorry, my bad private, because we're just gonna\xa0\n
2433
03:43:55,280 --> 03:44:03,170
level int num, and we're just gonna say this dot\xa0\n
2434
03:44:03,170 --> 03:44:07,879
now what I can actually do is you see how these\xa0\n
2435
03:44:07,879 --> 03:44:12,709
constructor, that means we're going to define\xa0\n
2436
03:44:12,709 --> 03:44:18,438
for the enough. So I'm going to put brackets here\xa0\n
2437
03:44:18,439 --> 03:44:24,200
two as low as one. Now, what this is going to do\xa0\n
2438
03:44:24,200 --> 03:44:30,939
medium and low. But when we create a new constant,\xa0\n
2439
03:44:30,939 --> 03:44:35,979
and it's going to set this level non equal to\xa0\n
2440
03:44:35,978 --> 03:44:40,750
this case, 321, we could obviously have multiple,\xa0\n
2441
03:44:40,750 --> 03:44:45,670
multiple arguments here and we can have a ton of\xa0\n
2442
03:44:45,670 --> 03:44:51,908
since this value is private, we're going to need a\xa0\n
2443
03:44:51,908 --> 03:44:55,599
probably where we're gonna want to use it. So that\xa0\n
2444
03:44:55,600 --> 03:45:00,940
will change that level num and to get that level\xa0\n
2445
03:45:00,939 --> 03:45:09,158
I don't think I can do a public. Eye we'll see\xa0\n
2446
03:45:09,158 --> 03:45:15,430
we'll simply return. Guess it's gonna need to be\xa0\n
2447
03:45:15,430 --> 03:45:22,840
this dot, LDL num. Okay, yeah, so that does work\xa0\n
2448
03:45:22,840 --> 03:45:29,049
so this is just going to give us the level num. If\xa0\n
2449
03:45:29,049 --> 03:45:36,099
What do you call it? level num. What I'm going\xa0\n
2450
03:45:36,100 --> 03:45:43,210
interior it's just gonna be a void. Okay, and all\xa0\n
2451
03:45:43,209 --> 03:45:49,059
num, and then we're gonna put in here, int, num,\xa0\n
2452
03:45:49,059 --> 03:45:54,459
a way to not only get the level num, but to change\xa0\n
2453
03:45:54,459 --> 03:45:57,879
and see how this works. So I'm just going to get\xa0\n
2454
03:45:57,879 --> 03:46:04,238
right now. So right now we have our level and it's\xa0\n
2455
03:46:04,238 --> 03:46:10,090
this level, we can use something called get value\xa0\n
2456
03:46:10,090 --> 03:46:17,260
in this case, I'm going to say get level. So what\xa0\n
2457
03:46:17,260 --> 03:46:24,158
and in here, we'll say elvio. dot. And then what\xa0\n
2458
03:46:24,158 --> 03:46:28,299
So now if we print this out to the screen,\xa0\n
2459
03:46:28,299 --> 03:46:34,719
we're getting one. So now I'll show you this\xa0\n
2460
03:46:34,719 --> 03:46:39,250
x value ever get value? I'm not sure we'll see. So\xa0\n
2461
03:46:39,250 --> 03:46:45,578
dot value of Yes, that is exactly what it is. And\xa0\n
2462
03:46:45,578 --> 03:46:54,549
so in this case, we could say, low, it's gonna\xa0\n
2463
03:46:54,549 --> 03:46:58,389
so the issue is, I just got to put this in string,\xa0\n
2464
03:46:58,389 --> 03:47:02,739
value of and say I put a string in here. So like,\xa0\n
2465
03:47:02,738 --> 03:47:06,879
and they type in a string, right, and you want\xa0\n
2466
03:47:06,879 --> 03:47:11,318
actually going to get is we get low, right?\xa0\n
2467
03:47:11,318 --> 03:47:16,478
In the enum. Although it's not a string, it\xa0\n
2468
03:47:16,478 --> 03:47:19,929
value of is used for, I can't really give you\xa0\n
2469
03:47:19,930 --> 03:47:24,190
know any good examples of using value of but\xa0\n
2470
03:47:24,189 --> 03:47:29,199
I figured I would show it to you. So I guess we\xa0\n
2471
03:47:29,199 --> 03:47:35,199
to make sure that all that is working, say elvio\xa0\n
2472
03:47:35,199 --> 03:47:41,349
And then let's just grab this again, actually.\xa0\n
2473
03:47:41,350 --> 03:47:48,489
just simply going to print out, record elvio dot\xa0\n
2474
03:47:48,488 --> 03:47:54,340
changing and working fine. And there we go,\xa0\n
2475
03:47:54,340 --> 03:47:58,930
use itams. Pretty much they're used for when you\xa0\n
2476
03:47:58,930 --> 03:48:02,530
maybe you want to loop through, see what those\xa0\n
2477
03:48:02,529 --> 03:48:07,149
readable, right? So we have level dot low, and\xa0\n
2478
03:48:07,148 --> 03:48:11,709
whatever. And that's all stored within our enum\xa0\n
2479
03:48:11,709 --> 03:48:15,250
as you want and you'll really see the use of\xa0\n
2480
03:48:15,250 --> 03:48:20,109
like larger programs. Okay, so anyways, that has\xa0\n
2481
03:48:20,109 --> 03:48:23,619
make sure you leave a like and subscribe\xa0\n
222406
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.