Discussion of Activity 3.2 - Using the CarTracker class

We have supplied a separate solution file called TreasureHunt_Solution.java, which shows one way to solve the problem.

Notice that there are two classes in this project that have main methods: TreasureHunt_Solution and the class we asked you to edit to write your own solution, called TreasureHunt.

There is more than one approach to running the solution file.

  1. Select the node TreasureHunt_Solution.java in the Projects window. Right-click on this file name and choose Run File.
  2. An alternative approach to use when you want to change the default main class is to edit the information contained in the project properties. In the Projects window, right-click on the project node Ex3_2 and choose Properties. When the Project Properties window opens, click Run in the Categories: pane at the left. The Main Class for the project is currently ex3_2.TreasureHunt.

  3. The project properties dialogue

    Click the Browse button and the Browse Main Classes dialogue will open. Click on ex3_2.TreasureHunt_Solution to select it as the main class.

    selecting an alternative main class

    Click the Select Main Class button, and then OK.

    Now TreasureHunt_Solution.java can be run by choosing Run|Run Main Project or by clicking the Run Main Project button on the NetBeans toolbar.

Note that the class you choose as the main class needs to contain a main method.