So as an assignment for a class i'm trying to make a simple circle class and then use it as an constructor. Here is my class code:
public class Circle
{
private double radius;
private double pi;
public void setRadius(double rad)
{
radius = rad;
}
public double getRadius()
{
return radius;
}
public double getArea()
{
return pi * radius * radius;
}
public double getDiameter()
{
return radius * 2;
}
public double getCircumference()
{
return 2 * pi * radius;
}
}
Here's the program that uses the class to make a constructor:
import java.util.Scanner; //scanner class for input
public class CircleDemo
{
public static void main(String[]args)
{
double radiusIn; //gets radius from input
Scanner keyboard=new Scanner(System.in); //activates scanner class in program
System.out.print("Enter the radius of a circle: ");
radiusIn=keyboard.nextDouble();
Circle circularObject= new Circle(radiusIn);
System.out.println("The circle's area is" + circularObject.getArea());
System.out.println("The circle's diameter is" + circularObject.getDiameter());
System.out.println("The circle's circumference is" + circularObject.getCircumference());
}
}
and i get the error: Error: constructor Circle in class Circle cannot be applied to given types; required: no arguments found: double reason: actual and formal argument lists differ in length
I don't see anything wrong with my code, but then again i'm using the sample that my teacher gave us.
Math.PIinstead of a private fieldpi, which hasn't even been set to the value of PI.pia value to use mathematically. What do you think the output will be? Furthermore, does the value ofpiever change?