Adding Formulas

frank3usc

Junior Member
Jan 16, 2003
16
0
0
Ok I have to make a program where I give it some formulas and it gives me the answers. Here is the what I have to do Program and here is the program.I have tried some things but it is not working for some reason. I got it working with the radius, now i gotta put in a formula for it to find the area, circumference, and diameter. I am not sure if i put it in the wrong place or what but any help would be appreciated.

/**
* radius.java
*
*
* Created: Mon Jan 27 13:34:56 2003
*
* @author <a href="mailto:Jonathan@DESKTOP"></a>
* @version
*/// Java packages
import javax.swing.JOptionPane;


public class radius{
public radius() {

}

public static void main(String[] args)
{
double radius=0;//in inches
double area;//in square inches
double diameter;//in inches
double circumference;//in inches
String radiusString=null;
boolean flag=true; //controls the loop


do {
try{
radiusString = JOptionPane.showInputDialog("Enter the radius of your circle in inches.");
if(radiusString==null) System.exit(0);//if cancel is selected
radius=Double.parseDouble(radiusString);
flag=false;
} catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null,"You entered "+radiusString+"\nPlease enter a positive number.");

}
} while(flag); //loops until a valid number is parsed
JOptionPane.showMessageDialog(null,"You entered "+radius);

public static void showArea(double radius)
{
double area = Math.PI * Math.pow(radius, 2);
JOptionPane.showMessageDialog(null, "The area of the circle = " + area);
}
public static void showDiameter(double radius)
{
double diameter = radius * 2;
JOptionPane.showMessageDialog(null, "The diameter of the circle = " + diameter );
}
public static void showCircumference(double radius)
{
double circumference = 2 * Math.PI * radius;
JOptionPane.showMessageDialog(null, "The circumference of the circle = " + circumference);
}
public static void showSmallestSquareArea(double radius)
{
double area = Math.pow(2 * radius, 2);
JOptionPane.showMessageDialog(null, "The minimum area of a square containing this circle = " + area );
}
public static void showBiggestSquareArea(double radius)
{ double area = Math.pow(2 * Math.sin(Math.PI / 4), 2);
JOptionPane.showMessageDialog(null, "The maximum area of a square contained in this circle = " + area );
};




} // radius

It is giving me this compiling error though:
CompileServer output:

c:/emacs-21.2/bin/radius.java
c:/emacs-21.2/bin/radius.java:41: illegal start of expression
public static void showArea(double radius)
^
1 error

Compilation exited abnormally with code 1 at Tue Jan 28 11:33:16