All language subtitles for 006 Quidditch Game – Part 3_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

The solution is going to cover part three where we start setting up the game class.

We'll start by defining the scoreboard field, a scoreboard needs to monitor the score of each team.

So we're going to use a Hashmat because there's parity between team and integer data.

Private Hashmat.

The Hashmat is going to store team manager key value entries and it's going to be called scoreboard.

The next step is to create a constructor, the constructor runs as soon as we create an object of the

game class and when it runs, it will receive two parameters the home team and the away team.

Now, inside, the constructor will set the scoreboard equal to a new object of the Hashmat class.

And then I'm going to put two entries into the scoreboard.

A home team that starts with a score of zero.

And an away team that starts with a score of zero and now notice that I'm adding copies of each parameter

to the Hashmat.

That's because you don't want your keys to share the same reference as the outside variable that's being

passed in.

Otherwise, the set of each key can be affected if you change the outside variable, which is a security

leak.

You know what?

Why don't I just show you really quickly instead of passing in copies, I'll pass in each parameter

directly and I'll create a new object of the game class using the format.

I left you all and learn the parts.

OK, they're both of type team.

Now we're going to pass into a new object of the game class.

A lot of breakpoint.

Step inside.

And check it out, each key has the same reference as the outside variable that was passed in as a parameter.

If I update one of the objects, I'll change the house name for whom?

Restart the debugger.

The state of the key should get affected as well.

That's not good.

But if the constructor creates copies of each parameter, we can rest assured that each key store is

a unique reference that points to a team copy.

You can feel free to test that out yourself and monitor the references, but I'm going to move on enough

about that.

Now we want to create two getters, we'll start with the Geter get score.

Which receives one parameter.

The team who score you want to get.

We'll get the score for this particular team.

And it's going to get the score value for this particular team or will it we'll come back to this now.

We are a center that updates the score for a particular team.

It's going to be called set score and receive two parameters, the team for which you want to update

the score.

And the score itself.

Then you can say scoreboard put.

The following key value pair.

Now, we're going to quality control this center later, because put either can add this as another

entry in the hash map or it can update the entry that already contains this time object.

Obviously, we want to update because the hash map should only have two entries.

So for now, let's move on.

Now we're going to to get her called get team that receives a parameter string name.

We'll come back to this in the next video for now, just return null.

And now you might be asking, should there be a set team setter, no.

It's impossible to update a key after you add it, you can remove a key and then add another one, but

you cannot change a key.

It's not possible.

All right, we're going to wrap up this video by testing the getters and setters, I'll get the score

for Gryffindor.

I'll set the score for Gryffindor to 10.

Spoiler alert, none of these should work, so here's why I'm going out to break points.

I'll step in to get score.

The parameter we passed in has this reference which doesn't match any of the references in the hash

map.

And unless you define an equals method, Java uses the default equals method to compare to objects,

which is why I can't find anything in the Hashmat that matches the parameter and returns no.

Is that really the issue?

We'll find out soon enough.

Now, what would happen here, once again, the reference being passed and doesn't match any of the

references in the Hashmat.

So instead of updating the entry that already contains this theme object, it's going to think it's

a new key and add another entry to the hash map and that's also not good.

Java's using the default equals method to compare team objects.

So we need to provide our own equals method that allows Java to compare to objects based on their fields,

not the reference.

The equals method needs to return a boolean.

And receives an object.

What's the type of that object?

We don't know, it can be any object.

First, we're going to check if the object that we're comparing against is no, because if it happens

to be null, then there's no way it equals the object that's calling this method.

Let's assume the object, is it?

No.

Then we need to check if it isn't of type team if the object isn't an instance of the team class.

OK, so at this point, the object, is it no, it is an instance of team, so we can typecast it to

type team.

And finally, we need to check if the objects fields are equal to the current object that's calling

this method, we need to compare the house return.

This thought house equals timecode house.

We need to compare the keeper.

This storekeeper equals team goalkeeper.

And how do we compare the array, remember, we can use arrays not to string.

The new string is going to convert the contents of the array into one long string, and so if the two

happened to share the same string, then they must have the same elements.

And that's a.

And so now I guess it should work.

Let's run the code.

And it still doesn't work.

Hmm, well, test out the setar.

Same thing.

I'm pretty sure we defined our equals method perfectly.

It compares to objects based on their fields.

Those two objects, one hundred percent have the same fields.

So why isn't Hashmat able to retrieve the key?

For Hashmat to retrieve a key, it's not enough for an object to be equal to it.

It must also share the same hash code.

You're going to learn more about hash codes in the next video.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.