• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with circle program  RSS feed

 
chavez james
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Let first say thank you for your help and reviewing my post. I am getting an error with my code. Ill paste in my code and then paste in my error. can someone tell me how to fix it.



This is my error:

Circle.java:78: error: method getRadius in class Circle cannot be applied to given types;
System.out.println("A circle with a radius of " + circle.getRadius() + " will have an area of " + circle.getArea() + " , a diameter of " + circle.getDiameter() + " and a circumference of " + circle.getCircumference());
^
required: double
found: no arguments
reason: actual and formal argument lists differ in length
1 error
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chavez james wrote:
This is my error:

Circle.java:78: error: method getRadius in class Circle cannot be applied to given types;
System.out.println("A circle with a radius of " + circle.getRadius() + " will have an area of " + circle.getArea() + " , a diameter of " + circle.getDiameter() + " and a circumference of " + circle.getCircumference());
^
required: double
found: no arguments
reason: actual and formal argument lists differ in length
1 error


You are invoking

whereas your method is


Now do you see what's going wrong?

On a related note, ask yourself this question,
Why am I doing with the double r variable
 
chavez james
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i believe that double r is = to radius so it needs to get the radius entered is that correct?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chavez james wrote:Well i believe that double r is = to radius so it needs to get the radius entered is that correct?

Well you are not assigning it. There is no statement like in your method getRadius().
Effectively your method is like you insert a key in the lock to open it and you find the lock is unlocked. So your key was really not required.

As a convention, the getter/accessor methods should return the current value.
The setter/mutator methods should set the value.

Your method getRadius is a mixture of both which does not make sense.
 
chavez james
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just deleted the double r in the () and it compiled correctly.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chavez james wrote:I just deleted the double r in the () and it compiled correctly.
That is what I would have recommended.

By the way: please format and indent your code. You have too many blank lines. You don't need a blank between the { and the body of a method nor after the method body and before }. You also had a horribly long line (No 78) which made the rest of the thread difficult to read. I broke it and you can see how to deal with long lines now.
you should not be printing all that information in the main method. You should provide the circle class with a toString method which returns all that info and then you can simply call
System.out.println(myCircle);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!