In this lab you will write client programs that work with the standard Java library class java.awt.Color. You will also test a Booksite client application based on a textbook class named Charge, which models pointlike electric charges. Some of your tasks are essentially just tests of these client demos. However, a few problems may require a bit of insight and creativity on your part.
To complete this project, follow the steps listed below:
You should definitely exercise your own design skills here, but it might help you to define more than one method in ColorStudy (not just the main() method). At the very least, that approach should reduce the amount of code that you have to write in main() itself.
When you have finished writing ColorStudy.java, Build the project again and run ColorStudy from the terminal window. When everything is working, show your results to your lab instructor.
Now take a quick look at Charge.java. In spite of the fact that this class contains a main() method, it does not represent an application, at least not in the same sense as most of the demos you have encountered up to this point. Instead, the class Charge serves as a blueprint for creating software objects that model real-world entities (in this case, electric charges). In this respect, Charge plays a role similar to the role that java.awt.Color plays in color-oriented graphics applications.
In contrast, Potential represents a client application that creates Charge objects and displays them using color plots. To keep things simple, it requires that all the charges lie in a plane (no 3D graphics here). You should now take a moment to look over the source code in Potential. Note in particular that it expects the standard input stream to provide the number of charges it must display, followed by the x-y coordinates and magnitude of each charge.
In this lab you will not be asked to define or even modify object-oriented classes like Charge, but you will need to understand how a client application like Potential can create and use Charge objects. This amounts to learning the so-called API (Applications Programming Interface) for the Charge class.
To start things off, build Lab11 again. Then create a new subfolder of Lab11 named data. Create a new, empty (text) file within data named "charges.txt", and initially copy the following lines into it:
2
0.3 0.5 10.0
0.7 0.5 10.0
When Potential reads this file it will create two charges,
whose x-y coordinates are
(0.3, 0.5) and (0.7, 0.5) respectively, where each
charge has magnitude 10.0. In case you care, these numbers
are all in standard MKS units. But of course you don't
need to care, at least not for the purposes of this lab.
Now run Potential from the terminal window, redirecting its standard input stream to charges.txt. Once you see what the display looks like for the values shown above, try changing the sign of the first charge (replace 10.0 by -10.0). Incidentally, this configuration of two opposite charges is known as an electric dipole. Then of course, please feel free to add more charges at various locations in the unit square, with varying charge magnitudes.
Your experimentation should not be confined just to the input data. If you go back to the source code for Potential, you should easily find that the author has actually included more than one possible way of defining the color at each (x,y) point. Only one choice is used, while the others have been commented out. Using a fixed data file, you should now try each of the other color plotting choices in turn (but remember that you will have to rebuild Lab11 after each change).
To complete the formalities, show your favorite results to your lab instructor.
When your project is complete and working correctly, demonstrate it to your lab instructor. Then, before you exit NetBeans, clean your Lab11 project. Finally, before you logout, switch back to your terminal and set your default directory back to csci/273.002/labs. Then create a JAR file of your Lab11 project folder, using the command
jar cf Lab11Project.jar Lab11Please leave both your Lab11 project folder and Lab11Project.jar in your csci/273.002/labs directory for the remainder of the semester.