Step 4: How to import files into an Eclipse Project

Launch Create Class Import Run Handin previous
step next step

You now have a class, PairOfDice, with no syntax errors or warnings, but you still need to test whether the class works as expected. We need a driver program which uses the class PairOfDice and which can be executed. I have written a Java program called PairOfDiceDriver.java to test our class. You probably do not want to copy the text, so we will import the file into our project.

The driver program PairOfDiceDriver.java is actually a file containing a Java class, PairOfDiceDriver with a single method, main. This class can be run as a stand-alone program. The program creates two PairOfDice and rolls both pairs until they each have the same sum. The program records the result of each roll, then displays how many rolls were required before both pairs produced the same sum.

  1. Download the file PairOfDiceDriver.java into your cs102 directory.

  2. Right-click (<ctrl> + mouse-click for the Mac) on the Default Package in the Project Manager pane underneath your project PairOfDice. Choose Import
    Import

  3. An Import Wizard window will display. Choose File system and select the Next button
    Import

  4. You are now prompted to choose a file
    Import
    Use the Browse button or type the path to the directory cs102 to display the following update to the Import Wizard
    Import

  5. Now click on the box next to cs102, which will display the files in this directory. Select PairOfDiceDriver.java. Your screen should look like
    Import

  6. You want to make sure you are only importing PairOfDiceDriver.java. Click on the arrow next to cs102 to display the subfolders:
    Import

  7. Uncheck all subfolders (.metadata and PairOfDice in this example)
    Import

  8. Now click on the Finish button. Your workspace will be displayed with the new file PairOfDiceDriver.java:
    Import

You are now ready to Run the program!!
Launch Create Class Import Run Handin previous step next step