Maha

Maha

  • NA
  • 0
  • 320k

Method

Dec 3 2011 11:19 AM
Instead of having WriteLine() method three times I wish to know whether is there any way to deploy display() method as shown in the following and develop the program appropriately.

// Creates a Boat class
// And instantiates three Boat objects

using System;

public class DebugFour1
{
public static void Main()
{
Boat aRowBoat = new Boat();
Boat aSkiBoat = new Boat();
Boat aYacht = new Boat();

aRowBoat.SetLicense("W2453");
aRowBoat.SetState("WI");

aSkiBoat.SetLicense("M6120");
aSkiBoat.SetState("MI");

aYacht.SetLicense("M5322");
aYacht.SetState("MA");

display(aRowBoat);
display(aSkiBoat);
display(aYacht);
}
static void display(object aBoat)
{
Console.WriteLine("Boat {0} from {1} has a {2} HP motor.", aBoat.GetLicense(), aBoat.GetState(), aBoat.GetMotor());
}
}
class Boat
{
private string licenseNum;
private string state;

public string GetLicense()
{
return licenseNum;
}
public string GetState()
{
return state;
}

public void SetLicense(string licNum)
{
licenseNum = licNum;
}
public void SetState(string st)
{
state = st;
}
}

Answers (6)