Return to Video

Dont Print in Drive - Intro to Java Programming

  • 0:00 - 0:06
    We had to make changes in two classes, the car class and the stimulation class.
  • 0:06 - 0:11
    In the car class, we now return an ArrayList which is allocated here, we add a
  • 0:11 - 0:18
    passenger to that ArrayList, whenever one has reached his destination. And all
  • 0:18 - 0:24
    the way in the end, we return that ArrayList as the return value of the method.
  • 0:24 - 0:28
    Did you modify the Java Doc, to add an add return statement. If so, pat
  • 0:28 - 0:33
    yourself in the back. In the drives car method, we call the drive method. That
  • 0:33 - 0:37
    returns an ArrayList. For each person in that ArrayList, we print the drop off
  • 0:37 - 0:43
    message. Note, that I didn't even bother to save the return value of the drive
  • 0:43 - 0:48
    method in a variable. You can of course and you may find that it makes the code
  • 0:48 - 0:54
    easier to understand. But here I say c.drive returns an ArrayList. And for
  • 0:54 - 1:00
    every person in that ArrayList, I do something with this loop. Now, we have
  • 1:00 - 1:03
    achieved the goal of our reorganization. The car class no longer knows anything
  • 1:03 - 1:08
    about system.out. The Simulation class does, but that doesn't bother me so much
  • 1:08 - 1:12
    because that simulation class also needed to know about system.in to read the
  • 1:12 - 1:18
    user input. So the simulation class deals with input and output, the car and
  • 1:18 - 1:23
    person class are blessedly unaware of that. Congratulations for having worked
  • 1:23 - 1:26
    through such a complex example. Real life code does look like that, with lots
  • 1:26 - 1:33
    of classes. And in the next unit, you will see the Java way of organizing
  • 1:33 - 1:36
    related classes.
Title:
Dont Print in Drive - Intro to Java Programming
Description:

19-44 Don't Print in Drive

more » « less
Video Language:
English
Team:
Udacity
Project:
cs046: Intro to Programming
Duration:
01:37

English subtitles

Revisions Compare revisions