几个C# PROGRAMS

 
using System;

namespace Wrox.ProCSharp.OOProg     //The first program
{
   class MainEntryPoint
   {
      static void Main()
      {
         Authenticator myAccess = new Authenticator();
         bool done;
         done = myAccess.ChangePassword("", "MyNewPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");
         done = myAccess.ChangePassword("", "AnotherPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");

         if (myAccess.IsPasswordCorrect("WhatPassword"))
            Console.WriteLine("Verified myAccess\' password");
         else
            Console.WriteLine("Failed to verify myAccess\' password");
      }

   }

   public class Authenticator
   {
      // implementation as shown earlier

      private string password = "";
  
      public bool IsPasswordCorrect(string tryPassword)
      {
         return (tryPassword == password) ? true : false;
      }

      public bool ChangePassword(string oldPassword, string newPassword)
      {
         if (oldPassword == password)
         {
            password = newPassword;
            return true;
         }
         else
            return false;
      }
   }
}

using System;

namespace Wrox.ProCSharp.OOProg    //The Second program
{
   class MainEntryPoint
   {
      static void Main()
      {
         Authenticator myAccess = new Authenticator();
         bool done;
         done = myAccess.ChangePassword("", "MyNewPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");
         done = myAccess.ChangePassword("", "AnotherPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");

         if (myAccess.IsPasswordCorrect("WhatPassword"))
            Console.WriteLine("Verified myAccess\' password");
         else
            Console.WriteLine("Failed to verify myAccess\' password");
      }

   }

   public class Authenticator
   {
      // implementation as shown earlier

      private string password = "";
  
      public bool IsPasswordCorrect(string tryPassword)
      {
         return (tryPassword == password) ? true : false;
      }

      public bool ChangePassword(string oldPassword, string newPassword)
      {
         if (oldPassword == password)
         {
            password = newPassword;
            return true;
         }
         else
            return false;
      }
   }
}

namespace Wrox.ProCSharp.OOProg
{
   using System;
   public enum TypeOfCall
   {
      CallToCellPhone, CallToLandline
   }

   public class Customer
   {
      private string name;
      private decimal balance;
      public string Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }

      public decimal Balance
      {
         get
         {
            return balance;
         }
      }
      public void RecordPayment(decimal amountPaid)
      {
         balance -= amountPaid;
      }
      public void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
               balance += (0.30M * nMinutes);
               break;
            default:
               break;
         }
      }
   }
   public class MainEntryPoint
   {
      public static void Main()
      {
         Customer arabel = new Customer();
         arabel.Name = "Arabel Jones";
         Customer mrJones = new Customer();
         mrJones.Name = "Ben Jones";
         arabel.RecordCall(TypeOfCall.CallToLandline, 20);
         arabel.RecordCall(TypeOfCall.CallToCellPhone, 5);
         mrJones.RecordCall(TypeOfCall.CallToLandline, 10);
         Console.WriteLine("{0,-20} owes ${1:F2}", arabel.Name, arabel.Balance);
         Console.WriteLine("{0,-20} owes ${1:F2}", mrJones.Name, mrJones.Balance);
      }
   }
}

namespace Wrox.ProCSharp.OOProg
{
   using System;
   public enum TypeOfCall
   {
      CallToCellPhone, CallToLandline
   }

   public class Customer
   {
      private string name;
      protected decimal balance;
      public string GetFunnyString()
      {
         return "Plain ordinary customer. Kaark!";
      }
      public string Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }

      public decimal Balance
      {
         get
         {
            return balance;
         }
      }
      public void RecordPayment(decimal amountPaid)
      {
         balance -= amountPaid;
      }
      public virtual void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
               balance += (0.30M * nMinutes);
               break;
            default:
               break;
         }
      }
   }
   public class Nevermore60Customer : Customer
   {
      private uint highCostMinutesUsed;
      public new string GetFunnyString()
      {
         return "Nevermore60. Nevermore!";
      }
      public override void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
         uint highCostMinutes, lowCostMinutes;
         uint highCostMinutesToGo =
            (highCostMinutesUsed < 60) ? 60 - highCostMinutesUsed : 0;
         if (nMinutes > highCostMinutesToGo)
         {
            highCostMinutes = highCostMinutesToGo;
            lowCostMinutes = nMinutes - highCostMinutes;
         }
         else
         {
            highCostMinutes = nMinutes;
            lowCostMinutes = 0;
         }
         highCostMinutesUsed += highCostMinutes;
         balance += (0.50M * highCostMinutes + 0.20M *
            lowCostMinutes);
         break;
            default:
               break;
         }
      }
   }
   public class MainEntryPoint
   {
      public static void Main()
      {
         Customer cust1;
         Nevermore60Customer cust2;
         cust1 = new Customer();
         Console.WriteLine("Customer referencing Customer: "
            + cust1.GetFunnyString());
         cust1 = new Nevermore60Customer();
         Console.WriteLine("Customer referencing Nevermore60Customer: "
            + cust1.GetFunnyString());
         cust2 = new Nevermore60Customer();
         Console.WriteLine("Nevermore60Customer referencing: "
            + cust2.GetFunnyString());  
      }
   }
}

时间: 2024-10-28 18:07:08

几个C# PROGRAMS的相关文章

关于oracle Scheduler的介绍——Programs

整理自君三思博客:http://blog.itpub.net/7607759/viewspace-611604/ 二.使用Programs 在论坛中偶尔见过有人讨论如何在ORACLE中执行操作系统命令,或是ORACLE数据库外的应用.应该说在9i及之前的版本中,虽然说并非完全无法实现(其实还是有多种方式能够变相实现的),不过复杂的实现方式让DBA使劲了力,伤透了心,费劲了事儿. 进入10g版本之后,就完全不必如此费神,因为有了DBMS_SCHEDULER,因为有了PROGRAM. 2.1  创建

几个C# PROGRAMS (2)

  using System;using System.Text.RegularExpressions; namespace Wrox.ProCSharp.RegularExpressionPlayaround{   class MainEntryPoint   {      static void Main()      {         Find1();         Console.ReadLine();      }       static void Find1()      { 

精益编程:Write Lean Programs

OO makes code understandable by encapsulating moving parting, but FP makes code understandable by minimizing moving parts. -Michael Feathers Product Repository First Attempt: The Worst Implement 需求1:在仓库中查找所有颜色为红色的产品 public ArrayList findAllRedProduct

Overview of MySQL Programs

mysqld    MySQL服务的后台程序,类似某些程序的后台程序如PostgreSQL的后台程序postgres , mongoDB的后台程序mongod等等.mysqld_safe    启动mysqld的一个脚本.mysql.server    也是启动mysqld的一个脚本,不过这个符合Linux SYSTEM V-Style的风格如sendmail等程序.(chkconfig --list可以看到).mysqld_multi    还是启动mysqld的脚本,这回这个脚本用于启动一台

第 29 章 Utility Programs

29.1. ed, red - text editor 行寻址 . 此选项对当前行寻址(缺省地址). number 此选项对第 number 行寻址.可以按逗号分隔的范围 (first,last) 对行寻址.0 代表缓冲区的开头(第一行之前). -number 此选项对当前行之前的第 number 行寻址.如果没有 number,则减号对紧跟在当前行之前的行寻址. +number 此选项对当前行之后的第 number 行寻址.如果没有 number,则加号对紧跟在当前行之后的行寻址. $ 此选项

第 7 章 Utility Programs

目录 7.1. ed, red - text editor 7.2. vim 7.2.1. 查找与替换 7.2.2. 插入文件 7.2.3. 批处理 7.2.3.1. vi 批处理 7.2.4. line() 7.2.5. set fileformat 7.3. awk 7.3.1. 处理列 7.3.2. printf 7.3.3. Pattern(字符匹配) 7.3.3.1. Pattern, Pattern 7.3.4. Built-in Variables (NR/NF) 7.3.4.1.

有哪些特别好看的大学网站首页?

  暨南大学 @赫赫是不着调小姐 :截图为招生界面,现已更改. 中国人民大学 截图为招生界面,现已更改. 一开始觉得好不好看这种问题在设计领域主观因素太多,更何况还掺杂了各位校友的感情因素,不如放个妹子上去,是吧? 随后人民大学官网短时间内流量急速上升,服务器不堪重负直接瘫痪. 其实国内知名大学的主页都还不错,而且很多风格类似.但是毕竟不是商业网站,就算技术达得到也不能太过炫酷,作为学校门户,让信息一目了然是主要目标.而且要考虑兼容性.此外,大学网站这种东西,要把很多因素考虑在内: 有时候学校网

.NET Framework For Java Programmers

.NET Framework For Java Programmers Author: Ashish Banerjee Objective After reading this article Java programmers should be able to decipher and de-jargonize the .NET architecture and relate it with the proposed ECMA standard.    Target Audience Java

VxWorks镜像简介

VxWorks镜像可分为三类:   可加载型VxWorks镜像:存储在开发机上,运行在板上RAM中   基于ROM的VxWorks镜像:存储在板上ROM,运行在板上RAM中   ROM驻留的VxWorks镜像:存储在板上ROM,运行在板上ROM中 一.可加载的VxWorks镜像     可加载的VxWorks镜像存储在开发机上,运行在RAM中.     在开发的初期阶段,可以根据需要添加或删除一些VxWorks组件,生成可加载的VxWorks镜像,存放在开发主机的某个目录下,便于调试.