//A simlpe elevator simulation
using System;
class Elevator
{
private int currentFloor = 1;
private int requestedFloor = 0;
private int totalFloorsTraveled = 0;
private Person passenger;
public void LoadPasseager
{
Passenger = new Person();
}
public void InitiateNewFloorRequest()
{
requestedFloor = passenger.NewFloorRequest();
Console.WriteLine("Departing floor:" + currentFloor + "Traveling to floor:" + requestedFloor);
totalFloorsTraveled = totalFloorsTraveled + Math.Abs(currentFloor + requestedFloor);
currentFloor = requestedFloor;
}
public void ReportStatistic()
{
Console.WriteLine("Total floors traveled:" + totalFloorsTraveled);
}
}
class Person
{
private System.Random randomNumbergenerator;
public Person()
{
randomNumbergenerator = new System.Random();
}
public int NewFloorRequst()
{
//Return randonly generated number
return randomNumbergenerator.Next(1,30);
}
}
class Building
{
private static Elevator elevatorA;
public static void Main()
{
elevatorA = new Elevator();
elevatorA.LoadPasseager();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.ReportStatistic();
}
}
红色部分的 Personger = new Person();出现错误 错误为:应为get 或 set访问器.
如何解决这个错误
我是刚刚学C#~~以后还要大家多多指教.
[此贴子已经被作者于2007-4-27 23:56:31编辑过]