WEBVTT

00:00:00.790 --> 00:00:03.190
The following content is
provided under a Creative

00:00:03.190 --> 00:00:04.730
Commons license.

00:00:04.730 --> 00:00:07.030
Your support will help
MIT OpenCourseWare

00:00:07.030 --> 00:00:11.390
continue to offer high-quality
educational resources for free.

00:00:11.390 --> 00:00:13.990
To make a donation or
view additional materials

00:00:13.990 --> 00:00:17.880
from hundreds of MIT courses,
visit MIT OpenCourseWare

00:00:17.880 --> 00:00:18.850
at ocw.mit.edu.

00:00:23.473 --> 00:00:24.014
ANA BELL: OK.

00:00:27.330 --> 00:00:30.570
We have our class.

00:00:30.570 --> 00:00:35.730
We've done pretty much
everything up until here,

00:00:35.730 --> 00:00:40.480
and we're going to add
this special function here.

00:00:40.480 --> 00:00:42.480
So we're implementing
this underscore underscore

00:00:42.480 --> 00:00:45.650
eq underscore underscore.

00:00:45.650 --> 00:00:49.700
And implementing this
is going to allow us

00:00:49.700 --> 00:00:51.990
to compare two types of cars.

00:00:55.200 --> 00:00:57.570
So the way I've decided to
compare two types of cars

00:00:57.570 --> 00:01:00.180
is I'm saying the
two cars are going

00:01:00.180 --> 00:01:02.370
to be equal if they have
the same number of wheels,

00:01:02.370 --> 00:01:03.911
they have the same
color, and if they

00:01:03.911 --> 00:01:08.542
have the same number of doors.

00:01:08.542 --> 00:01:09.410
OK?

00:01:09.410 --> 00:01:13.540
So if all of these are
equal, then return true

00:01:13.540 --> 00:01:14.665
and else return false.

00:01:18.440 --> 00:01:20.390
Inside the actual
program here, I'm

00:01:20.390 --> 00:01:23.300
creating one car, four
wheels, two doors.

00:01:23.300 --> 00:01:25.280
I'm changing its color to red.

00:01:25.280 --> 00:01:29.420
I'm creating another car--
four wheels, two doors.

00:01:29.420 --> 00:01:33.020
By default, this new
car, or your car,

00:01:33.020 --> 00:01:34.850
is going to have the
color empty string,

00:01:34.850 --> 00:01:38.610
because that's how a new
car gets initialized, right?

00:01:41.640 --> 00:01:44.810
So between my car and
your car, the difference

00:01:44.810 --> 00:01:46.020
is going to be the color.

00:01:46.020 --> 00:01:46.760
OK?

00:01:46.760 --> 00:01:48.035
So the color is not
going to be the same,

00:01:48.035 --> 00:01:49.280
but they have the
same number of wheels

00:01:49.280 --> 00:01:50.488
and the same number of doors.

00:01:52.810 --> 00:01:57.220
So because I implemented
the equal method in my code,

00:01:57.220 --> 00:01:59.200
this does not throw an error.

00:01:59.200 --> 00:02:00.580
This lets me proceed.

00:02:00.580 --> 00:02:03.000
It compares four with
four, which is good,

00:02:03.000 --> 00:02:04.250
two with two, which is good.

00:02:04.250 --> 00:02:06.100
And then the colors
don't match, so it's

00:02:06.100 --> 00:02:09.479
going to say false,
which most of the guys

00:02:09.479 --> 00:02:11.133
are getting it right.