This is the error message I am getting and the driver and class is below it.
Thank You if you can help me :)

C:\My Documents\CS151\CircleSolutionDriver.java:18: cannot resolve symbol
symbol  : constructor Circle ()
location: class Circle
   Circle circle = new Circle();
                   ^
1 error

Tool completed with exit code 1

This is the driver:

* This program calculates the circumference of a circle or the area of a circle
* depending on which one the user needs at the time.  This program will also
* give the user the option of the concepts and the formula that will be used in
* the solution.
***********************************************************************************************/

public class CircleSolutionDriver
{
   public static void main(String[] args)
   {

 //Create an object, enter data, process, and display information

   Circle circle = new Circle();


   circle.CircleInfo();
   circle.calculate();



   }//end main
 } //end CircleSolutionDriver

This is the class:

* This program calculates the circumference of a circle or the area of a circle
* depending on which one the user needs at the time.  This program will also
* give the user the option of the concepts and the formula that will be used in
* the solution.
***********************************************************************************************/

import java.text.DecimalFormat;

public class Circle
{
  public double perimeter;
  public double area;
  public double radius;
  public char response;

//********************************************************************************************

//This constructor assigns the values into instance variables

public Circle(double radius)
{
  this.radius = radius;
}// end CircleSolution constructor
//*********************************************************************************************
//This constructor method inputs

public void CircleInfo()
{
  System.out.print("Please enter the radius of the circle: ");
  radius = Input.readDouble();
  System.out.print("Please enter which formula you would like calculated.");
  System.out.print("P for Perimeter or A for area:");
  response = Input.readChar();
}//end constructor
//***********************************************************************************************
//This method calculates the perimeter and the area and prints the results

public void calculate()
{

    if((response == 'P') || (response == 'p'))
    {
       System.out.print("Would you like to see the formula that will be used to calculate the perimeter?");

       if ((response == 'Y') || (response == 'y'))
       {
         System.out.print("The perimeter is calculated by PI= 3.14159 * radius * 2.0.");
         System.out.print("The perimeter is the sum of the lengths of sides of the circle.");
       }
       else if ((response == 'N') || (response == 'n'))
       {
         perimeter = (Math.PI) * radius * 2.0;
         DecimalFormat fixedFormat = new DecimalFormat ("##0.000##");
         System.out.print("The perimeter of your circle is: " + fixedFormat.format(perimeter));
       }
    }
    if((response == 'A') || (response == 'a'))
    {
      System.out.print("Would you like to see the formula that will be used to calculate the area?");
       if((response == 'Y') || (response == 'y'))
       {
         System.out.print("The area is calculated by area = PI = 3.14159 * radius * radius.");
         System.out.print("The area ia the term for the measurment of the amount of surface ocupied by the circle.");
       }
       else if((response == 'N') || (response == 'n'))
       {
         area = (Math.PI) * radius * radius;
         System.out.print("The area of your circle is: " + area);
       }
    }
 }

//************************************************************************************************
//This method returns the radius

public double getRadius()
{
  return radius;
}//end getRadius

//************************************************************************************************
//This method changes the radius

public void setRadius(double nRadius)
{
  radius = nRadius;
}//end setRadius

//***********************************************************************************************


}// end class Circle

Dani AI

Generated

The compiler error occurs because the driver calls new Circle() but the Circle class only defines a constructor that takes a double. The Java compiler only provides a no-argument constructor automatically when you do not declare any constructors. Since a parameterized constructor exists, there is no implicit zero-arg constructor to satisfy new Circle() (as pointed out).

Two practical fixes:

  • Add an explicit no-argument constructor to Circle (you can leave it simple or call your existing input method from it):
public Circle() {
  // set defaults or reuse the input routine
  this.radius = 0.0;
  // or: CircleInfo();
}
  • Or change the driver so it constructs Circle with a radius value that you obtain first:
double r = /* read radius from user */;
Circle circle = new Circle(r);

A common source of confusion here: the method public void CircleInfo() in the class is not a constructor because it has a return type (void). A true constructor has no return type and must be declared as public Circle() { ... }. If the intent was to prompt for input at construction time, either rename/remove the void and make it a proper no-arg constructor, or explicitly call CircleInfo() from a new no-arg constructor as shown above.

Other quick tips: recompile both source files after changes; ensure file names match the public class names; consider making fields private and validating user input; and avoid heavy I/O inside constructors if you want objects that are easier to test. This will fix the "cannot resolve symbol: constructor Circle()" issue and make the design clearer.

First glance is you defined a constructor with a parameter. If you define a constructor with a parameter, you also need to define the default constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.