1
00:00:00,120 --> 00:00:05,250
Now we're going to finalize the main class, the next thing we got to do is add a method that returns

2
00:00:05,250 --> 00:00:10,050
every transaction from transactions that text but as a transaction object.

3
00:00:10,650 --> 00:00:19,440
So what we'll do is define a public static method that returns an array list of transaction objects.

4
00:00:20,850 --> 00:00:23,670
The method is going to be called return transactions.

5
00:00:26,450 --> 00:00:29,640
And we already know it's going to throw a file not found exception.

6
00:00:29,660 --> 00:00:30,980
So we'll throw it right now.

7
00:00:31,980 --> 00:00:32,340
OK.

8
00:00:33,960 --> 00:00:37,230
First thing we'll do is create a new object of the Phalen bitstream class.

9
00:00:41,110 --> 00:00:43,150
That connects to the transactions file.

10
00:00:46,910 --> 00:00:50,420
Then we'll create a new object of the scanner class.

11
00:00:52,710 --> 00:00:54,870
That receives input from the foreign input stream.

12
00:00:57,430 --> 00:00:57,760
OK.

13
00:00:58,000 --> 00:01:03,040
And now what we want to do is create the array list of transaction objects that were eventually going

14
00:01:03,040 --> 00:01:04,930
to return array list.

15
00:01:05,980 --> 00:01:06,880
Transaction.

16
00:01:10,050 --> 00:01:11,130
Transactions.

17
00:01:12,640 --> 00:01:13,530
Is equal to an.

18
00:01:15,310 --> 00:01:20,290
Is equal to a new ArrayList that can store transaction objects.

19
00:01:23,750 --> 00:01:29,150
And now what I want to do is create a while loop that runs through every single line in the transactions

20
00:01:29,150 --> 00:01:29,480
file.

21
00:01:30,050 --> 00:01:33,170
So while scanned as a next line.

22
00:01:35,130 --> 00:01:39,360
And as long as there is a next line, we're going to pick it up, scanned our next line.

23
00:01:39,960 --> 00:01:45,060
And if you look back at transactions dot text, we can split every line into four values.

24
00:01:45,070 --> 00:01:46,860
They're all separated based on a comma.

25
00:01:46,870 --> 00:01:48,060
So here we can say scanned.

26
00:01:48,060 --> 00:01:49,650
Our next line split.

27
00:01:50,750 --> 00:01:52,140
Around a comma.

28
00:01:52,760 --> 00:01:58,400
And what that's going to do is return an array of four string values for each line.

29
00:01:59,710 --> 00:02:06,600
And then using these values, we can add a new transaction object to the transactions ArrayList transactions

30
00:02:06,890 --> 00:02:10,600
and there will create a new transaction objects.

31
00:02:11,410 --> 00:02:16,540
Now if you look back at the transaction constructor, first, we're expecting an enum type.

32
00:02:17,580 --> 00:02:20,100
We'll have to say transaction type.

33
00:02:21,210 --> 00:02:27,060
And that tape can be one of two constants withdraw or deposit, we can get one of these constants by

34
00:02:27,060 --> 00:02:29,790
using the value of index one.

35
00:02:30,180 --> 00:02:33,180
So here we'll say transaction type the value of.

36
00:02:34,670 --> 00:02:36,500
Values at index one.

37
00:02:39,090 --> 00:02:44,130
The next parameter is long time stamp, which is that index is zero.

38
00:02:44,670 --> 00:02:49,500
Here will say values at index zero, but the constructor expects a long.

39
00:02:49,530 --> 00:02:51,450
So what will have to do is say.

40
00:02:52,770 --> 00:02:55,260
Long, dark, past long.

41
00:02:55,650 --> 00:02:58,560
And we're going to pass along out of this string value.

42
00:03:01,930 --> 00:03:04,230
OK, next parameter is a string ID.

43
00:03:05,290 --> 00:03:07,900
We can just say values at index to.

44
00:03:09,030 --> 00:03:14,580
Values at Index three, make sure to pass a double from the following string.

45
00:03:22,110 --> 00:03:23,450
I think we're missing a bracket.

46
00:03:27,600 --> 00:03:28,410
And that's pretty much it.

47
00:03:28,470 --> 00:03:33,840
That's why Loop should populate the transactions array list with three hundred and fifty two transactions.

48
00:03:34,200 --> 00:03:37,680
But before we return, the transactions are our list.

49
00:03:38,010 --> 00:03:39,120
We want to sort it.

50
00:03:39,750 --> 00:03:42,060
We'll say collections does sort.

51
00:03:43,660 --> 00:03:47,860
And we will sort the transactions are a list based on time stamp.

52
00:03:48,760 --> 00:03:49,660
Close, Skinner.

53
00:03:50,640 --> 00:03:53,160
And return transactions.

54
00:04:02,670 --> 00:04:08,190
OK, before we move on, we want to make sure this method works by going over to men and instead of

55
00:04:08,190 --> 00:04:11,490
calling return accounts, call or return transactions.

56
00:04:11,820 --> 00:04:15,150
Switch this to an array a list of transactions.

57
00:04:16,850 --> 00:04:17,240
OK.

58
00:04:17,660 --> 00:04:19,910
At a break point, debug the runtime.

59
00:04:22,140 --> 00:04:27,770
If this works, we should get an array list of three hundred and fifty two sorted transactions.

60
00:04:30,410 --> 00:04:31,820
Seems like it works.

61
00:04:33,360 --> 00:04:35,460
Are they all sorted based on time stamp?

62
00:04:35,490 --> 00:04:36,750
Indeed, they are.

63
00:04:36,780 --> 00:04:38,730
This is wonderful.

64
00:04:40,600 --> 00:04:40,990
OK.

65
00:04:45,010 --> 00:04:50,110
So we were able to return every single transaction from the transactions file, but as an object, the

66
00:04:50,110 --> 00:04:53,510
next step is to create a method that executes transactions.

67
00:04:54,010 --> 00:05:01,030
So I'll create a public static void method called run transactions.

68
00:05:02,160 --> 00:05:07,020
They receives the array list of transactions we want to execute.

69
00:05:11,350 --> 00:05:17,320
And inside the function, what I'm going to do is run through every single transaction in the transactions

70
00:05:17,320 --> 00:05:17,980
array list.

71
00:05:18,490 --> 00:05:23,110
And here I'll say bank, don't execute transaction transaction.

72
00:05:24,130 --> 00:05:26,560
And it's really nice if everything is coming together.

73
00:05:30,640 --> 00:05:34,690
If you look back at transactions, not text, every transaction has an ID.

74
00:05:35,650 --> 00:05:40,810
The ID determines in which account this particular transaction is going to take place.

75
00:05:41,320 --> 00:05:47,530
This transaction is going to take place in the account 73 DB, which would be.

76
00:05:51,080 --> 00:05:52,250
A checking account.

77
00:05:55,610 --> 00:06:00,980
So what I want to do in Maine is define a method that gets every single transaction that belongs to

78
00:06:00,980 --> 00:06:04,790
a particular account and print the transaction history.

79
00:06:06,050 --> 00:06:10,640
The method is public static void transaction history.

80
00:06:12,080 --> 00:06:18,230
It receives a strong aid, it receives the ID of the account, whose transactions we want to print.

81
00:06:19,520 --> 00:06:23,390
And there's really nothing meaningful in this function, it's all aesthetics, and I left you all the

82
00:06:23,390 --> 00:06:26,540
aesthetics inside of learning the parts, so we'll copy it over.

83
00:06:27,820 --> 00:06:29,440
Copy over this entire comment.

84
00:06:31,620 --> 00:06:35,760
And first thing we want to print is this fancy message.

85
00:06:39,370 --> 00:06:40,480
Six out.

86
00:06:43,060 --> 00:06:44,090
And your quotes.

87
00:06:47,090 --> 00:06:51,200
Next thing we want to print is every transaction that corresponds to the I.D..

88
00:06:53,040 --> 00:06:55,200
So what we want to do is create a for loop.

89
00:06:57,490 --> 00:07:04,330
Here we'll call banks get transactions will pass and the account ID, whose transactions we want to

90
00:07:04,330 --> 00:07:04,630
get.

91
00:07:05,110 --> 00:07:09,910
So this is going to return an array of transactions for a particular account.

92
00:07:10,480 --> 00:07:16,600
And so here we want to run through every single transaction in this array of transactions.

93
00:07:21,020 --> 00:07:24,070
And for every transaction that we run through, we're going to wait.

94
00:07:24,140 --> 00:07:25,760
Three hundred milliseconds.

95
00:07:30,610 --> 00:07:32,260
And print the following message.

96
00:07:42,700 --> 00:07:45,280
OK, now we just got to print the following messages.

97
00:07:49,210 --> 00:07:51,280
Print after tax.

98
00:07:59,970 --> 00:08:05,430
And here we need to fill our string with an account that corresponds to the ID, so we'll just say bank

99
00:08:06,060 --> 00:08:07,200
get accounts.

100
00:08:08,330 --> 00:08:08,630
I'd.

101
00:08:16,550 --> 00:08:22,130
So ultimately, all this function is doing is running through all of the transactions for a particular

102
00:08:22,130 --> 00:08:22,700
account.

103
00:08:26,130 --> 00:08:29,340
And here we're getting that account and printing, it's two string.

104
00:08:30,690 --> 00:08:35,669
At this point, we're pretty much done, all we got to do is copy this inside of our main method and

105
00:08:35,669 --> 00:08:36,539
test our code.

106
00:08:36,690 --> 00:08:37,710
I can't wait.

107
00:08:47,120 --> 00:08:49,200
So there's nothing too crazy going on here.

108
00:08:49,220 --> 00:08:53,000
First, we're just grabbing every single account from the accounts that tax file.

109
00:08:53,240 --> 00:08:56,660
We're loading all of these accounts into the bank object.

110
00:08:57,080 --> 00:09:00,470
Then we're grabbing every single transaction from any transactions file.

111
00:09:00,830 --> 00:09:04,220
We're executing on any transactions from the bank object.

112
00:09:04,580 --> 00:09:10,580
And then after all, the withdrawals and deposits have been made, the bank deduct taxes and then we're

113
00:09:10,580 --> 00:09:13,280
running through every single account in the accounts ArrayList.

114
00:09:13,430 --> 00:09:18,350
We're printing the two string of that account and then we're printing the history of all transactions

115
00:09:18,350 --> 00:09:19,940
that occurred at this account.

116
00:09:20,660 --> 00:09:22,100
I can't wait to test this out.

117
00:09:22,110 --> 00:09:23,390
Let's just press the run button.

118
00:09:30,010 --> 00:09:32,110
And this is looking pretty good.

119
00:09:32,140 --> 00:09:35,830
I really hope you enjoyed this challenge and learned a lot by trying to solve it.

120
00:09:36,100 --> 00:09:41,740
This is definitely the hardest challenge in this course, and this wraps up inheritance and polymorphism.

