This lab will give you a chance to work with several examples of library classes in Java. Some of your tasks will involve downloading and running applications that use methods defined in one or more library classes available on the Booksite for your text. Such programs are known as clients of the libraries. You will also have a chance to write a new version of one of the Booksite client applications. And you will even write a small Java library of your own, containing some simple but useful mathematical functions.
You can find useful background information on libraries and clients in Section 2.2 of your text.
To complete this project, follow the steps listed below:
Otherwise, you now need to put a copy of Booksite1.jar into your csci/273/labs folder. Assuming that the default directory in your terminal window is still set to csci/273/labs, you can do this by entering the following command:
Note: be sure not to leave out the dot (.) at the end of the line... and please type at least one space before the dot...
cp Booksite1/dist/Booksite1.jar .
In your earlier labs you did this using a brute-force approach: you downloaded all the sources (.java files) for the library classes you needed, placing them directly into the default directory for your project. This time you will use a more elegant (and more efficient) method: you will add the JAR file Booksite1.jar to the classpath for your Lab08 project. This will automatically make all the Booksite classes that you downloaded into Booksite1.jar available to any client program you write in Lab08. Of course Booksite1.jar contains only the bytecode (.class) files, not their sources, but the bytecode is all your client programs will need.
A good way to add any JAR file (or folder) to a project classpath in the NetBeans IDE is to select the Projects view, right-click on the Lab08 project name, and select the Properties option in the popup menu. This should raise a property sheet dialog that initially appears as shown below:
In the left-hand panel labeled Categories, select Libraries. The initial dialog should then be replaced by one that looks like this:
In the right-hand panel of the resulting dialog, select Add JAR/Folder. Clicking this should raise the subdialog
Find and select Booksite1.jar, then click Open to add it to your project classpath.
Open IFS.java in the NetBeans editor window. If you immediately see lots of red lines, that probably means that somehow you did not actually manage to add Booksite1.jar to your classpath in the last step. It might also be possible that you omitted one or more of the required files in Booksite1. In any event, if you cannot resolve the problem(s) by yourself, consult with your lab instructor before you attempt to go further.
As soon as the NetBeans editor seems to be happy with IFS.java, open Bernoulli.java in the editor window and make sure it is also free of red lines. Then attempt to Build your Lab08 project. This step should cause you no problems, since you are just compiling unmodified Booksite source files. But if anything seems to go wrong at this stage, it is again time to alert your lab instructor.
To keep all these files in one convenient place, you should now create a new subfolder of Lab08 named, say, IFSData. Then download the files sierpinski.txt, barnsley.txt, and coral.txt into IFSData. Note that these examples were all downloaded from the Booksite and stored locally for your convenience. Incidentally, with a little detective work you should be able to download several more IFS data files directly from the Booksite.
So hopefully you now understand why the command you should now enter is
So try to type all this in, and stand back...
java -cp dist/Lab08.jar:../Booksite1.jar IFS 10 < IFSData/sierpinski.txt
Not very impressive? Essentially just a blank window? Well, if you look closely enough, you just might be able to see a few barely discernable points scattered around.
OK, so close this window and try increasing the value 10 in this command to 100. Repeat using 1000, then 10000, and maybe even 100000. By that time you should have a much better idea of what is going on. And you certainly should now take time to check out the other examples cited above.
The purpose of this exercise is certainly not to make you an expert on Iterated Function Systems, but it does illustrate how much you can benefit from well-designed libraries. Look in particular at the source code for IFS.java, and you will have to admit that it is very short. Part of that is due to the fact that it is data-driven, meaning that it uses a very general format that allows the same code to process a wide variety of transformations. But the use of library methods to handle various subtasks is an even more important factor in reducing the size of client programs. If client programs had to include explicit code to do all the work by themselves, they would be much longer.
The primary reason for including this program here is to introduce you to some useful array-plotting methods in the Booksite library StdStats.
Try running Bernoulli using the following command:
While the plot window is still open, you should look over the source code for Bernoulli in the NetBeans editor and try to understand just how the plot was generated. While you are at it, note again how little code it takes to do this sort of thing if suitable library classes are available to you.
java -cp dist/Lab08.jar:../Booksite1.jar Bernoulli 50 10000
As soon as you write this class and manage to compile it, show your source code to your instructor.
Extra Credit, up to 20 extra points: Add a separate Java main class named PlotHyperbolics to your Lab08 project. Using your Hyperbolics library, have PlotHyperbolics produce a combined plot of sinh(x) and cosh(x). The results should at least vaguely resemble the image shown below:
When your project is complete and working correctly, demonstrate it to your lab instructor. Then, before you exit NetBeans, clean your Lab08 project. Finally, before you logout, switch back to your terminal and set your default directory back to csci/273/labs. Then create a JAR file of your Lab08 project folder, using the command
jar cf Lab08Project.jar Lab08Please leave both your Lab08 project folder and Lab08Project.jar in your csci/273/labs directory for the remainder of the semester.