This program creates two Building objects
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// This program creates two Building objects.
using System;
class Building {
public int floors; // number of floors
public int area; // total square footage of building
public int occupants; // number of occupants
}
// This class declares two objects of type Building.
public class BuildingDemo1 {
public static void Main() {
Building house = new Building();
Building office = new Building();
int areaPP; // area per person
// 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;
// compute the area per person in house
areaPP = house.area / house.occupants;
Console.WriteLine("house has:\n " +
house.floors + " floors\n " +
house.occupants + " occupants\n " +
house.area + " total area\n " +
areaPP + " area per person");
Console.WriteLine();
// compute the area per person in office
areaPP = office.area / office.occupants;
Console.WriteLine("office has:\n " +
office.floors + " floors\n " +
office.occupants + " occupants\n " +
office.area + " total area\n " +
areaPP + " area per person");
}
}
Related examples in the same category