-1

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 :

enter image description here

Any help is appreciated thanks!

qwerty_so
  • 35,448
  • 8
  • 62
  • 86

1 Answers1

0
    Circle circle1= new Circle(diameter);
    System.out.println("The circle's diameter is: " + circle1.getDiameter());
    System.out.println("The first circle's perimeter is: " + 
    Circle.calcPerimeter());
    System.out.println("The circle's area is: " + circle1.calcArea());

Use the variable instead of the class. You would have accessed getDiameter if it was a static method.

Ran
  • 333
  • 1
  • 4
  • 16