[java] Java error - "invalid method declaration; return type required"

We are learning how to use multiple classes in Java now, and there is a project asking about creating a class Circle which will contain a radius and a diameter, then reference it from a main class to find the diameter. This code continues to receive an error (mentioned in the title)

public class Circle
{
    public CircleR(double r)
    {
        radius = r;
    }
    public diameter()
    {
        double d = radius * 2;
        return d;
    }
}

Thanks for any help, -AJ

Update 1: Okay, but I shouldn't have to declare the third line public CircleR(double r) as a double, right? In the book I am learning from, the example doesn't do that.

public class Circle 

    { 
        //This part is called the constructor and lets us specify the radius of a  
      //particular circle. 
      public Circle(double r) 
      { 
       radius = r; 
      } 

      //This is a method. It performs some action (in this case it calculates the 
        //area of the circle and returns it. 
        public double area( )  //area method 
      { 
          double a = Math.PI * radius * radius; 
       return a; 
    } 

    public double circumference( )  //circumference method 
    { 
      double c = 2 * Math.PI * radius; 
     return c; 
    } 

        public double radius;  //This is a State Variable…also called Instance 
         //Field and Data Member. It is available to code 
    // in ALL the methods in this class. 
     } 

As you can see, the code public Circle(double r).... how is that different from what I did in mine with public CircleR(double r)? For whatever reason, no error is given in the code from the book, however mine says there is an error there.

This question is related to java

The answer is


You forgot to declare double as a return type

public double diameter()
{
    double d = radius * 2;
    return d;
}

Every method (other than a constructor) must have a return type.

public double diameter(){...

I had a similar issue when adding a class to the main method. Turns out it wasn't an issue, it was me not checking my spelling. So, as a noob, I learned that mis-spelling can and will mess things up. These posts helped me "see" my mistake and all is good now.