哪位高人帮我解答这个题目
// A simple elevator simulationusing System;
class Elevator
{
private int currentFloor = 1;
private int requestedFloor = 0;
private int totalFloorsTraveled = 0;
private Person passenger;
public void LoadPassenger()
{
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 NewFloorRequest()
{
// Return randomly generated number
return randomNumberGenerator.Next(1,30);
}
}
class Building
{
private static Elevator elevatorA;
public static void Main()
{
elevatorA = new Elevator();
elevatorA.LoadPassenger();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.ReportStatistic();
Console.Read();
}
}
想在这个程序下做如下修改:给Elevator类添加一个表示电梯名的实例变量,可以将他命名为myName,此实例变量是用private还是public?编写一个构造函数,当你用new关键字创建一个Elevator对象并赋予一个变量时,通过构造函数来为此变量设置值,当使用new关键字时,调整对构造函数的调用方法,将Elevator的名字作为一个参数(花括号之间,而不是在new Elevator()之间插入),写成new Elevator("ElevatorA")
Elevator每完成一次运输它必须打印出发和到达楼层名 不是打印:Departing floor: 2 Traveling to floor 24
应该打印:ElevatorA:Departing floor: 2 Traveling to floor 24 其中ElevatorA是myName中Elevator的名字