00:05
Good day, ladies and gentlemen.
00:07
Today we're looking at problem number 7 .3.
00:12
It's a account from the good book python.
00:15
It's the account class problem.
00:19
And so we're supposed to create a class which satisfies all these conditions, basically, all the conditions in the book.
00:34
And then we have to go through and create the test file and then also the uml diagram.
00:46
So this time what i've done is i've actually put, i've already written all the code, but i'm going to actually walk you through it.
00:58
There's just too much to this problem to try and do this line by line.
01:03
And it's really quite involved, or it's quite a bit of work.
01:09
I guess a lot of it's pretty basic.
01:11
But anyhow, i'm going to talk you through the code and sort of give you an idea of what's going on.
01:19
Okay.
01:20
So first off, we have to create a class account.
01:24
So that's what we have.
01:25
We create the class account.
01:28
And we have this.
01:30
So we initial it as we define the, we define the.
01:33
Initializer with the self, the id, and they want the initial value here to be zero, oops, the initial value to be zero for id, and then balance the initial value to be 100, and the annual interest rate to be zero, okay? and now specifically it states that these were supposed to create private data fields named id, balance, and annual interest rate.
02:12
And you notice that in this case, i have the underscores here, which indicate that they're private.
02:19
Okay.
02:19
So these cannot be referenced from outside the class.
02:25
Once those values are set, you cannot reference them.
02:31
You cannot just, okay, you can't, okay.
02:37
So, and then i've set, then we have these what are called assessor methods.
02:44
Sometimes they're called get methods.
02:46
There's other names for them.
02:48
But the assessor methods should just return what the corresponding value is.
02:55
In particular here, so when i want the id, i just return to self.
03:01
Dot id because if you recall, like i said, you can't reference it from outside.
03:09
You can't get that information unless you have these get information, these get or assessor methods.
03:19
So by placing them here, you can get that information outside of it.
03:27
It just, it can't be changed by saying self.
03:33
Dot id equals something else rather than it is.
03:37
Okay.
03:39
And i'll show you what i mean once we're all done here.
03:43
I'll show you what i mean.
03:45
I'm sorry.
03:46
I'm just sort of losing my place here.
03:50
But so the assessor methods are as such.
03:55
And then the mutator methods here, the mutator methods allow us to change what might be the current value to a new value.
04:06
So i have this set id to some id.
04:11
So i just set the self.
04:14
Id to id.
04:18
And then i do the same things with both the balance and the interest rates.
04:24
Okay.
04:24
So these are what we call the assessor, the assessor methods.
04:31
Okay.
04:32
So now for the other, now we have a few other methods here.
04:41
And in particular, now we have the monthly rate, which is to get monthly interest rate.
04:47
And now importantly, that this should return what, you know, the monthly interest rate, which as the author kindly explains, is the annual interest rate divided by 12.
05:02
So to get, you have to, you have to first get the annual interest rate.
05:07
So in other words, we have to go self .get annual interest rate and then divide that number by 12 using the get annual interest rate that allows us to get the value and then divide by 12 and then we return that value.
05:28
Okay.
05:29
Now for the next one, which is to get monthly interest.
05:32
Now, what we just want is the monthly interest rate.
05:39
So we calculate that.
05:43
We use the monthly interest rate, and we multiply that by the balance.
05:48
And now, of course, we can't, we first have to get the monthly interest rate, which is the previous method.
06:04
And then we multiply that by the balance, which, again, is self.
06:11
Dot get balance.
06:12
And that allows us to get the balance.
06:16
Okay.
06:17
Because remember, again, that it's a private, it's a private data field.
06:23
So we can't use it.
06:25
We have to actually use the get statement to use it.
06:29
Now, the withdrawal module or the method, it requires, it requires, the amount that you're going to withdraw.
06:41
And now what it does is it sets a new balance at the current balance minus the amount you're going to withdraw.
06:51
So we first, to do that, we have to get the current balance.
06:56
So in other words, we have to go set dot get balance to get the balance of what we have, subtract that amount.
07:06
And now because we want the new, the updated balance to be reflected by this change, we use the set balance function or method to replace the old balance.
07:23
So if you make a withdrawal, then this will update the old balance with the new one.
07:31
I mean, obviously it would be nice if we excluded this, you know, this.
07:38
This little set balance here because then that your old balance would still be the same as your new balance and nothing would change.
07:50
So by including this set balance, we can change the current balance to reflect that transaction.
08:02
And we do the same thing with the deposit where we grab the current balance, which we do through the get balance, and we add the amount this time, and then we replace the old balance with the new balance.
08:23
So we use the set balance thing to the set balance module to change the current balance.
08:33
Okay.
08:35
And now to get to look, now i have the test function.
08:40
I have the test, yeah.
08:44
So i have the test, the test file here.
08:54
And let's just run that and see what happens...