1 00:00:00,790 --> 00:00:03,190 The following content is provided under a Creative 2 00:00:03,190 --> 00:00:04,730 Commons license. 3 00:00:04,730 --> 00:00:07,030 Your support will help MIT OpenCourseWare 4 00:00:07,030 --> 00:00:11,390 continue to offer high-quality educational resources for free. 5 00:00:11,390 --> 00:00:13,990 To make a donation or view additional materials 6 00:00:13,990 --> 00:00:17,880 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,880 --> 00:00:18,850 at ocw.mit.edu. 8 00:00:23,473 --> 00:00:24,014 ANA BELL: OK. 9 00:00:27,330 --> 00:00:30,570 We have our class. 10 00:00:30,570 --> 00:00:35,730 We've done pretty much everything up until here, 11 00:00:35,730 --> 00:00:40,480 and we're going to add this special function here. 12 00:00:40,480 --> 00:00:42,480 So we're implementing this underscore underscore 13 00:00:42,480 --> 00:00:45,650 eq underscore underscore. 14 00:00:45,650 --> 00:00:49,700 And implementing this is going to allow us 15 00:00:49,700 --> 00:00:51,990 to compare two types of cars. 16 00:00:55,200 --> 00:00:57,570 So the way I've decided to compare two types of cars 17 00:00:57,570 --> 00:01:00,180 is I'm saying the two cars are going 18 00:01:00,180 --> 00:01:02,370 to be equal if they have the same number of wheels, 19 00:01:02,370 --> 00:01:03,911 they have the same color, and if they 20 00:01:03,911 --> 00:01:08,542 have the same number of doors. 21 00:01:08,542 --> 00:01:09,410 OK? 22 00:01:09,410 --> 00:01:13,540 So if all of these are equal, then return true 23 00:01:13,540 --> 00:01:14,665 and else return false. 24 00:01:18,440 --> 00:01:20,390 Inside the actual program here, I'm 25 00:01:20,390 --> 00:01:23,300 creating one car, four wheels, two doors. 26 00:01:23,300 --> 00:01:25,280 I'm changing its color to red. 27 00:01:25,280 --> 00:01:29,420 I'm creating another car-- four wheels, two doors. 28 00:01:29,420 --> 00:01:33,020 By default, this new car, or your car, 29 00:01:33,020 --> 00:01:34,850 is going to have the color empty string, 30 00:01:34,850 --> 00:01:38,610 because that's how a new car gets initialized, right? 31 00:01:41,640 --> 00:01:44,810 So between my car and your car, the difference 32 00:01:44,810 --> 00:01:46,020 is going to be the color. 33 00:01:46,020 --> 00:01:46,760 OK? 34 00:01:46,760 --> 00:01:48,035 So the color is not going to be the same, 35 00:01:48,035 --> 00:01:49,280 but they have the same number of wheels 36 00:01:49,280 --> 00:01:50,488 and the same number of doors. 37 00:01:52,810 --> 00:01:57,220 So because I implemented the equal method in my code, 38 00:01:57,220 --> 00:01:59,200 this does not throw an error. 39 00:01:59,200 --> 00:02:00,580 This lets me proceed. 40 00:02:00,580 --> 00:02:03,000 It compares four with four, which is good, 41 00:02:03,000 --> 00:02:04,250 two with two, which is good. 42 00:02:04,250 --> 00:02:06,100 And then the colors don't match, so it's 43 00:02:06,100 --> 00:02:09,479 going to say false, which most of the guys 44 00:02:09,479 --> 00:02:11,133 are getting it right.