



Calculate the volume of a sphere.
Make sure to import java.util.Scanner;
Post your code here.






More Options ...

Categories
Tag Cloud
Blog RSS
Comments RSS
Void (Default)
Life
Earth
Wind
Water
Fire
Lightweight
10:31 pm - April 5th, 2009
12 Mar 09 6:55 PM MST
Hello I went with the GUI version. To summarize all of my files, the main part of my code is this:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//double radius = input.nextDouble();
float radius;
radius = Float.parseFloat(jTextField1.getText());
double volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius , 3 );
jTextField2.setText(String.valueOf(volume));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// this will clear the radius input/textbox field
jTextField1.setText(”");
jTextField2.setText(”");
}
That right there is the program in action!
Now take a look at the screen shot to see proof of my program running:
10:34 pm - April 5th, 2009
10:37 pm - April 5th, 2009
12 Mar 09 7:01 PM MST
All of the following text files contains the code to complete my project, it does not contain all of the resources though, if you were to copy my code and run it, you will have errors. I’ll create another post that will allow everyone in the class to download my code and run it on NETBEANS or ECLIPSE!
But, if you want to take a look at my Code, these 3 files are it!
ryanvolumeofsphereview.txt
ryanvolumeofsphereaboutbox.txt
ryanvolumeofsphereaboutapp.txt
10:38 pm - April 5th, 2009
12 Mar 09 7:11 PM MST
OK, This post contains the COMPLETE package of everything in my project. If you want to try my code, Download this package and unzip it into your NETBEANS package folder. You know, that folder that contains all of your saved projects and work(s).
If you want to run, open, edit and save the project with eclipse, download my file and use the information on this website:
http://dguitar.sourceforge.net/en/EclipseAndNetbeans.html
it contains the information to help you open and adapt my code to eclipse.
Also, if you are having trouble, just let me know I’ll walk you through creating a GUI in eclipse with my posted code. It’s simple, Create a form, add 2 text boxes, 2 buttons and 3 or 4 labels. The calculate button contains my posted code and the clear button is to clear both text boxes.
this is the code of the calculate button:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//double radius = input.nextDouble();
float radius;
radius = Float.parseFloat(jTextField1.getText());
double volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius , 3 );
jTextField2.setText(String.valueOf(volume));
}
this is the code of the clear button:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// this will clear the radius input/textbox field
jTextField1.setText(”");
jTextField2.setText(”");
}
And you will have a running program (granted you import the proper packages, which eclipse does for you automatically)!
10:48 pm - April 5th, 2009
Brooke Estabrook-Fishinghawk 13 Mar 09 7:24 AM MST
Response to Ryan
It is great that you take the extra step to go with thr GUI version. While it takes more time the added effort is well worth the skill level.