r/javahelp • • Mar 05 '23

Solved Implementing a method within a toString method

I'm writing a class in which I have a class representing a circle. With the radius, two public methods were created to calculate the area and perimeter respectively. How might I call these methods in the toString method of the class? I have attached some of the class for visual representation.

Note: There is no good reason for you to down vote my posts.

0 Upvotes

10 comments sorted by

View all comments

4

u/desrtfx Out of Coffee error - System halted Mar 05 '23

Since you haven't in the faintest mentioned what your actual toString method should output, we cannot directly help.

Also, neither the area, nor the perimeter method should be static and even less take an argument. The radius is already part of the Circle object and this is the radius that should be used for the calculations.

What I would imagine is that you will want some string concatenation to integrate the calculated perimeter and area in the output.

1

u/Charlemagne-767 Mar 05 '23

Yes, that is my goal. To include the results of the calculation of the area and perimeter within the toString. I will take what you said to heart and see what I can do