I will be up front with you guys this WAS a homework problem but was do last week. I will not recieve anymore cedit for this.I just wantto have a better understanding of what is going on.
The code below is supposed to take in a value form the user and use that value to determin the circumference and are of a circle.the code will compile but the results for the area and circumference is always zero. I think it has somthing to do with the value that is read in from the user never gets carrie dover to the other class where the math is performed.I also wonder if I am calling the methods right.any help will be greatly appreciated.Also any tips on how I should format my questions in the futhur please let me know
package Devry3;
public class circle
{
public static double radius;
public static double circumference;
public static double Area;
public circle()
{
radius = 0;
circumference = 0;
Area = 0;
}
public double CalculateCircumference(double circumference)
{
circumference = radius * 2 * Math.PI;
return circumference;
}
public static double CalculateArea(double Area)
{
Area = Math.pow(radius,2) * Math.PI;
return Area;
}
}
the second class is below
import javax.swing.JOptionPane;
import Devry3.circle;
public class CircleTestClass {
static String str1;
static double r;
static double Area;
static double circumference;
public static void main(String[] args) {
circle methods = new circle();
str1 = JOptionPane.showInputDialog("please enter the radius: ");
double r = Double.parseDouble(str1);
//methods.CalculateCircumference(r);
//methods.CalculateArea(r);
JOptionPane.showMessageDialog(null,"the circumference is: " + methods.CalculateCircumference(circumference));
JOptionPane.showMessageDialog(null,"the Are is: " + methods.CalculateArea(Area));
}
}

New Topic/Question
Reply




MultiQuote





|