import javax.swing.*;
import java.text.*;
public class UG3 {
public static void main (String[] arg) {
String radius = JOptionPane.showInputDialog("Input Radius");
String height = JOptionPane.showInputDialog("Input Height");// input radius and height.
try { // trying to make sure that the user inputs information otherwise it will cancel.
int rad = Integer.parseInt(radius);
int hei = Integer.parseInt(height);
NumberFormat r = NumberFormat.getInstance();
r.setMaximumFractionDigits(2);
r.setMinimumFractionDigits(2);
JOptionPane.showMessageDialog(null, "The volume of the cylinder is approximately "+ r.format(volume) +"CM^3"); // output results. // Here is the problem " volume " is: "cannot be resolved".
int yes = JOptionPane.showConfirmDialog(null, "Would you like to find the volume of a cylinder once more?", "", JOptionPane.YES_NO_OPTION);
if(yes == JOptionPane.YES_OPTION) {
main(arg);
}
else {
JOptionPane.showMessageDialog(null, "You'r welcome! \n \n Click 'OK' to exit", "Cylinder.", JOptionPane.ERROR_MESSAGE);
}
}
catch (NumberFormatException e) { // cancel.
JOptionPane.showMessageDialog(null, "Sorry but you have to enter radius and height to complete the task.");
}
} //main
public static double volume(double radius, double height){
return Math.PI * Math.pow(radius,2) * height;
}
}//Cylinder
I wrote "comments" to show you where. Anyway, "volume cannot be resolved" why? Did I miss to delete something from the first method? is something missing? Can't get my head around it. :S