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
Posted Aug 28, 2012, 7:41 PM
VulpesPosted Aug 28, 2012, 6:40 PM
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, 4:44 PM
VulpesPosted Aug 28, 2012, 4:13 PM
{0, 15} means that it should be right justified within a 15 character field.
Posted Aug 28, 2012, 3:28 PM
Is it possible to explain the relation between left alignment and minus sing.
VulpesPosted Aug 28, 2012, 2:44 PM
Posted Aug 28, 2012, 1:24 PM
Name State Population
------- ------ -----------
Scarborough Ontario 100000
Victoria British_Columbia 700000
Kingston Ontario 120000
Vancouver British_Columbia 600000
Posted Jul 21, 2012, 7:30 PM
VulpesPosted Jul 21, 2012, 7:13 PM