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
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
Russian
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
The solution is going to cover part four.
We're going to come back to this test case, but the next one tells us to make sure we calculate the
correct subtotal.
So I'm going to write a unit test named subtotal as valid.
Each item in the cart is one ninety nine.
So our unit test is going to assert the price we're expecting 398.
Is equal to the price that gets returned by cart, get subtotal.
And now inside C�rdova write code to make the test fail.
I'll define a function that returns a double named get subtotal.
And for now, we'll return a random number.
Our test fails, that's fine, let's write code to make it pass.
Inside, get subtotal, I'm going to add a temporary double subtotal variable.
And then create a loop that runs through the size of the array list.
And during each run, I'm going to add the price of each item to the subtotal.
And then return the subtotal.
If we run our test now, it works, the assertion passes.
But can get subtotal be any simpler, yes, loops are messy, you should always favor running the Israelis
through a pipeline of functions.
You learned about the intermediate operation map map updates every element in the sequence.
But map to double, expect you to update every element in the sequence with a double value just like
map and expect to lambda expression, the Lambda receives each element in the sequence as a parameter.
And for each element, we're going to return the price.
So at this point in the pipeline, our stream is full of double values.
More specifically, we have a double stream and every double stream is capable of calling the terminal
operations some.
Some is a terminal operation because it ends the pipeline and it returns the final results.
In this case, it's going to return the sum of every price in the double stream.
And to me, this looks a lot better than before.
And as always, as you refactor run, the unit has to make sure there aren't any bugs and there aren't
any.
Now we ask ourselves the same question, can the code be refactored and the answer is yes.
If your expression is only a single line, then you can remove the curly brackets as well as the return
keyword.
And Jeff is going to know you intend on returning each double because not to double expects it.
Again, working with lambda expressions really simplifies your code.
We on the unit test and beautiful once again, can the code be refactored?
Nope, we're done.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.