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;
}
}
Loading

VulpesRank #55 · 29.2K reputationPosted Jul 21, 2012, 3:13 PM EDT
Posted Jul 21, 2012, 3:30 PM EDT
Posted Aug 28, 2012, 9:24 AM EDT
Name State Population
------- ------ -----------
Scarborough Ontario 100000
Victoria British_Columbia 700000
Kingston Ontario 120000
Vancouver British_Columbia 600000
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2012, 10:44 AM EDT
Posted Aug 28, 2012, 11:28 AM EDT
Is it possible to explain the relation between left alignment and minus sing.
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2012, 12:13 PM EDT
{0, 15} means that it should be right justified within a 15 character field.
Posted Aug 28, 2012, 12:44 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2012, 2:40 PM EDT
When you use {0, -15} the field will be filled with spaces until it's 15 characters wide and then the rest of the string will start from the next character after that.
With {0} the rest of the string will start from the next character after whatever's in the {0} is printed.
Posted Aug 28, 2012, 3:41 PM EDT