• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling methods which contain system.out.println code

 
David Dickinson
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a method which prints the Type and Value fields from selection of Car objects.



Then I need to total the value of multiple forcourts by calling getForecourtYValue(), getForecourtZValue().
(Don't worry my code is much cleaner than this im trying to provide an example which is unrealted to my code).

And then I will print the combined value of these forecourts. In my summing method I just call each function which adds up each individual forecourt and thus minimises code duplication, but it does print each forecourts listings twice (i'm using Test Driven Design).

How can I avoid a function which is called printing its output?

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd change the code. if the method is called getForecourtXValue(), it should only give you the value, not get AND print the value.

Can you create a new method called printForecourtXValue, and then use the two methods when/where you need to?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic