书上的例子

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");
  }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值