Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
We've now got our double nested for loops put together, so we're iterating over all of the suits and
rings within this list now inside of this body right here, we need to create a new instance of a card
and then put that card into our big list of cards inside the deck.
Now, to create the new card itself, it's going to be pretty straightforward, so to make the card
we can save our card is a new card, very similar to how we've called other constructors or created
new instances of classes before.
But there's one thing I want to mention here, when we create our new card right here, we probably
want to pass in the suit and the rank that we're currently iterating over so that this newly generated
card right here knows what suit and rank it's supposed to represent.
But if you look down at our card class, we have not yet set up a constructor function on this thing.
So if we called new card right here, well, this would definitely work.
But we do not yet have the ability to pass in the given rank and suit of the card.
As a matter of fact, when I add that code in, I'm probably going to end up seeing an error.
Here it is right here.
So too many positional arguments, zero expected, but two found.
So this is complaining and saying, hey, you're passing in the rank in the suit, but the card is not
set up to expect those arguments whatsoever.
So down inside the card, we're going to add a constructor function here as well.
And we're going to make sure that if we pass in the rank and the suit, we take them and initialize
the appropriate properties on our card instance.
Now, this is another thing we did previously just a moment ago with our person class.
So we're going to write out some very similar looking code.
So inside of my card class, I'm going to add on a constructor function.
And then remember the shorthand form that we can use to take some arguments in automatically assign
them to some fields that belong to this class.
So notice that the rink is the first argument here, so I can take that first argument and automatically
assign it to this rank property here by writing this rank.
And then I'll repeat the same process for the suit as well.
So let's say this suit.
So now, whenever we call new card and passing the rank in the suit, those two properties will be automatically
assigned to the relevant fields on the card instant's.
So now we've got the appropriate card created here, and this code right here is going to run 52 times
once for every combination of suit and rank.
Well, for me, not 52, two times.
But you get the idea.
So now that we've created the card, we need to take that card and add it to our list of cards to add
a new element to a list, we can reference the list itself, which is going to be in this case, simply
cards.
Remember, in part, we don't have to say this cards or anything like that.
We optionally can, but we do not have to.
So I'll simply say cards and then to add a new element, I'll say add.
And then I'll pass in the element that I want to add to that list like so.
OK, so this is looking pretty good.
I am going to tell you that there is a very subtle air inside this code right now.
So there's a very small bug.
Let's add in a new main function to this file so that we can test out this new debt class.
And then when we run that code, we're going to see that air kind of a peer or the very subtle bug appear.
And we'll take a quick pause and talk about what's going wrong.
So let's add in the main function at the very top up here.
I'll add in void main.
And I'll just create a new deck by writing out new deck, and then we don't have to actually do anything
with that, I just want to run the constructor function.
OK, so I click on Ron.
And then you're going to notice an error message on the top right up here, it says Dot ad is not a
function.
OK, so like I said, very subtle error in here.
So let's take a quick pause.
We'll come back to the next section and try to figure out exactly why we saw this error message.
So quick break and I'll see you in just a minute.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.