using System;
class building{
        public int a;
        public int b;
        public int c;
    public void e()
    {
        Console.WriteLine("" + b / c + " area per person");
    }
}
//声明个building对象class builaingDemo {
    public static void Main()
    {
        building house = new building();  //定义名为 house 的 building 对象变量
        building office = new building();  //定义office 的 building 对象变量
    int d;    house.c = 4;   //定义building house c 等于4
    house.b = 2500;  //定义building house b 等于2500
    house.a = 2;  //定义building house a 等于2    office.c = 25;  //定义building office c 等于25
    office.b = 4200;  //定义building office b 等于2005
    office.a = 3;  //定义building office a 等于3    d = house.b / house.c;  // d 等于2500除4 等于 625    Console.WriteLine("house has:\n " +
    house.a + " floors\n " +
    house.c + " occupants\n " +
    house.b + " total area");
    house.e();
    Console.WriteLine();    d = office.b / office.c;    Console.WriteLine("house has:\n " +
    office.a + " floors\n " +
    office.c + " occupants\n " +
    office.b + " total area");
    office.e();
    }
}哈哈 一样

解决方案 »

  1.   

    using System;
    class building{
            public int a;
            public int b;
            public int c;
        public int e()
        {
            return b / c;
        }
    }
    //声明个building对象class builaingDemo {
        public static void Main()
        {
            building house = new building();  //定义名为 house 的 building 对象变量
            building office = new building();  //定义office 的 building 对象变量
            int d;
        house.c = 4;   //定义building house c 等于4
        house.b = 2500;  //定义building house b 等于2500
        house.a = 2;  //定义building house a 等于2    office.c = 25;  //定义building office c 等于25
        office.b = 4200;  //定义building office b 等于2005
        office.a = 3;  //定义building office a 等于3    d = house.e();  // d 等于2500除4 等于 625    Console.WriteLine("house has:\n " +
        house.a + " floors\n " +
        house.c + " occupants\n " +
        house.b + " total area" +
        d + " area per person");
        Console.WriteLine();    d = office.e();    Console.WriteLine("house has:\n " +
        office.a + " floors\n " +
        office.c + " occupants\n " +
        office.b + " total area" +
        d + " area per person");
        }
    }
      

  2.   

    如果没J基础可以学好.NET麽。能推荐点方法麽
      

  3.   

    变量名要有意义
    字段要私有,属性可以公开客户端的代码不需要对类进行解释
    在类的内部解释
    class building{
            public int a;//.....
            public int b;//.....
            public int c;//.....
        public int e()//........
        {
            return b / c;
        }
    }