/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Add a method to Building.
using System;
class Building {
publicint floors; // number of floors
publicint area; // total square footage of building
publicint occupants; // number of occupants
// Display the area per person.
publicvoid areaPerPerson() {
Console.WriteLine(" " + area / occupants +
" area per person");
}
}
// Use the areaPerPerson() method.
publicclass BuildingDemo2 {
publicstaticvoid Main() {
Building house = new Building();
Building office = new Building();
// assign values to fields in house
house.occupants = 4;
house.area = 2500;
house.floors = 2;
// assign values to fields in office
office.occupants = 25;
office.area = 4200;
office.floors = 3;
Console.WriteLine("house has:\n " +
house.floors + " floors\n " +
house.occupants + " occupants\n " +
house.area + " total area");
house.areaPerPerson();
Console.WriteLine();
Console.WriteLine("office has:\n " +
office.floors + " floors\n " +
office.occupants + " occupants\n " +
office.area + " total area");
office.areaPerPerson();
}
}