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
All right, we've set up our classes now we need to inject some logic into them.
Going back to requirements, talked text, and from first glance, it seems that we need to force every
child the class to override two common methods.
Deposit and withdraw.
And to do that, we need to define two abstract methods inside the parent class.
So we'll go to account Java.
And here we'll see.
Public.
Abstract void, and it will deposit some amount of money, double amounts.
Now, a withdrawal can be successful or it can fail.
So here we'll say public.
Abstract bullying.
That can withdraw some amount of money.
All right, and as we override, deposit and withdraw, we need to define this protected method inside
of account Java.
Remember, that protected means this method is only accessible from within its children.
It's not public, which means you can't access it from anywhere.
It's protected only child.
The classes, checking savings and loan can access the ruined method.
Anyways, we seem to be getting an error.
OK, got an important decimal format before we can use it, and we're good.
And now remember that if a parent defines an abstract method, the child class is forced to override
it.
So we'll go to checking.
That's why we're seeing these errors.
Checking needs to provide its own logic for deposit and withdraw.
OK, so I'll just override them for now.
We won't provide any logic just yet.
Not until we write unit tests.
Checking we'll do the same thing for savings.
And.
Merge doing that to get rid of the areas for now.
Now, the reason I'm not writing the logic just yet is because we need to unit test all of the behavior
inside of the requirements that text filed before we write the code for it.
That way, we make sure that any code we write, any logic we provide doesn't have any bugs.
So long as every test passes, we know that we're good.
So I'll go to a count tests that Java and I'll start by on commenting the accounts array.
And that doesn't seem to be like a good amount of indentation, so I'll fix that and import the accounts
class.
And now, before running each test, we got to make sure the array is being populated first, so we'll
start by annotating a method with before this before method is going to run before each test.
Public void setup.
Where we set up our accounts are by going back over to learn the parts and populating it with three
objects.
Checking.
Savings.
That did not work.
And loan.
OK, perfect.
We're going to start by unit testing the behavior for withdrawing.
We want to make sure the correct amount gets withdrawn from the checking account under normal circumstances.
So what we'll do is create a unit test.
Public void would draw.
And what we need to do is withdraw from the checking account that's at index zero.
So accounts.
At Index zero, that would draw.
And we're going to withdraw 14 40.
Then we'll make an assertion assert equals.
The assertion expects eighty four point five one after we get the account balance accounts out of like
zero dark get balance.
So instead of checking, not Java.
We'll update the current balance, SuperDart set balance.
By minus thing, the amount from the current balance.
All right, and before we run our tests, let's just return true by default.
We'll address that later on.
Now we can run our test and see if it works.
And it still fails, and it seems like the value is off by decimal points, because this is money,
we're going to round to two decimal points.
So what we can do is call the protected method super dot around.
Right over here.
Rerun your test.
And perfect.
OK, now looking back at the requirements, now we're going to unit test this behavior.
The checking account charges an overdraft fee of five dollars and fifty cents if the amount being withdrawn
exceeds the account balance.
So we want to make sure this overdraft fee gets deducted if they try to withdraw more than what's in
their balance.
So back here?
We'll create another unit tests.
Test.
And the unit test will be called overdraft public void overdraft.
And we need to withdraw from the checking account and index zero.
So we'll say accounts and index zero, that would draw.
And we'll be withdrawing fifteen thirty four point forty three.
And then here we'll make an assertion will assert equals.
The expected value is negative $15 and 42 cents after we get the account's balance accounts at index
zero, don't get balance.
Run the test, and it obviously should fail.
Now we can write code to make it pass.
So back in checking.
We'll see if.
The current balance to get balance minus the amount being withdrawn.
Smaller than zero.
Then we'll update the current balance, super accept balance, super tight get balance.
Minus amounts.
Minus five dollars and fifty cents.
But hold on a second.
This seems like a pretty important value.
So it'd be safer to use a constant tear instead.
So what I'll do is I'll declare a private.
Static final double overdraft fee.
Is equal to five dollars and fifty cents.
And will use that constant instead.
Because there's no risk of accidentally changing a constant.
All right, and in the event that this if statement gets executed, we want to break the entire function
by returning crew here because obviously you don't want this to run.
And then that's true and that will just mess everything up.
So we'll go back to account tests, run the test.
And once again, with doubles, we got the issue of having way too many decimal points, we're dealing
with money, so we went around to two decimal places.
So over here.
And checking, we'll have to call SuperDart around.
We were on the test.
OK.
Back door requirements, that text will a unit test this behavior?
We want to make sure that withdrawal doesn't happen if the amount surpasses the overdraft limit.
So we'll create a unit test.
Public.
Void.
Overdraft limit.
Inside, I'm going to withdraw.
Seventeen twenty six from the checking accounts.
And then we're going to assert that the resulting balance shouldn't change, it should remain.
Uh, fifteen twenty four point five one.
When we get the account balance accounts, zero, don't get balance.
OK.
Run the test.
And it fails.
Now we just got to write code to make it pass.
Back here, we'll check if the current balance.
If super don't get balance minus amounts.
Is smaller than negative 200, then well, wait a second.
This seems like an important value, and it would be safer once again to use a constant here instead.
So we'll declare a private static.
Final double.
Constant named overdraft limit equal to $200.
And we'll say if superdog, that balance minus amount is smaller than the overdraft limit.
Then we'll just return false.
That will break the entire function.
Let's make this an if.
And you know what?
Let's just create a chain of if else.
That looks a lot better to me.
All right.
We can rerun our test.
And that works perfect.
All right, back here, the next piece of behavior we're going to unit test is the withdrawal fee.
We want to make sure that it's charged a $5 fee if they attempt to withdraw from a savings account.
So we'll create a unit test.
Test.
Public void, withdrawal fee.
And we're going to withdraw $100 from the savings accounts, accounts and index one.
Well, withdraw $100.
And then we're going to make an assertion that the resulting balance is twenty one hundred thirty six
dollars point sixty cents as we get the current balance for the savings account.
Count that index one, don't get balance.
All right.
Run the test.
And it fails.
Now we just got to write code to make it past so inside the redraw method for savings.
We'll update the balance super set balance.
We'll get the current balance, super Typekit balance.
Minus the amount.
Minus $5.
Once again, $5, it seems like an important value, so we're going to declare it as a constant here,
we'll say private static.
Final double.
What drove the.
Is equal to $5.
And here we'll use a constant instead.
And, as always, will around to two decimal places.
And return true to indicate that the withdrawal was successful.
Now, usually in a savings account, you shouldn't be able to make a withdrawal that exceeds your balance.
But it didn't say anything in the requirements tax.
So whatever in the Java world, we're going to permit it.
Run the test.
And it passes.
All right, we're going to continue with the remaining tasks in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.