Prompt: Write a class encapsulating the concept of a circle, assuming a circle has the following attributes: a Point representing the center of the circle, and the radius of the circle, and integer. Include a constructor, the accessors and mutators, and methods toString and equals. Also include methods returning the perimeter ( 2 × 𝜋 × 𝑟 ) and area ( 𝜋 × 𝑟^2) of the circle. Write a client (application) class to test all the methods in your class.

I started out trying to thing how to do this and I mapped out a certain idea but do not know how to incorporate the point represent the center of the circle. I am not sure how to proceed further.. Please give me your wise guidance:

I do not know what to do. I have viewed tutorials, but that makes it even more confusing.... I hope you can assist me.
Thank you so much for coping with a noob like me.
Thanks.

March 20th, 2014, 12:09 AM

dicdic

Re: Write a class encapsulating the concept of a circle: Help Needed

Quote:

but do not know how to incorporate the point represent the center of the circle.

what do you mean by that?
do you need to know where exactly the center of circle located?
if that's the case, then, should your circle be in cartesian plane?
then your circle would have coordinates center(x, y)?

Quote:

// For some reason this code has problems.
// I tried integrating it into the top code and
// That failed, not sure why though.

"A toString method that prints out the location of the circle (the x, y coordinates of
the Point) and the radius."

I think the requirement wants you to override the toString method of Object
If you are using netbeans or eclipse, just press Ctrl + spacebar and find the toString and click enter.
that will override the toString method and you must return what you want to print out with that Circle class.
If you are not using any IDE, just create a public method named toString that has return type of String

Quote:

public class TestCircle {

public static void main(String[] args) {

final double PI = 3.14;

int x,y, radius = 4;

double area = 24;

double perimeter = 30;

area = PI * radius * radius;
perimeter = 2 * PI * radius;

// Output Results
System.out.println("The area of the circle is " + area );
System.out.println("The perimeter of the circle is " + perimeter );
}
}

I guess you have compilation error with your code?
each java file can contain only one public class. except for nested public class.
it would be better if you put your Circle class in another java file.

March 20th, 2014, 02:01 PM

Knowledge_Feeds_The_Mind

Re: Write a class encapsulating the concept of a circle: Help Needed

So I reworked the code and now I think I only have to find a way to integrate the second code into the first code

The system seems to contradict itself:
Whenever I assign "final" to center, the system states. "Local variable center is accessed from within inner class; needs to be declared final" and then when I reassign final to center it states, "Cannot assign a value to final variable center."
Thank you so much for your help and advice :D

March 21st, 2014, 02:17 AM

dicdic

Re: Write a class encapsulating the concept of a circle: Help Needed

Quote:

final point center = null;

you declared the class Point with uppercase P
java is a case sensitive programming language.
then it should be final Point center not final point center.

I finalized my code, but I cannot run it, the program says that there is no main class?
"public static void main(int radius, int x, int y) {" I thought that this was my main class....
Do you know what may be causing this?

I finalized my code, but I cannot run it, the program says that there is no main class?

sorry for late reply. I don't do anything related to programming during weekends
the reason is you don't have main method in your class.public static void main(String[] var) is a special method in java. you cannot modify its parameter (except for the variable name of String array)