All language subtitles for 004 Shopping Cart – 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

There are two more classes we need to write up in this video.

We'll do the shopping cart.

The shopping cart is identified by the items that it carries and the number of items can increase or

decrease in the shopping cart.

So right there, we know we need to make an array list that can store item objects.

And as always, if a class has failed, you need to apply the big three steps, you need to take instructor,

a getter and a setter.

The instructor is public shares the same name as a class.

And it receives no parameters because in the beginning, your card is going to be empty, we're just

going to set the field equal to a new era list that can store item objects.

OK, now we want to get her there, receives a one parameter.

The index of the item object they're trying to access.

And this letter is going to return a new copy of the item object at the request that inducts.

Now, we went out a centre that receives two parameters.

The index of the element you want to update.

And an item object that we're going to update the element with.

Then we're going to get the element at the requested index.

And set it equal to a new copy of the item object being Pastan.

And that's all for the big three steps, if you feel like it's getting repetitive, then that's good.

It means you're getting the hang of it.

Now we're going to add actions.

One thing we can do is add an item to the card.

So all credit boolean method named ADD it receives one parameter and item object.

And the duck comment tells us we can add an item only if it wasn't already added, I'm going to ignore

this condition for now.

I'll come back to it at the end.

For now, I'm just going to add the item to the items list.

And return true.

The next action that it can perform is to remove an item from a cart.

This method is void called remove, and it receives one parameter, the name of the item you want to

remove.

So what we'll do is create a far loop that runs through the size of the array list.

And inside the loop, we're going to get the item object at every index I.

We'll get the name field of that item and we'll check if it equals the name of the item, though, as

Pastan.

And if that's the case, then we're going to remove that item from the array list.

The last method is check out this one return to string that resembles a receipt.

And the receipt needs to include three things, the subtotal, which means the price before tax, the

tax they have to pay and the total.

And instead of creating three separate variables, I'd rather create an array with ALENKA three.

And so the idea is that the first element is going to be the subtotal, the second element, the tax

and the third element is going to be the total.

So during each run, I'm going to update the first element, the subtotal and add to the price of the

item inside the cart.

So that should give us the price of every item before tax, the tax rate is 13 percent.

So we'll set the second element equal to the first one.

Times point one three.

And now the total is equal to the subtotal plus the tax, so we'll set the third element equal to the

subtotal plus tax.

All right, now we have the total subtotal end tax so we can return a receipt, just copy over the format

from the article.

And replace the placeholder is where we need to.

Kate, now our final task before we can test our code is add it to string method that returns a nicely

formatted string of every item inside the cart.

As always, public string to string.

I'm going to create a string named temp for temporary.

It's going to be an empty string for now and we'll just return it's.

First, don't create a loop that runs through the size of the array list.

And during each run, I'm going to get the two string of the item object at the index eye and I'm going

to add the string to the temp variable that we're returning.

And after adding the two string of an item, I'm only going to add one line to separate it from the

next two string that gets added.

OK, now we're going to test our code before we do anything else.

I'll have to create a shopping cart object inside Main.

I'm going to add four items to the shopping cart, so I'll go back to the article, I'll copy them over.

And print the cards.

And by printing the cart, it prints a nicely formatted string of every item inside the cart, but it

seems we added the salary twice for our purposes.

We only want to allow the user to put one of each item.

We can't have any duplicates.

Well, thankfully, every aerialist has a contained method, the method receives an object, it returns

true if one of the elements inside the array list equals the object they were passing in.

So what I'm going to do is check if the items array list already contains the item being Pastan.

Then I'm going to return false.

Otherwise, the item will get added and will return true.

And now you might think, OK, we're good contains is going to behave exactly like we want it to.

It's going to check if the array list already contains an object before adding it.

Yeah, let's run the code and see what happens.

First, it adds the celery, OK, that's fine.

But then we get the exact same Sellery object, its fields are identical to the one already in the array

list, the array list and our eyes already contains that object.

But it gets added anyway, so why isn't this condition evaluating to true, why doesn't it recognize

that the array list already contains a salary object?

The short answer is we need to help the contains method achieve its goal.

So before we move on to part four, you need to learn about the equals method.

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