Hello there you beautiful people.
And in this video we're going to make a bank.
We won't introduce anything new here really but it's nice to have a fresh example you know away from
all those coins to help all those complicated concepts from object oriented programming to stick in
your mind so you can see it a fresh.
Now the way that we're going to do this is to create two types of account a current account and a savings
account.
And both of these are going to inherit from the account parent class because most accounts pretty much
work the same way right so each account can deposit and withdraw money and it can also print you a stayman
.
However each account will have different minimum limits.
The current account will have an overdraft of a thousand and the savings account won't have an overdraft
at all.
Just like real life.
That's pretty cool right.
And by the end of this video hopefully those OPI concepts or those object oriented programming concepts
that you've come across will sink in a bit deeper and you have a really cool program to show off as
well.
So let's get into it.
Hello there you beautiful baby.
So the first thing I'm going to do I'm going to create a new script called Bank dot P Y.
So save that desktop Python buyable bank doppie why
save it.
Maximize it.
Amber good to go.
So first of all let's create an abstract parent class.
The first thing we're going to need is a simple constructor.
And this is going to take a name you know the name of the account holder a balance and a and the minimum
balance for the account.
So we're going to make a class of count.
I'm going to define the constructer right here.
We're going to take the name balance and minimum balance.
Now bear in mind this is for any account right this is just a general account class.
What behavior do all accounts have going.
So the name of the account is going to become that name.
The balance is going to become that balance and the minimum balance is going to become that minimum
balance whatever goes in that.
All right now.
Each account can deposit money.
So let's make a method for that defined deposit self and then you just deposit an amount.
Right.
Okay.
So one of what's going to happen is self balance is going to become self out of balance plus that amount
.
Now a short for writing this you can see the way the self-doubt balance appears twice.
It's a bit of a mass.
Okay.
So what we can do is we're going to write shelved a balance plus equals amount and that is exactly the
same.
It's going to say self to balance is itself.
Plus I'm out.
So not sure or you might want to keep on.
Mom my wife keep on.
So that's and that know each account can also withdraw money but only if you have enough.
Right.
So it's made that method define withdraw need to put self as the first parameter.
And again you would draw an amount.
Now if if a self-taught balance minus the amount that you withdraw is greater than or equal to your
minimum balance
then you can subtract it and I'm going to use that shortcut again self balance minus equals amount.
OK.
We're not comfortable with this was go going to uni the old way but it's basically the same thing.
And if if he if he can then he was going to do it.
Otherwise it's going to say it's going to print to you.
Sorry not enough
funds.
OK.
So that's now just the that's the withdraw method.
Nice and straight forward.
And the final thing that all accounts can do is give you a statement.
So let's create that define stateman oneself and all this is going to do it's going to print a counterbalance
.
Put a pound sign.
Goodness me.
Then you can sign and format in their softer balance.
Okay so there's that.
Now that's our general behavior sorted.
Now that was pretty easy right.
I mean we've now got a deposit where you give it an amount and it's can add that meant to the balance
you can withdraw a certain amount but only if you've got enough otherwise he's going to tell you can't
.
And if it's going where if you ask for a statement it's going to say the account balance and then give
you the balance.
So now we need to just make our current account so we're going to go down here make class corrent and
get that to inherit from account.
All right now create our constructer in there.
We're going to we're going to define in it.
Self name balance.
Like I said this is what these are the options that someone is going to be given these are the parameters
they have to enter to create a current account like a not these ones not these ones these ones.
Okay.
Now what we need to do now is to pass that data up to this account.
So what we're going to do we'll get to call the super mattered the init function in it and pass la the
name we just got the balance we just got.
And because this is a current account we know the minimum balance
is going to be minus a thousand we're going to give them an overdraft of minus a thousand.
I'm aware of is there.
Okay so what happens here.
Basically whenever you create an account a current account say say I have a current account I'm going
call it x.
I'd write corrent my name would be ziyad and my balance would be.
I did say 500 right.
Name is going to become ziyad and balance is going to become 500.
We then pass ziyad in here is what's going to happen.
Balance is going to become five hundred and minimum balances minus five miles of.
And that's going to go up into here.
So this is going to become ziyad.
This is going to become 500.
And this is going to become minus 1000.
Okay.
And then the name for this instance called X is going to become that the balance for X is going to become
this and the minimum balance is going to become that.
Okay.
And it's going to get all these methods as well.
Okay.
So that's how that works.
Let me just pull it back to to how it was working before I'm going to undo everything pretty much.
But are there undo.
All right so now I'm going to give us our 500 pounds.
OK.
So we've managed to create that.
So let let's just show you this working.
Okay.
I'm going to run this over she's working fine in it.
Got an unexpected argument minimum balance probably just a mis spell.
So let's go back in their seats as himin balance.
I passed it minimum balance.
It should just be in balance.
That's going to fix itself.
OK.
So if let let's make a.
Ashley let's just get rid of this in here.
Let's just make an account run this again.
Make an account Z equals corrent.
And I call it ziyad and put in 500.
Okay.
Now let's deposit 300 pounds a do Z Dopp deposit
300 pounds.
Now that's a put me at eight hundred pounds right so let's look at our stateman Z dot statement.
It tells us the account balance is indeed 800 pounds.
So what if I withdraw one thousand Z don't withdraw one thousand and I need to make sure that this is
up a case.
Then I look at the balance or statement is intamin and minus two hundred OK.
If I withdraw another 800
fine so far call now if I'd withdraw another one.
Another one.
Sorry not enough funds.
And the reason is because with the minimum balance of minus 1000 which is exactly what we expected to
happen.
Now one more thing I want to show you is if I print the Z will get this ugly text again right.
Current object at the Lillah.
It's just horrible.
Right.
This is the hexadecimal memory address.
Just not the one we want a bit more of a bit more nice text than that.
So the way that we can do this is we can in here define a string function and we'll go on to say in
here we're going to say return
someone's current account balance.
And actually that put coal on their balance is something else.
And we're going to form out in there the name self to our name and self balance.
Now if I show you this again to run the let's create my current account again and then print me or print
my account ziyad current account balance 500.
Much nicer than this rubbish okay So that's why you use the t r method.
Now what we've got next we've got the savings account.
OK.
So for a savings account we just need to create another class so class savings and that's going to inherit
from account.
We're going to find our construct our self name balance fabulous and we're going to call the the parent
constructer to do all the set up that we don't want to have in each class.
When I give you that name we're going to have that balance.
But this time the minne Balance is going to be zero.
Okay.
Because you can't go less than zero.
And we are going to that should be that.
And then for the at this print function here this s t r going to take the pace that I am make sure he's
got the right indentation and instead of saying so and so's current account I'm going to say so and
so savings account beautiful.
So let's make another account gimmick current account for me and we're gonna make a current account
for someone called Tom savings account sorry someone called Tom and Tom is going to be on three hundred
.
Okay so if we print t then Tom's savings account balance three hundred.
Fabulous.
So if we withdraw three hundred from Tom's account I'm going now.
If we look at his balance teed off statement we seize on zero.
If I had to withdraw just one more it's going to say sorry not enough funds.
Whereas if we look at my account my cans on 500 I can go all the way to negative a thousand because
it's a current account so I can do withdraw of 1500
and now I'm on minus 1000.
And if I just withdraw one more it's going to tell me that I don't have enough funds.
So there you are.
We've actually it's actually simpler to make a bank with Bank accounts and stuff like that than it is
to make a bunch of coins.
Believe it or not what a mad world we live in anyway.
While I didn't show you anything new here I heard that that was useful for making you feel more comfortable
with how classes and objects work as I know for me it's useful when I see and follow through.
Another example in the next video we're gonna have a review of this section of the buy the bible and
go over what we've learned about opis imply them saw see you in the next video.