I am working on a program that will compute the circumference and area of the circle with just asking for the diameter here is the first part:
public class Circle
{
private double diameter;
public Circle (double dia)
{diameter = 1;}
public void setDiameter(double dia)
{diameter = dia;}
public double getDiameter()
{return diameter;}
public double calcPerimeter()
{return 3.14 * diameter; }
public double calcArea()
{return 3.14 * (diameter / 2 * diameter / 2);}
}
this is the test that comes with the program:
import java.util.Scanner;
import java.text.DecimalFormat;
public class CircleTest
{
public static void main(String[] args)
{
double diameter;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the diameter of the circle:");
diameter = keyboard.nextDouble();
Circle circle1= new Circle(diameter);
System.out.println("The circle's diameter is: " + Circle.getDiameter());
System.out.println("The first circle's perimeter is: " +
Circle.calcPerimeter());
System.out.println("The circle's area is: " + Circle.calcArea());
}
}
It throws me error like :
Any help is appreciated thanks!