1
00:00:05,530 --> 00:00:06,730
Welcome back everyone.

2
00:00:06,910 --> 00:00:11,520
Let's go ahead and work through the solutions for the object oriented programming exercise.

3
00:00:11,530 --> 00:00:13,480
All right here we are at the exercise.

4
00:00:13,520 --> 00:00:19,050
I want to scroll down until we get to our actual class account and let's start filling in.

5
00:00:19,060 --> 00:00:24,220
So again it's up to you if it's optional if you open and close princes or no princes Python 3 won't

6
00:00:24,220 --> 00:00:26,170
complain either way.

7
00:00:26,170 --> 00:00:31,480
But first we're going to need to have our own method because remember we want two attributes we want

8
00:00:31,480 --> 00:00:33,940
an owner attribute and a balance attribute.

9
00:00:33,940 --> 00:00:40,420
So we always start with self and then we'll say owner and then balance and especially if you want.

10
00:00:40,570 --> 00:00:48,280
You can set a default balance of zero and we'll say colon and they will assign those attributes so I'll

11
00:00:48,280 --> 00:00:54,920
say self-taught owner is equal to the owner it's passed in and then self-taught balance is equal to

12
00:00:55,520 --> 00:00:56,870
balance.

13
00:00:56,990 --> 00:00:57,540
OK.

14
00:00:57,830 --> 00:01:03,110
So we also want to be able to print our actual account owner and account balance.

15
00:01:03,110 --> 00:01:04,970
So let's go ahead and set that up right now.

16
00:01:05,420 --> 00:01:11,340
Since you already have everything we need for it will create either an S T or a method or if you want

17
00:01:12,630 --> 00:01:13,830
a representation method.

18
00:01:13,830 --> 00:01:18,960
It's kind of up to you when you want to choose in this case will work the exact same way and then we'll

19
00:01:18,960 --> 00:01:24,340
say that the account owner is self-taught owner.

20
00:01:24,380 --> 00:01:35,290
How I'm using string literals here and then we'll say a count let's just say balance balance is self-taught

21
00:01:35,300 --> 00:01:40,640
balance.

22
00:01:40,690 --> 00:01:45,090
So so far I've set up my attributes and they set up my printing capabilities.

23
00:01:45,250 --> 00:01:54,710
All I need to do is set up to deposit and withdraw methods will start the deposit method pasand self

24
00:01:54,710 --> 00:02:00,580
to make sure the positing to this instance of the account and then we'll create a variable called deposit

25
00:02:00,590 --> 00:02:09,180
amount or DGP underscore amitie and then we'll take our current balance and we're going to set it equal

26
00:02:09,180 --> 00:02:20,180
to the current balance plus the deposited amount and then we can also print out a message like deposit

27
00:02:20,240 --> 00:02:23,250
was accepted.

28
00:02:23,250 --> 00:02:26,840
It's up to you whether or not you want to print that but all we're doing here is when someone calls

29
00:02:26,850 --> 00:02:32,480
deposit they pasan a deposit amount and then you take your current balance add that deposit and then

30
00:02:32,480 --> 00:02:34,670
set that to be your current balance.

31
00:02:34,670 --> 00:02:41,300
Notice here how I'm using self to reference the self balance.

32
00:02:41,460 --> 00:02:44,510
And finally we're going to have a withdrawal method.

33
00:02:44,510 --> 00:02:50,150
So say withdrawal very similar is going to pass and solve.

34
00:02:50,160 --> 00:02:59,560
Except this time we'll say it's a WD amount or withdrawal amount they'll say if self-taught balance

35
00:03:00,040 --> 00:03:11,120
is greater than or equal to the withdrawal amounts I'll take my current balance and I'll stick to my

36
00:03:11,120 --> 00:03:14,920
current balance minus the withdrawal amount.

37
00:03:16,190 --> 00:03:24,520
And then I will print something like withdrawal successful else.

38
00:03:24,740 --> 00:03:27,220
That means I actually don't have enough money for this withdrawal yet.

39
00:03:27,470 --> 00:03:36,660
So I will edit my balance and then I'll just say Prince funds not available.

40
00:03:36,680 --> 00:03:37,140
All right.

41
00:03:37,370 --> 00:03:40,840
So let's zoom out so you can see kind of everything that's going on here.

42
00:03:40,850 --> 00:03:45,710
So all we did was we set up our method to set up the attributes the owner attribute and the balance

43
00:03:45,740 --> 00:03:46,700
attribute.

44
00:03:46,790 --> 00:03:49,300
Then we set up our representation for the string.

45
00:03:49,310 --> 00:03:53,030
So if we want to print out our account we get the account owner and balance.

46
00:03:53,060 --> 00:03:56,900
You could have had a lot of flexibility as far as what you actually want to be printing out.

47
00:03:56,900 --> 00:03:58,710
Then we set a deposit.

48
00:03:58,730 --> 00:04:04,190
So we take our current balance as a deposit amount and print deposit that and then for the withdrawal

49
00:04:04,370 --> 00:04:08,370
we first want to check do we actually have enough balance is our balance greater than or equal to the

50
00:04:08,370 --> 00:04:09,470
overall amount.

51
00:04:09,470 --> 00:04:15,590
If so then we can remove that of Charle amount say withdrawal was successful else will print funds not

52
00:04:15,590 --> 00:04:16,770
available.

53
00:04:17,120 --> 00:04:24,840
So let's do all this will instantiate a class will print the object and then I'm going to print the

54
00:04:24,840 --> 00:04:29,410
account owner or show the account balance as well.

55
00:04:29,700 --> 00:04:31,110
So will print that out.

56
00:04:33,580 --> 00:04:35,290
Then we'll make a deposit.

57
00:04:35,290 --> 00:04:38,670
No need to print that out because it's just an action being performed.

58
00:04:38,740 --> 00:04:40,050
Then I'll make a withdrawal.

59
00:04:40,390 --> 00:04:42,720
So this should be withdrawal I believe.

60
00:04:42,760 --> 00:04:44,110
Let me make sure we match that up.

61
00:04:44,200 --> 00:04:51,660
Withdrawal and then also say withdrawal here so let's save this.

62
00:04:51,660 --> 00:04:54,810
Open this up and run it.

63
00:04:54,940 --> 00:05:00,730
So we'll say Python and I wrote this in my example the PI file saw hit enter and see.

64
00:05:00,750 --> 00:05:04,710
So I have Jose 100 my deposit fifty was accepted.

65
00:05:04,710 --> 00:05:05,530
That makes sense.

66
00:05:05,550 --> 00:05:06,610
My withdrawal was successful.

67
00:05:06,630 --> 00:05:07,260
Seventy five.

68
00:05:07,260 --> 00:05:08,130
That makes sense.

69
00:05:08,310 --> 00:05:11,400
However when I try to withdraw 500 funds were not available.

70
00:05:11,400 --> 00:05:13,010
Which also makes sense.

71
00:05:13,020 --> 00:05:13,460
OK.

72
00:05:13,620 --> 00:05:16,140
That's all you had to do for this project.

73
00:05:16,140 --> 00:05:20,790
Again if you have any questions feel free to post the Q&amp;A for us but hopefully once you're able to view

74
00:05:20,790 --> 00:05:23,680
the solution you can see how everything connects together.

75
00:05:23,700 --> 00:05:26,550
We'll see you at the next lecture where we'll talk about decorator's.
