In general, it is good practice to keep the methods short and have a specific purpose, otherwise they may be misused. (Your method determines if the place should be printed and format the output).
The method should return what it was intended for: if you want to ask if it should be printed, a more suitable way would be:
public bool ShouldPrintLocation(MarsLander ml, int i) { return (i == ((ml.GetHeight() % 100) + 9); }
PrintLocation() then actually prints the location, if necessary:
public void PrintLocation(MarsLander ml) { for (int i = 10; i >= 0 ; i--) { string locationText = ShouldPrintLocation(ml, i) ? "*" : string.Empty; Console.WriteLine("{0} m: {1}", i * 100, locationText); } Console.WriteLine(); }
It makes sense for me to have output formatting in PrintLocation , since this method is designed to ... Print location, as opposed to doing some logic / calculation
source share