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 goal of this workbook was to quality control the item in machine classes, because if you're on
the out the way it is.
Some of the items have negative prices, negative quantities and blank names.
Once again, these values don't make any sense and the caller should be forbidden from passing them.
So when the item constructor, we're going to start by throwing an illegal argument exception, if the
name is blank, so if name is equal to null.
Or if the name is blank.
Throw new.
A legal argument, exception name cannot be null or blank.
We're going to throw another exception if the price is less than zero, so if the price is less than
zero, there are a new illegal argument exception.
Price cannot be less than zero.
We need to throw another exception if the quantity is less than zero.
In which case will once again throw a new illegal argument, exception quantity cannot be less than
zero.
Katri around the code.
The constructor forbids the caller from passing a legal values.
That's good.
This unchecked exception is forcing us to fix our code.
So we're going to copy over the values from the workbook.
Rerunning, running the app.
And now we're good.
Remember that centers are another place where the color may pass on illegal values, so we need to apply
quality control there as well.
So inside set name right through another illegal argument, exception, if the caller passes a name
that is no or a blank.
There are new legal argument, exception name cannot be null or blank.
We'll do the same thing and set price if the culture passes a price that is less than zero, we'll throw
a new illegal.
Are you an exception?
Price cannot be less than zero.
Last one quantity, if they pass a quantity that is less than zero, throw a new illegal argument,
exception quantity cannot be less than zero.
Kate, now in the machine class, there is no need to throw a legal argument, exceptions in the constructor
again, worst thing that could happen is a null being passed, but the output already throw a null pointer
exception and the same can be said for set item.
But what if the caller passes an invalid index here?
Well, once again, the code would already throw an array index out of bounds exception.
Same thing can be said about the center.
So throwing another exception wouldn't make any sense.
However, we can expect an illegal argument right here.
There's a chance the caller may pass on an item with a quantity of zero.
And in such a case, we need to index the item that they're interested in.
And check if it's quantity is equal to zero.
If that's the case, we need to throw an illegal argument exception.
But says cannot dispense an item with a quantity of zero.
That's all for a legal argument, exceptions.
What about illegal state exceptions?
Well, looking at this class, I can't really think of a scenario when a machine object can call a method
at a bad time.
Basically, the machine object would always be in a valid state to call any of its methods, and that's
really it.
You had to check points to the item in machine and classes, and every checkpoint forbids the caller
from misusing the methods or constructor's.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.