Java Error when compiling...

this is my error C:\My Documents\Math.java:6: '{' expected.

public class Math.java {

^

1 error

Tool completed with exit code 1

this is my code:

// Assignment1 Angel Amitrano

// J1 ASSN 1

import javax.swing.JOptionPane; //import class JOptionPane

public class Math.java {

public static void main ( String args [] )

{

String Math.PI// first string entered by user

int diameter

circumference

area

radius

//read in radius from user as a string

radius =

JOptionPane.showInputDialog ( "Enter Radius:" );

//convert numbers from type String to type int

diameter = Integer.parseInt ( diameter );

circumference = Integer.parseInt ( circumference );

area = Integer.ParseInt ( area );

//calculations

diameter = 2 * radius

circumference = 2 * Math.PI * radius

area = Math.PI * radius * 4

//Display the results

JOptionsPane.INFORMATION_MESSAGE(

null, "Diameter is "

null, "Area is "

null, "Circumference is ", "Results",

JOptionPane.PLAIN_MESSAGE );

System.exit(0); //terminate the program

}

}

id"

and this is what its supposed to do:

Write a Java application that inputs the radius of a circle from the user and then displays the circle's diameter, circumference, and area. Use the GUI techniques shown below for input and output. Use the predefined constant Math.PI for the value of . This constant is more precise than using 3.14159. Class Math is defined in the java.lang package, so you do not need to import it.

Use the following formulas (r is the radius):

diameter = 2r

circumference = 2 r

area = r2

I am screwed..can anyone help?

[1813 byte] By [Angell3] at [2007-9-26 7:05:34]
# 1
Try changing the line:public class Math.java {to:public class Math {Be sure to keep the file name Math.java - just change the source code.
atmguy at 2007-7-1 16:44:52 > top of Java-index,Developer Tools,Java Compiler...
# 2

hello..thanks for replying.... I am now using this code...

import javax.swing.JOptionPane;

public class Circle

{

public static void main(String args[])

{

String getRadius;

double radius, circ, diam, area;

getRadius = JOptionPane.showInputDialog("Enter the Radius");

radius = Double.parseDouble(getRadius);

diam = 2 * radius;

circ = 2 * Math.PI * radius;

area = Math.PI * ( 2 * radius);

JOptionPane.showMessageDialog (null, "The diameter is: " + diam +

"\nThe circumference is: " + circ +

"\nThe area is: " + area, "Results",

JOptionPane.PLAIN_MESSAGE );

System.exit(0);

}

}

and it works great to get the message bosex up.. But for some reason the area and teh circumference are the same amount.. i am using the formulas my professor gave me also.

thanks A LOT for any help you can give!!

Angell3 at 2007-7-1 16:44:52 > top of Java-index,Developer Tools,Java Compiler...
# 3

Yes, these two lines calculate the same result.

circ = 2 * Math.PI * radius;

area = Math.PI * ( 2 * radius);

area should be:

circ = 2 * Math.PI * radius;

area = Math.PI * radius * radius;

What happens if the user enters "5.6abc" in the input dialog? Your code would be better if you enclosed the dialog and Double.parseDouble() with a try/catch block to test for input errors.

atmguy at 2007-7-1 16:44:52 > top of Java-index,Developer Tools,Java Compiler...