943,964 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 5185
  • Java RSS
May 1st, 2007
0

toString format help

Expand Post »
Dear god. this is driving me crazy. I'm working on an assignment involving inheritence, multiple classes, etc. I'm stuck at one stupid part. I have to write a toString method that formats the text. Is there a way to return a string with formatted text? I know about the printf method, and I can get that to work fine, but just with System.out.printf... I don't know how to return a formatted string.. Is it even possible?

What i need is I have someones name, first and last, then their age, but the ages of the people have to line up in a column. Make sense? The names & ages are one object, & the multiple people are in array of people objects... so i have a for loop that will go through and print each person one at a time. So how do i pad the age correctly & return it to the calling method?

I would just say forget returning the string and just simply print it out, but I need the same method elsewhere to write to a file also.

so, what i need to end up with is something that looks like this

[html]
Name Age other stuff more stuff
-------------------------------------------------------------------------------
Bob Someguy 42 blabado 3.14
Guy Two 38 dododod 1234
[/html]
nice neat columns n' stuff...
I appreciate any thoughts...
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
bondo is offline Offline
43 posts
since Apr 2007
May 1st, 2007
0

Re: toString format help

BLAH! Ok, i should've done a search first. I found my answer.

For anyone else who need's help on this same thing, here's the thread I found:

http://www.daniweb.com/techtalkforum...ad.php?t=56466
Reputation Points: 11
Solved Threads: 0
Light Poster
bondo is offline Offline
43 posts
since Apr 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help me please..
Next Thread in Java Forum Timeline: help again with textfields





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC