Return to Video

Reorganizing the Carshare Classes - Intro to Java Programming

  • 0:00 - 0:05
    For the CarShareApp, we crated four classes. There was the CarShareApp, which
  • 0:05 - 0:11
    used the simulation, which used cars and persons. The simulation and car
  • 0:11 - 0:16
    classes go together and are specific to the CarShareApp. The person is more
  • 0:16 - 0:21
    general and could possibly be used for other situations. These three classes
  • 0:21 - 0:25
    could be organized into packages. The person class might go into a more
  • 0:25 - 0:30
    general, com.udacity package, and the simulation and car, would go in a more
  • 0:30 - 0:36
    specific, carshare package. The CarShareApp, is just a main program, that we're
  • 0:36 - 0:41
    writing that uses these other things, so we'll keep it in the default package.
  • 0:41 - 0:45
    Creating packages in BlueJ is a little bit funny, so I'll show you how to do
  • 0:45 - 0:50
    this. From the car share project. I'm going to look up at the menu. It's at the
  • 0:50 - 0:55
    upper left for me, but it might be right along this bar for you. I'll go to
  • 0:55 - 1:01
    Edit> New Package, and then put in the package name. Com.udacity.carshare. Now
  • 1:01 - 1:09
    the package appears here in Bluejay. I can open it up. This is the com package.
  • 1:09 - 1:13
    This is the Udacity package and this is the Car-share package in the Car-share
  • 1:13 - 1:19
    package I want to put the car in simulation classes. So to do that i will go to
  • 1:19 - 1:23
    that Edit menu again and then I select Add Classroom file and then inside the
  • 1:23 - 1:29
    folder that contains all of the Car-share I'll select the car and add it. Now
  • 1:29 - 1:33
    the car shows up in the Car-share package. But I need to add the simulation
  • 1:33 - 1:40
    too. Edit > Add Classroom File > Simulation > Add. Now in the Udacity package I
  • 1:40 - 1:46
    want to add the person. Edit > Add Classroom File and this time I'll select
  • 1:46 - 1:51
    Person. And now its here, so this compiles but if I go back to the Car-share
  • 1:51 - 1:57
    package and try to compile these or find cannot find symbol class. That's
  • 1:57 - 2:01
    because person is no longer right beside simulation so i have to tell Java
  • 2:01 - 2:07
    where to look for the person class. Where do I look for the person class? In
  • 2:07 - 2:14
    com.udacity. Now before I ask you a question, I've got one more clean up task.
  • 2:14 - 2:17
    Right now there are actually two persons. There's one in com Udacity, and
  • 2:17 - 2:21
    there's one in Car-share seven. So, all of the classes that I copied into
  • 2:21 - 2:26
    different packages, I need to remove. So I'll remove car, and it's okay that
  • 2:26 - 2:32
    I'm permanently removing it because I copied it. And then I'll remove person
  • 2:32 - 2:37
    and I'll remove simulation. So like I just mentioned, right now Car isn't
  • 2:37 - 2:41
    compiling. What import statements would you need to add to this project to make
  • 2:41 - 2:45
    it compile again? Go ahead and reorganize all of the classes into the right
  • 2:45 - 2:51
    packages. Then to get the CarShareApp running again. To which class should I
  • 2:51 - 2:56
    add the import com.udacity.person? Write none if I never need to import this.
  • 2:57 - 3:03
    To which class should I add the import com.udacity.carshare.car? And to which
  • 3:03 - 3:07
    close should I add the import com.udacity.carshare.simulation? And remember
  • 3:07 - 3:11
    write none if you never use a particular import statement. And separate answers
  • 3:11 - 3:15
    with commas, if you find that there are two classes that use the same import.
Title:
Reorganizing the Carshare Classes - Intro to Java Programming
Description:

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

English subtitles

Revisions Compare revisions