Results 1 to 2 of 2
- 08-08-2012, 01:37 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 7
- Rep Power
- 0
How to display toString() inside another toString()
Ok here is the dilemma (this is the same project as before but different problem)
I have finished my program but found the output is not what I would like it to be. I have the following lines that display two different toString() methods:
But the thing is I actually need to call the "benefit1" from within the Employee1.toString();Java Code:System.out.printf("%s", employee1.toString()); System.out.printf("%s", benefit1.toString());
So how do I do this? My employee's toString method is as follows:
I need the benefit's toString() output to show up between 'Weekly Pay' and 'Category'Java Code:public String toString() { NumberFormat nf = NumberFormat.getCurrencyInstance(); return String.format("\nFirst Name: %s\nLast Name: %s\nGender; %s\nDependents: %s\nAnnual Salary: %s\nWeekly Pay: %s\nCategory: %s\n", getFirstName(), getLastName(), getGender(), getDependents(), nf.format(getAnnualSalary()), nf.format(calculatePay()), category); }
(Weekly Pay and Category are listed in the codebox above, I need it between those two elements)Last edited by SVTermiCobra; 08-08-2012 at 01:39 AM.
- 08-08-2012, 01:49 AM #2
Member
- Join Date
- Aug 2012
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
how to display from toString through subclass
By SVTermiCobra in forum New To JavaReplies: 3Last Post: 08-07-2012, 10:49 PM -
help with toString
By teardrop3903 in forum New To JavaReplies: 5Last Post: 04-28-2011, 02:39 AM -
toString
By justin23 in forum New To JavaReplies: 13Last Post: 05-02-2010, 02:44 PM -
toString
By luckyleaf95 in forum New To JavaReplies: 9Last Post: 02-11-2010, 08:52 AM -
Can i just use toString?
By cachi in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks