I'm not sure where I'm going wrong in this program. I needed to create two different classes, one being the driver class the other the utility class. The purpose is to ask the user for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference. Please help, here is what I have so far.
public class Circle
{
private double Radius;
final double PI = 3.14159;
double number;
public double Circle(double Rad)
{
Radius = number;
return Radius;
}
/**
The getArea method returns the area of the
circle
*/
public double getArea()
{
return PI*Radius*Radius;
}
/**
The getDiameter method returns the diameter
of the circle
*/
public double getDiameter()
{
return Radius*2;
}
/**
The getCircumference method returns the
circumference of the circle
*/
public double getCircumference()
{
return 2*PI*Radius;
}
}
That is one here is the other
public class CircleDemo
{
public static void main(String[] args)
{
String input; //Hold users input
double Radius; //hold the radius
double Area;
double Circumference;
double Diameter;
double number;
//Create the radius object
Circle radius = new Circle();
//Get the radius of the circle
input = JOptionPane.showInputDialog("What is the Radius " +
"of the circle?");
number = Double.parseDouble(input);
Circle.setRadius(number);
//Calculate the Area of the circle
Area = Radius.getArea();
//Display the area of the circle
JOptionPane.showMessageDialog(null, "The area of the circle " +
"is " + Area);
//Calculate the Diameter of the circle
Diameter = Radius.getDiameter();
//Display the diameter of the circle
JOptionPane.showMessageDialog(null, "The diameter of the circle " +
"is " + Diameter);
//Calculate the Circumference of the circle
Circumference = Radius.getCircumference();
//Display the circumference of the circle
JOptionPane.showMessageDialog(null, "The circumference of the circle " +
"is " + Circumference);
System.exit(0);
}
}