Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,150 --> 00:00:05,220
In this video, we'll create the bank class, so we'll start by setting up inside Bank Java and the
2
00:00:05,220 --> 00:00:08,760
bank is going to be in charge of managing accounts and transactions.
3
00:00:09,060 --> 00:00:10,590
So here I'll create an array list.
4
00:00:12,820 --> 00:00:18,550
Type accounts called accounts, and I'll create another ArrayList.
5
00:00:21,830 --> 00:00:25,250
Not a ray array list of type transaction.
6
00:00:27,160 --> 00:00:28,990
Called transactions.
7
00:00:33,300 --> 00:00:37,140
Now we'll add a constructor that receives no parameters, public bank.
8
00:00:38,430 --> 00:00:40,250
And here we can initialize the area list.
9
00:00:40,290 --> 00:00:45,000
This accounts is equal to a new object of the ArrayList class.
10
00:00:46,190 --> 00:00:48,080
That can store account objects.
11
00:00:52,120 --> 00:00:55,440
Seems like going after import accounts, OK?
12
00:00:56,530 --> 00:01:03,770
Then we'll set this that transactions equal to a new object of the ArrayList class that can store transaction
13
00:01:03,770 --> 00:01:04,459
objects.
14
00:01:08,320 --> 00:01:14,560
OK, now we need methods that we can use to add account objects to the account surrealist and transaction
15
00:01:14,560 --> 00:01:16,930
object to the transactions ArrayList.
16
00:01:17,470 --> 00:01:19,000
We're going to start with ad account.
17
00:01:19,330 --> 00:01:22,480
So we'll see public void ad accounts.
18
00:01:23,730 --> 00:01:26,370
This method receives an account object.
19
00:01:29,000 --> 00:01:36,380
And to the Arab, the state accounts, we're going to add a new copy of the account object.
20
00:01:40,050 --> 00:01:43,650
But wait, a second account is an abstract class.
21
00:01:49,080 --> 00:01:54,660
So it doesn't matter if this is a checking savings or loan object.
22
00:01:54,900 --> 00:01:57,360
We can't create a new account object.
23
00:01:57,810 --> 00:02:01,210
And that's why we need a clone method, a clone method.
24
00:02:01,230 --> 00:02:07,370
What it does is it returns a copy of the object that calls it so inside account counter Java.
25
00:02:07,770 --> 00:02:09,060
We're going to force.
26
00:02:10,330 --> 00:02:17,620
We're going to force every child the class to override Clone, so we'll say public abstract account
27
00:02:18,340 --> 00:02:18,820
clone.
28
00:02:20,670 --> 00:02:21,180
OK.
29
00:02:22,300 --> 00:02:29,230
And now back here, we can say this state accounts don't add account cyclone.
30
00:02:32,180 --> 00:02:36,500
And what that's going to do is return a copy of the object that calls it.
31
00:02:36,920 --> 00:02:41,900
So if this object is checking, it's going to call the clone method from the checking class.
32
00:02:42,200 --> 00:02:46,520
If this object is savings, it's going to call the clone method from the savings class.
33
00:02:46,760 --> 00:02:51,770
If this object is loan, it's going to call the clone method wherever it is from the loan class.
34
00:02:52,490 --> 00:02:55,610
And ultimately, Clone will return a copy of that object.
35
00:02:56,210 --> 00:03:00,050
But right now, we still have to override the clone methods and each child.
36
00:03:00,290 --> 00:03:01,490
So we'll start with checking.
37
00:03:02,510 --> 00:03:06,050
I like to define my clone method right after the copy constructor.
38
00:03:08,590 --> 00:03:10,450
So here I'll override Clone.
39
00:03:11,500 --> 00:03:14,770
OK, now inside Clone, we're going to create a new checking object.
40
00:03:18,430 --> 00:03:23,500
And the object we're creating, it's going to get all of its values from the current object that's calling
41
00:03:23,500 --> 00:03:25,840
this method, which would be this.
42
00:03:30,180 --> 00:03:32,130
We'll do the same thing inside savings.
43
00:03:33,440 --> 00:03:39,110
We'll put a clone method right after the copy constructor in here, I will say return new savings.
44
00:03:40,630 --> 00:03:41,380
This.
45
00:03:43,800 --> 00:03:45,420
Put a clone method inside Lone.
46
00:03:49,360 --> 00:03:54,970
Return a new loan object that's going to get all of its values from the current object, that's calling
47
00:03:54,970 --> 00:03:55,510
this method.
48
00:04:00,160 --> 00:04:04,570
All right, now, we're going to test our clone methods, so go back to the article and copy over these
49
00:04:04,570 --> 00:04:07,510
objects inside mean we can remove the following?
50
00:04:07,570 --> 00:04:08,470
We don't need any more.
51
00:04:10,780 --> 00:04:12,340
An ad for break points.
52
00:04:14,610 --> 00:04:15,940
We're getting a bunch of errors.
53
00:04:15,960 --> 00:04:16,980
Not sure why.
54
00:04:18,000 --> 00:04:20,459
Oh, we got to import the account class.
55
00:04:22,590 --> 00:04:22,890
OK.
56
00:04:24,060 --> 00:04:25,350
Let's visualize the runtime.
57
00:04:29,930 --> 00:04:32,750
Here it creates a new object of the chucking class.
58
00:04:33,870 --> 00:04:38,070
And now in this line, Clone is supposed to return a copy of this object.
59
00:04:38,370 --> 00:04:39,090
How does it do it?
60
00:04:39,630 --> 00:04:40,620
Well, let's step inside.
61
00:04:43,290 --> 00:04:50,830
So Clone returns a new checking object passing in the current object as the source the copy values from.
62
00:04:51,210 --> 00:04:53,760
So ultimately, that's going to call the copy constructor.
63
00:04:55,820 --> 00:04:56,270
OK.
64
00:04:58,840 --> 00:05:05,230
So that new object we just created that became the current object and the one that originally called
65
00:05:05,230 --> 00:05:08,800
this method, that is now the source object that we're copying values from.
66
00:05:13,000 --> 00:05:17,980
Here, the copper constructor is updating its ID, its name and its balance.
67
00:05:23,420 --> 00:05:26,030
And now Clone returns a new copy of that object.
68
00:05:27,300 --> 00:05:27,990
Perfect.
69
00:05:28,770 --> 00:05:29,910
Same thing for savings.
70
00:05:30,390 --> 00:05:34,620
This one is pretty simple, we're just creating a new savings object, passing in three values into
71
00:05:34,620 --> 00:05:35,340
the constructor.
72
00:05:35,610 --> 00:05:42,840
Nothing interesting here, but here Savings Cyclone Clone is returning a new copy of the object that
73
00:05:42,840 --> 00:05:44,370
calls it so we'll step inside.
74
00:05:45,690 --> 00:05:51,810
Clone creates a new savings object, passing in the current object as the source the copy values from.
75
00:05:52,200 --> 00:05:54,690
So ultimately, this is calling the copy constructor.
76
00:05:56,810 --> 00:06:03,260
The object we just created becomes the current object, and the object that originally called the clone
77
00:06:03,260 --> 00:06:06,260
method becomes the source object to copy values from.
78
00:06:09,650 --> 00:06:13,430
And here we're copying every value from the source object into the current one.
79
00:06:17,920 --> 00:06:19,720
Clone returns the new object.
80
00:06:20,870 --> 00:06:21,970
And we're good.
7370
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.