or by selecting the Applications/Programming/NetBeans IDE 6.5 option in the toplevel window bar of your desktop.
Once NetBeans is ready, select the File/New Project... option in the toplevel menu bar. In the list boxes labeled Categories: and Projects: appearing in the first dialog, select Java and Java Application respectively. In the second dialog, enter Lab03 as the Project Name. Also make sure that the Project Location (the folder that will contain your Lab03 project folder) is set to csci/273.002/labs under your account. If it is set to anything else, edit the Project Location textbox now to make sure NetBeans will create your project in your labs folder. Remember also to uncheck the Create Main Class checkbox. Otherwise, accept the default settings and click Finish.
Now go to the NetBeans explorer window. Make sure that the Projects view is selected, open your Lab03 project, then open Source Packages, and look for <Default Package>. Remember that if you want to create a new Java class in the default package, you can right-click on <Default Package> and select the type of class you want (Java class, Java main class, Empty Java file), and start editing.
Caution: Remember that the Booksite listings come in two versions. The first version you see displays the source listing in the form of an HTML file, which includes visual features intended to improve human readability. You want to click the first link at the top of the HTML listing to display a plain-text file. In all cases, you should download only plain-text versions into your NetBeans projects.
Remember that Lab03.jar contains only the bytecode (.class) files for the project classes, not the project source files. But as you saw in your previous labs, you can use a terminal window to run any of the classes in your project from this JAR file. So return to your terminal window at this point, and make an initial test of each Booksite program in your project by entering the following commands:
Note: the first of these commands assumes that your default directory was previously set to csci/273.002/labs. If you are not sure about this, replace the first command by
cd Lab03 java -cp dist/Lab03.jar PowersOfTwo 20 java -cp dist/Lab03.jar Harmonic 100 java -cp dist/Lab03.jar Sqrt 2.0 java -cp dist/Lab03.jar Binary 255 java -cp dist/Lab03.jar Factors 6
Once you have verified that all the programs are running properly, make more detailed tests of the following selected programs. For each input, try to understand the program output.
java -cp dist/Lab03.jar PowersOfTwo 30 java -cp dist/Lab03.jar PowersOfTwo 31 java -cp dist/Lab03.jar PowersOfTwo 32
java -cp dist/Lab03.jar Binary 1 java -cp dist/Lab03.jar Binary 2 java -cp dist/Lab03.jar Binary 7 java -cp dist/Lab03.jar Binary 15 java -cp dist/Lab03.jar Binary 2147483647 java -cp dist/Lab03.jar Binary 2147483648
java -cp dist/Lab03.jar Factors 26 java -cp dist/Lab03.jar Factors 52 java -cp dist/Lab03.jar Factors 32767 java -cp dist/Lab03.jar Factors 2147483647
java -cp dist/Lab03.jar Sqrt 2 java -cp dist/Lab03.jar Sqrt -2
Checkpoint 1: Let your lab instructor know you are ready to show that you can run each of these programs from the terminal window. Be prepared for requests to explain your previous results, and also to experiment with additional command-line arguments for some of them.
Checkpoint 2: Demonstrate your program to your lab instructor, using the terminal window to supply the argument.
Note: the algorithm used in Sqrt is actually a special case of Newton's method for finding roots of a function f(x), namely solutions of the equation f(x) = 0. In general, Newton's method is an iterative scheme, in which an initial guess at a root, say x0, is repeatedly updated using the formula
where fi = f(xi) and (df/dx)i is just the derivative of f evaluated at xi. Note that for Sqrt, the equation is just f(x) = x2 - C = 0, where the constant C is the input argument. Similarly, for Cbrt the equation is f(x) = x3 - C = 0. So hopefully from this much information, and the source code for Sqrt, you should be able to figure out the precise iteration scheme to use for Cbrt... but if necessary, you can get some guidance at this point from your lab instructor.
Checkpoint 3: Demonstrate your program to your lab instructor, using the terminal window to supply the argument.
Checkpoint 4: Demonstrate your program to your lab instructor, using the terminal window.
After your instructor has checked out the various stages of your project, you are almost finished with the lab. But before you exit NetBeans, clean your Lab03 project. Then reset the default directory in your terminal window to be csci/273.002/labs again. Note: if your default directory is still set to csci/273.002/labs/Lab03, the easiest command to move one level "upstairs" is just
Now create a JAR file of your complete Lab03 project development folder, using the command
jar cf Lab03Project.jar Lab03Recall that this JAR file differs from the Lab03.jar file that NetBeans creates in the dist project folder when you Build a project. Lab03.jar is a distribution JAR file, suitable only for running Java programs, not writing or compiling them. Lab03Project.jar contains your entire project development folder, including all your sources and NetBeans project management files.
For future reference, remember that you can upload a NetBeans project development JAR file to another system running NetBeans, extract its contents via a command similar to
and use NetBeans to Open your project and continue working on it.
jar xf Lab03Project.jar
Please leave both your Lab03 project folder and Lab03Project.jar in your csci/273.002/labs directory for the remainder of the semester.