Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,400 --> 00:00:05,170
In this video, we're going to cover the solution for part one, like before each class that models
2
00:00:05,170 --> 00:00:09,310
an object was placed inside the models folder and the main class is by itself.
3
00:00:10,350 --> 00:00:14,520
We're going to start with task one, which is that all the necessary fields to the movie class.
4
00:00:16,550 --> 00:00:18,800
Into the fields are private string name.
5
00:00:21,540 --> 00:00:22,800
Private string format.
6
00:00:27,240 --> 00:00:28,590
Private double orating.
7
00:00:31,340 --> 00:00:33,470
Private double selling price.
8
00:00:40,340 --> 00:00:42,320
Private double rental price.
9
00:00:46,910 --> 00:00:52,850
And a private boolean field named is available is going to determine whether the movie is in stock or
10
00:00:52,850 --> 00:00:53,390
rented.
11
00:00:57,710 --> 00:01:02,120
And task to reminds us that if a class has failed and needs to apply the big three steps, the first
12
00:01:02,120 --> 00:01:03,560
step is to create a constructor.
13
00:01:03,920 --> 00:01:06,620
But once again, it's only going to receive three parameters.
14
00:01:06,620 --> 00:01:08,630
String name, string format.
15
00:01:11,400 --> 00:01:12,360
Double orating.
16
00:01:17,170 --> 00:01:21,230
Here is where we set every field in that object equal to a parameter value.
17
00:01:21,600 --> 00:01:22,420
The name.
18
00:01:24,410 --> 00:01:25,520
This format.
19
00:01:30,410 --> 00:01:31,460
This stock rating.
20
00:01:39,630 --> 00:01:44,220
As I'm updating the selling price, first, I'll check if the format equals Blu ray.
21
00:01:50,610 --> 00:01:56,220
If so, I'll set the value equal to four point twenty five, otherwise two point twenty five.
22
00:02:00,110 --> 00:02:04,130
I'll do the same thing for the rental price, I'll check if the format is blue, right?
23
00:02:04,400 --> 00:02:07,070
If so, I'll set the value to one ninety nine.
24
00:02:12,110 --> 00:02:14,120
Otherwise, 99 cents.
25
00:02:18,070 --> 00:02:21,400
And that first is available is going to be true for every movie.
26
00:02:28,440 --> 00:02:31,140
Next thing we want to do is autocomplete, the gutters and setters.
27
00:02:56,700 --> 00:03:02,010
Now, getas for bullion types are written differently, if you try to write get, you're not going to
28
00:03:02,010 --> 00:03:02,980
get any results.
29
00:03:12,600 --> 00:03:19,290
That's because the standard naming for Boolean getters is to preface the field with is followed by the
30
00:03:19,290 --> 00:03:19,860
field name.
31
00:03:20,370 --> 00:03:21,570
Here are some examples.
32
00:03:24,940 --> 00:03:29,800
And in our case, the field already starts with and is so the gutter is just going to share the same
33
00:03:29,800 --> 00:03:30,060
name.
34
00:03:30,760 --> 00:03:33,100
Going back to the code if you write is.
35
00:03:34,390 --> 00:03:38,400
This code recognizes that you want to autocomplete a getter for your boolean.
36
00:03:39,410 --> 00:03:41,800
OK, now we can just autocomplete the suttas.
37
00:04:02,850 --> 00:04:08,520
However, we're going to make selling price private, we need to hide this setar because the color shouldn't
38
00:04:08,520 --> 00:04:09,570
be allowed to use it.
39
00:04:11,450 --> 00:04:15,560
That's because the format they pass in should automatically determine the selling price.
40
00:04:18,459 --> 00:04:23,220
So instead of set format, it needs to update the format and update the selling price, so we'll call
41
00:04:23,250 --> 00:04:29,890
set selling price and the value we pass in into selling price will be based on a condition if it equals
42
00:04:29,890 --> 00:04:30,460
Blu ray.
43
00:04:33,360 --> 00:04:35,370
We're going to pass in 425.
44
00:04:37,460 --> 00:04:39,830
Otherwise, we'll pass to 25.
45
00:04:40,690 --> 00:04:46,630
And the beauty about the syntax is that it replaces six lines because otherwise you'd have to write
46
00:04:46,630 --> 00:04:47,610
something like this.
47
00:04:48,550 --> 00:04:54,850
It's totally fine if you want to use a false, but I just prefer keeping the code as short, as concise
48
00:04:54,850 --> 00:04:55,570
as it can be.
49
00:04:59,930 --> 00:05:03,470
Anyways, we'll do the same thing for Ronald Price will make it private.
50
00:05:10,140 --> 00:05:13,350
And once again, we're going to check if format equals Blu ray.
51
00:05:19,590 --> 00:05:22,050
In which case, we're going to pass 199.
52
00:05:26,340 --> 00:05:28,200
Otherwise, 99 cents.
53
00:05:29,960 --> 00:05:34,190
Now, I know that we're supposed to test our code and task five, but it doesn't hurt to test what we
54
00:05:34,190 --> 00:05:34,840
have so far.
55
00:05:40,300 --> 00:05:42,730
And an important movie from the model's package.
56
00:05:48,920 --> 00:05:53,720
And now that I've imported the class, I can use it, first thing I'll do is create a new object of
57
00:05:53,720 --> 00:05:54,950
the movie store costs.
58
00:05:59,880 --> 00:06:02,040
The move is going to be The Shawshank Redemption.
59
00:06:05,720 --> 00:06:07,670
It will have a Blu ray format.
60
00:06:18,950 --> 00:06:22,760
In any case, we'll put a break point right here, I'll step into the constructor.
61
00:06:39,560 --> 00:06:42,290
This points to the current object we just created.
62
00:06:43,290 --> 00:06:48,810
It updates every field, it sets the selling price, the twenty five, because the format is blurry
63
00:06:49,260 --> 00:06:53,940
and it sets the rental price to one ninety nine once again, because the format is Blu ray.
64
00:06:57,730 --> 00:07:00,040
OK, now we can test the format setter.
65
00:07:01,750 --> 00:07:03,580
We'll change the format to DVD.
66
00:07:12,150 --> 00:07:13,410
Relaunch the debugger.
67
00:07:15,340 --> 00:07:17,410
I'm going to step over creating the object.
68
00:07:22,760 --> 00:07:28,550
And setting the format automatically determines the selling price as well as the rental price, great.
69
00:07:30,230 --> 00:07:35,600
Now we can move on to tasks three and four, the next step is that a copy constructor, because at some
70
00:07:35,600 --> 00:07:40,150
point we need a way to copy moving objects without falling into the reference trap.
71
00:07:40,160 --> 00:07:42,980
So I'm simply going to copy this constructor.
72
00:07:43,370 --> 00:07:47,180
And instead of parameters, we're going to be obtaining values from a source object.
73
00:07:51,200 --> 00:07:56,100
Then I'm going to set every field in the current object equal to the field value from a source object,
74
00:07:56,120 --> 00:07:57,110
nothing new here.
75
00:08:17,340 --> 00:08:18,830
Let's visualize what's going on.
76
00:08:23,210 --> 00:08:28,370
Back in Maine, I'm going to create a new movie object that copies every field value from this one.
77
00:08:35,960 --> 00:08:38,600
Take out a breakpoint to visualize the runtime.
78
00:08:48,870 --> 00:08:54,900
This points to the new contact object that we just created, Saurus points to the object that we passed
79
00:08:54,900 --> 00:09:00,240
in, and one by one, we're copying every value from the source object into the current object.
80
00:09:10,370 --> 00:09:14,690
And the next task tells us that every class that models an object should have a two string method,
81
00:09:14,870 --> 00:09:18,710
dominate a two string method to our class public string to string.
82
00:09:23,040 --> 00:09:26,280
And then you're going to copy over the format that I left you from the article.
83
00:09:40,140 --> 00:09:42,450
And who replaced the placeholders where we need to?
84
00:10:01,190 --> 00:10:02,780
Now, four is available here.
85
00:10:02,810 --> 00:10:07,730
We're going to check if the movie object that's calling the two string method if it is available.
86
00:10:12,540 --> 00:10:16,050
And if this ends up being true, we're going to return in stock.
87
00:10:17,380 --> 00:10:19,900
Otherwise, we're going to return a rented.
88
00:10:40,290 --> 00:10:42,330
All right, we're done creating the movie class.
89
00:10:49,270 --> 00:10:51,610
And inside main, I'm going to print the object.
90
00:11:07,630 --> 00:11:09,260
And everything works beautifully.
91
00:11:09,610 --> 00:11:12,820
Notice that it shows in stock because the movie is available.
92
00:11:18,990 --> 00:11:21,660
We can try setting the availability to false.
93
00:11:33,470 --> 00:11:35,840
And this time it shows the movie is rented.
8867
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.