using System;
using System.Collections;
namespace 静态问题实验课本上的例子
{
class Account
{
public static uint totalAccountsCreated = 0;
public Account()
{
totalAccountsCreated++;
}
}
class Bank
{
private ArrayList accounts;
public Bank()
{
Console.WriteLine("Congratulations! you have created a new bank");
accounts = new ArrayList();
}
public void AddNewAccount()
{
accounts.Add(new Account());//将新创建的对象加入数组
Console.WriteLine("new account added!");
PrintStatistics();
}
public void RemoveFirstAccount()
{
if(accounts.Count > 0)
{
accounts.RemoveAt(0);
Console.WriteLine("Account removed!/n");
PrintStatistics();
}
else
{
Console.WriteLine("Sorry no more current accounts ");
}
}
public void PrintStatistics()
{
Console.WriteLine("Number of current accounts :" + accounts.Count + "/nNumber of new accounts creats: " + Account.totalAccountsCreated);
}
}
class DynamicBankSimulation
{
private static Bank bigBucksBank;
static void Main(string[] args)
{
string command;
bigBucksBank = new Bank();
do
{
PrintMenu();
command = Console.ReadLine().ToUpper();//把输入的字符变为大写
switch(command)
{
case "A":
bigBucksBank.AddNewAccount();
break;
case "E":
Console.WriteLine("Bye Bye !");
break;
case "R":
bigBucksBank.RemoveFirstAccount();
break;
case "P":
bigBucksBank.PrintStatistics();
break;
default:
Console.WriteLine("Invalid choice ");
break;
}
}while( command != "E");
}
private static void PrintMenu()
{
Console.WriteLine("/n What would you like to do ?/n"
+ "A) Add new account/n" +
"R) Remove account /n" +
"P) Print Statistics/n" +
"E) End session /n");
}
}
}