Win a copy of Rust Web Development this week in the Other Languages forum!

N Doidge

+ Follow
since Jan 24, 2011
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by N Doidge

Well, first of all it's "toString", not "tostring". But I don't see the problem. You already have some methods declared in the Location class. Now you want to declare another one. So just put the new method right after the existing ones. Why is there a question about that?

Sorry about that Paul, adding more confusion lol of using "tostring" on here.

Just was unsure on how to approach that task, really a newbie on java, so kid gloves with myself.

Also would I need to change the location class, double x, double y to int? and use

10 years ago

fred rosenberger wrote:You need to override the "toString" method in your Location class.

It's impossible for the JVM to know what you really want to print for a user-defined class. But since every class is a child of the Object class, they all inherit its implementation of that method, which basically prints the memory address (that hex code you see).

Create a toString method, and define what you want it to really print, and it should work.

ahhhh right, now its falling into place lol.
Now only problem is how and where do I place the tostring method within location class?
I have been trying for about a hour now and seem to failing into a pile of information on tostrings methods without any success

10 years ago
cheers paul! your a star! I think that I can see/what you mean regarding the wrapped in braces now

It now seems that its populating the array correctly now
for example two inputs for Circle:
area of the circle 0 is 9156.24
area of the circle 1 is 9847.04

two inputs for square:

area of the Square 0 is 1849.0
area of the Square 1 is 4356.0

one circle and one square:

area of the circle 0 is 6358.5
area of the Square 1 is 4225.0

right so only 2 more shapes to add here and then work how to get location to appear correctly (getting some strange output here 26c623af) with also the polygon workout done lol
10 years ago
Hi everyone, just need a bit of help here as ive been staring at this code for 4 days and not making much headway.
Also its apperantly a classic *drumrolls* area of shapes! with x,y location

Basicly in a nutshell its going to be an array of 20 (at the moment set at 2) of class shapes with subclass exented ( circle, square, retcangle and polygon)
with X,Y location. Also stuck on polygons

At the moment i think that i have made a uttermistake and now damaged the code. As now circle seems to provide two output after one input!
area of the circle 0 is 6358.5
area of the Square 0 is 6358.5
any help would be highly appreciated

10 years ago