Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,390 --> 00:00:00,990
In this video.
2
00:00:00,990 --> 00:00:02,850
We're going to cover the solution for part five.
3
00:00:02,880 --> 00:00:06,120
Once again, we tie everything together by adding user interactivity.
4
00:00:06,630 --> 00:00:11,370
Task one tells us to make the store object a class variable because we are going to need to access it
5
00:00:11,370 --> 00:00:13,740
from more than one place inside the class.
6
00:00:19,830 --> 00:00:22,740
Task two is to define a function named load movies.
7
00:00:31,030 --> 00:00:36,070
It takes one parameter, the file name that we're going to load movies from and the function is going
8
00:00:36,070 --> 00:00:37,930
to throw a file not found exception.
9
00:00:48,520 --> 00:00:51,580
First thing we're going to do is load contacts from the file name.
10
00:00:51,910 --> 00:00:53,560
We can use a file input stream.
11
00:00:54,250 --> 00:00:59,230
We'll create a new object of the file input stream class and pass into it the file name that we want
12
00:00:59,230 --> 00:01:00,070
to connect to.
13
00:01:00,880 --> 00:01:03,920
The next thing we need to do is read the data from the movies file.
14
00:01:03,940 --> 00:01:07,420
So after connecting to the file will create a new getter object.
15
00:01:17,070 --> 00:01:21,630
And instead of receiving input from the system, it's going to receive input from the input stream.
16
00:01:22,600 --> 00:01:26,410
And then we can use a while loop to read all the data from the file that we're scanning.
17
00:01:26,860 --> 00:01:30,300
The while loop will keep running as long as the file has a next line.
18
00:01:33,990 --> 00:01:35,490
So it should run ten times.
19
00:01:35,850 --> 00:01:39,140
And during each run, we're going to create a new movie object.
20
00:01:49,830 --> 00:01:50,580
But wait.
21
00:01:50,700 --> 00:01:52,980
Each movie is separated by hyphens.
22
00:01:53,010 --> 00:01:54,060
We can't use Scandal.
23
00:01:54,120 --> 00:01:55,390
Next, bigger scandal.
24
00:01:55,410 --> 00:01:59,370
Next picks up the next value delimited by a white space.
25
00:02:00,000 --> 00:02:02,550
In this case, the delimiter is two hyphens.
26
00:02:03,000 --> 00:02:06,480
So during each run, we're going to have to pick up the entire line as one string.
27
00:02:06,900 --> 00:02:08,759
String line is equal to scandal.
28
00:02:08,759 --> 00:02:09,530
Our next line.
29
00:02:12,210 --> 00:02:16,380
Based on the delimiter, we know that each line can split into three strings.
30
00:02:16,860 --> 00:02:21,960
And I told you to research how the split function can be used to split a string into multiple strings.
31
00:02:22,590 --> 00:02:23,850
So I hope you came up with this.
32
00:02:24,270 --> 00:02:26,340
All you got to do is say line, not split.
33
00:02:29,800 --> 00:02:33,250
And we're going to split the line every time there's a pair of hyphens.
34
00:02:34,300 --> 00:02:38,890
If you hover on the method, it returns an array of string values, which we're going to store in an
35
00:02:38,890 --> 00:02:40,150
array called words.
36
00:02:46,630 --> 00:02:52,030
This array is going to contain three elements because we know that the line was split into three words.
37
00:03:01,720 --> 00:03:03,640
The first word we know is the name.
38
00:03:05,610 --> 00:03:07,370
The second word is the format.
39
00:03:08,830 --> 00:03:10,330
And the third is the rating.
40
00:03:12,680 --> 00:03:16,380
A oh rating is a double, but it's being stored as a string.
41
00:03:16,410 --> 00:03:19,650
And your task was to research how to parse a double from a string.
42
00:03:21,610 --> 00:03:23,620
And I hope you found something like this.
43
00:03:24,010 --> 00:03:26,050
We're going to use the wrapper class double.
44
00:03:27,360 --> 00:03:28,620
To pass a double.
45
00:03:31,110 --> 00:03:32,700
From the string at index to.
46
00:03:34,980 --> 00:03:35,910
And splendid.
47
00:03:39,230 --> 00:03:42,320
And once you're done, don't forget to close the scanner object.
48
00:03:45,120 --> 00:03:47,010
And that's it for the load movies function.
49
00:03:47,190 --> 00:03:49,920
We'll go back to the main method we're going to call Load Movie.
50
00:03:55,780 --> 00:03:58,960
And the file we're going to be loading movies from is movies that text.
51
00:04:01,950 --> 00:04:06,750
Once again we get an error because the load movies method can through a file not found exception.
52
00:04:07,290 --> 00:04:08,760
This is a tactics option.
53
00:04:08,760 --> 00:04:12,960
So if you want to call this method, Java is going to force you to try to run the code.
54
00:04:19,810 --> 00:04:24,160
And if the code happens to fail, you need to catch the file, not a found exception.
55
00:04:31,070 --> 00:04:33,170
And we'll just print the message that comes out of it.
56
00:04:37,180 --> 00:04:37,390
Here.
57
00:04:37,390 --> 00:04:38,290
We're going to print.
58
00:04:47,970 --> 00:04:49,030
Movies loaded.
59
00:04:49,050 --> 00:04:50,460
Followed by two lines.
60
00:04:51,750 --> 00:04:54,090
Then we'll print the two string of the store object.
61
00:04:57,770 --> 00:04:57,980
And.
62
00:04:57,980 --> 00:05:00,170
Okay, I want to test everything before moving on.
63
00:05:00,170 --> 00:05:03,140
We write a lot of code and went at a break point right here.
64
00:05:09,240 --> 00:05:10,380
Launch the debugger.
65
00:05:11,520 --> 00:05:12,840
And step into the function.
66
00:05:15,210 --> 00:05:19,440
I'll step over creating the file input stream as well as the scanner object.
67
00:05:20,160 --> 00:05:24,120
The wire loop runs through every line in the movie file injury each run.
68
00:05:24,120 --> 00:05:25,800
We're picking up the entire line.
69
00:05:31,850 --> 00:05:35,060
Then we're splitting the line around every pair of hyphens.
70
00:05:37,190 --> 00:05:39,920
As a result, we get an array with three values.
71
00:05:40,550 --> 00:05:45,200
Then we're using these values to create a new object and add it to the collection of movies.
72
00:05:45,920 --> 00:05:46,650
And you know what?
73
00:05:46,670 --> 00:05:48,820
I'll never get bored of visualizing code.
74
00:05:48,830 --> 00:05:49,700
It's really cool.
75
00:06:00,190 --> 00:06:03,130
Now there are a lot of movies, so I'll start the debugger here.
76
00:06:08,810 --> 00:06:10,280
And that's all for tasks.
77
00:06:10,280 --> 00:06:11,150
One, two and three.
78
00:06:12,470 --> 00:06:14,780
In the next video over an implement task for.
6861
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.