Maha

Maha

  • NA
  • 0
  • 326.2k

set method is not necessary if constructor parameters are given

Jul 21 2012 3:39 PM
Following one is an incomplete program of number 7 in Chapter4. The program is asking to include a constructor then talking about set method. It is confusing because in my view set method is not necessary if constructor parameters are given. Please complete this program.

using System;

namespace _4e7
{
class MovingHistory
{
static void Main(string[] args)
{
City myCity = new City("Scarborough","Ontario", 100000);
City myFriendCity = new City("British_Columbia", "Victoria", 700000);


}
}
}
class City
{
string cityName;
string cityState;
int population;

public City(string cityName, string cityState, int population)
{
this.cityName = cityName;
this.cityState = cityState;
this.population = population;
}
public string getCityName()
{
return cityName;
}
public string getCityState()
{
return cityState;
}
public int getPopulation()
{
return population;
}

}

Attachment: chapter4 5_8.zip

Answers (9)