I've been working on this code for two days now and I still can't figure out what is going wrong. I'm very new to programming and we just started learning about creating objects and constructors so I appreciate any help I can get. I have to turn in a set of assignments in 3 hours so if you could help me out you'd really be a life saver.
The part that is in BOLD is what I am having trouble with. I believe I'm supposed to call an argument but every time I do it says that I cannot call a static reference to a non-static field. So when I change all of my variables to static and then try to run the program my output is 0 for all of the methods that I try to call.
The purpose of my program is to "demonstrate the Circle class by asking the user for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference."
import java.util.Scanner; //Needed for the Scanner class
public class Circle
{
double radius; //User's input radius
final double PI = 3.14159; //Initialized value of PI
//Constructor Method
public Circle(double radius)
{
this.radius = radius;
}
//The setRadius method accepts an argument that is stored in the radius field
public void setRadius(double radius)
{
this.radius = radius;
}
//The getRadius method returns the value that is stored in the radius field
public double getRadius()
{
return radius;
}
//The getArea method returns the value that is stored in the area field
double area = (PI * radius * radius); //Formula to get the area of the circle
public double getArea()
{
return area;
}
//The getDiameter method returns the value that is stored in the diameter field
double diameter = (radius * 2); //Formula to get the diameter of the circle
public double getDiameter()
{
return diameter;
}
//The getCircumference method returns the value that is stored in the circumference field
double circumference = (2 * PI * radius); //Formula to get the circumference of the circle
public double getCircumference()
{
return circumference;
}
public static void main(String[] args) {
//Create a Scanner class for user input
Scanner keyboard = new Scanner(System.in);
[B]Circle myCircle = new Circle();[/B]
System.out.println("Please enter the circle's radius.");
double radius = keyboard.nextDouble();
myCircle.getArea(); //Calls for the circles area
System.out.println("The circle's area is:" + " " + myCircle.getArea()); //Displays the circles area
myCircle.getDiameter(); //Calls for the circles diameter
System.out.println("The circle's diameter is:" + " " + myCircle.getDiameter()); //Displays the circles diameter
myCircle.getCircumference(); //Calls for the circles circumference
System.out.println("The circle's area is:" + " " + myCircle.getCircumference()); //Displays the circles circumference
}
}