Hello there you beautiful people. 2
And in this video we're going to make a bank. 3
We won't introduce anything new here really but it's nice to have a fresh example you know away from 4
all those coins to help all those complicated concepts from object oriented programming to stick in 5
your mind so you can see it a fresh. 6
Now the way that we're going to do this is to create two types of account a current account and a savings 7
account. 8
And both of these are going to inherit from the account parent class because most accounts pretty much 9
work the same way right so each account can deposit and withdraw money and it can also print you a stayman 10
. 11
However each account will have different minimum limits. 12
The current account will have an overdraft of a thousand and the savings account won't have an overdraft 13
at all. 14
Just like real life. 15
That's pretty cool right. 16
And by the end of this video hopefully those OPI concepts or those object oriented programming concepts 17
that you've come across will sink in a bit deeper and you have a really cool program to show off as 18
well. 19
So let's get into it. 20
Hello there you beautiful baby. 21
So the first thing I'm going to do I'm going to create a new script called Bank dot P Y. 22
So save that desktop Python buyable bank doppie why 23
save it. 24
Maximize it. 25
Amber good to go. 26
So first of all let's create an abstract parent class. 27
The first thing we're going to need is a simple constructor. 28
And this is going to take a name you know the name of the account holder a balance and a and the minimum 29
balance for the account. 30
So we're going to make a class of count. 31
I'm going to define the constructer right here. 32
We're going to take the name balance and minimum balance. 33
Now bear in mind this is for any account right this is just a general account class. 34
What behavior do all accounts have going. 35
So the name of the account is going to become that name. 36
The balance is going to become that balance and the minimum balance is going to become that minimum 37
balance whatever goes in that. 38
All right now. 39
Each account can deposit money. 40
So let's make a method for that defined deposit self and then you just deposit an amount. 41
Right. 42
Okay. 43
So one of what's going to happen is self balance is going to become self out of balance plus that amount 44
. 45
Now a short for writing this you can see the way the self-doubt balance appears twice. 46
It's a bit of a mass. 47
Okay. 48
So what we can do is we're going to write shelved a balance plus equals amount and that is exactly the 49
same. 50
It's going to say self to balance is itself. 51
Plus I'm out. 52
So not sure or you might want to keep on. 53
Mom my wife keep on. 54
So that's and that know each account can also withdraw money but only if you have enough. 55
Right. 56
So it's made that method define withdraw need to put self as the first parameter. 57
And again you would draw an amount. 58
Now if if a self-taught balance minus the amount that you withdraw is greater than or equal to your 59
minimum balance 60
then you can subtract it and I'm going to use that shortcut again self balance minus equals amount. 61
OK. 62
We're not comfortable with this was go going to uni the old way but it's basically the same thing. 63
And if if he if he can then he was going to do it. 64
Otherwise it's going to say it's going to print to you. 65
Sorry not enough 66
funds. 67
OK. 68
So that's now just the that's the withdraw method. 69
Nice and straight forward. 70
And the final thing that all accounts can do is give you a statement. 71
So let's create that define stateman oneself and all this is going to do it's going to print a counterbalance 72
. 73
Put a pound sign. 74
Goodness me. 75
Then you can sign and format in their softer balance. 76
Okay so there's that. 77
Now that's our general behavior sorted. 78
Now that was pretty easy right. 79
I mean we've now got a deposit where you give it an amount and it's can add that meant to the balance 80
you can withdraw a certain amount but only if you've got enough otherwise he's going to tell you can't 81
. 82
And if it's going where if you ask for a statement it's going to say the account balance and then give 83
you the balance. 84
So now we need to just make our current account so we're going to go down here make class corrent and 85
get that to inherit from account. 86
All right now create our constructer in there. 87
We're going to we're going to define in it. 88
Self name balance. 89
Like I said this is what these are the options that someone is going to be given these are the parameters 90
they have to enter to create a current account like a not these ones not these ones these ones. 91
Okay. 92
Now what we need to do now is to pass that data up to this account. 93
So what we're going to do we'll get to call the super mattered the init function in it and pass la the 94
name we just got the balance we just got. 95
And because this is a current account we know the minimum balance 96
is going to be minus a thousand we're going to give them an overdraft of minus a thousand. 97
I'm aware of is there. 98
Okay so what happens here. 99
Basically whenever you create an account a current account say say I have a current account I'm going 100
call it x. 101
I'd write corrent my name would be ziyad and my balance would be. 102
I did say 500 right. 103
Name is going to become ziyad and balance is going to become 500. 104
We then pass ziyad in here is what's going to happen. 105
Balance is going to become five hundred and minimum balances minus five miles of. 106
And that's going to go up into here. 107
So this is going to become ziyad. 108
This is going to become 500. 109
And this is going to become minus 1000. 110
Okay. 111
And then the name for this instance called X is going to become that the balance for X is going to become 112
this and the minimum balance is going to become that. 113
Okay. 114
And it's going to get all these methods as well. 115
Okay. 116
So that's how that works. 117
Let me just pull it back to to how it was working before I'm going to undo everything pretty much. 118
But are there undo. 119
All right so now I'm going to give us our 500 pounds. 120
OK. 121
So we've managed to create that. 122
So let let's just show you this working. 123
Okay. 124
I'm going to run this over she's working fine in it. 125
Got an unexpected argument minimum balance probably just a mis spell. 126
So let's go back in their seats as himin balance. 127
I passed it minimum balance. 128
It should just be in balance. 129
That's going to fix itself. 130
OK. 131
So if let let's make a. 132
Ashley let's just get rid of this in here. 133
Let's just make an account run this again. 134
Make an account Z equals corrent. 135
And I call it ziyad and put in 500. 136
Okay. 137
Now let's deposit 300 pounds a do Z Dopp deposit 138
300 pounds. 139
Now that's a put me at eight hundred pounds right so let's look at our stateman Z dot statement. 140
It tells us the account balance is indeed 800 pounds. 141
So what if I withdraw one thousand Z don't withdraw one thousand and I need to make sure that this is 142
up a case. 143
Then I look at the balance or statement is intamin and minus two hundred OK. 144
If I withdraw another 800 145
fine so far call now if I'd withdraw another one. 146
Another one. 147
Sorry not enough funds. 148
And the reason is because with the minimum balance of minus 1000 which is exactly what we expected to 149
happen. 150
Now one more thing I want to show you is if I print the Z will get this ugly text again right. 151
Current object at the Lillah. 152
It's just horrible. 153
Right. 154
This is the hexadecimal memory address. 155
Just not the one we want a bit more of a bit more nice text than that. 156
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 157
here we're going to say return 158
someone's current account balance. 159
And actually that put coal on their balance is something else. 160
And we're going to form out in there the name self to our name and self balance. 161
Now if I show you this again to run the let's create my current account again and then print me or print 162
my account ziyad current account balance 500. 163
Much nicer than this rubbish okay So that's why you use the t r method. 164
Now what we've got next we've got the savings account. 165
OK. 166
So for a savings account we just need to create another class so class savings and that's going to inherit 167
from account. 168
We're going to find our construct our self name balance fabulous and we're going to call the the parent 169
constructer to do all the set up that we don't want to have in each class. 170
When I give you that name we're going to have that balance. 171
But this time the minne Balance is going to be zero. 172
Okay. 173
Because you can't go less than zero. 174
And we are going to that should be that. 175
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 176
got the right indentation and instead of saying so and so's current account I'm going to say so and 177
so savings account beautiful. 178
So let's make another account gimmick current account for me and we're gonna make a current account 179
for someone called Tom savings account sorry someone called Tom and Tom is going to be on three hundred 180
. 181
Okay so if we print t then Tom's savings account balance three hundred. 182
Fabulous. 183
So if we withdraw three hundred from Tom's account I'm going now. 184
If we look at his balance teed off statement we seize on zero. 185
If I had to withdraw just one more it's going to say sorry not enough funds. 186
Whereas if we look at my account my cans on 500 I can go all the way to negative a thousand because 187
it's a current account so I can do withdraw of 1500 188
and now I'm on minus 1000. 189
And if I just withdraw one more it's going to tell me that I don't have enough funds. 190
So there you are. 191
We've actually it's actually simpler to make a bank with Bank accounts and stuff like that than it is 192
to make a bunch of coins. 193
Believe it or not what a mad world we live in anyway. 194
While I didn't show you anything new here I heard that that was useful for making you feel more comfortable 195
with how classes and objects work as I know for me it's useful when I see and follow through. 196
Another example in the next video we're gonna have a review of this section of the buy the bible and 197
go over what we've learned about opis imply them saw see you in the next video.