Mall billing system based on Rule mode (C # source code)

Source: Internet
Author: User
From: http://blog.csdn.net/andylin02/archive/2008/11/14/3302034.aspx

  1. Using system;
  2. Namespace cashsystem
  3. {
  4. // Thread class
  5. Class crunmain
  6. {
  7. Public static void showmessage ()
  8. {
  9. Console. writeline ("----------------- please input your choise :------------");
  10. Console. writeline ("/T/t0. quite ");
  11. Console. writeline ("/T/T1. pay cash noremally ");
  12. Console. writeline ("/T/T2. Pya cash in 8 rebate ");
  13. Console. writeline ("/T/T3. pay cash in after 300 return 100 ");
  14. Console. writeline ("-------------------------------------------------------");
  15. }
  16. Public static int main ()
  17. {
  18. Ccashcontext objcont = new ccashcontext ();
  19. Ccashsuper objcash = NULL;
  20. While (true)
  21. {
  22. Int nchoice = 0;
  23. Int ncount = 0;
  24. Double dumoney = 0.0;
  25. Double duprice = 0.0;
  26. Showmessage ();
  27. Nchoice = convert. toint32 (console. Readline ());
  28. Switch (nchoice)
  29. {
  30. Case 0:
  31. Console. writeline ("press any key to quit! ");
  32. Console. Read ();
  33. Return 0;
  34. Case 1:
  35. Objcash = new ccashnormal ();
  36. Break;
  37. Case 2:
  38. Objcash = new ccashrebate (0.8 );
  39. Break;
  40. Case 3:
  41. Objcash = new ccashreturn (300,100 );
  42. Break;
  43. Default:
  44. Objcash = NULL;
  45. Break;
  46. }
  47. If (null = objcash)
  48. {
  49. Console. writeline ("input error! ");
  50. Continue;
  51. }
  52. // Set cash object
  53. Objcont. setbehavior (objcash );
  54. Console. writeline ("Please input price :");
  55. Duprice = convert. todouble (console. Readline ());
  56. Console. writeline ("Please input count :");
  57. Ncount = convert. toint32 (console. Readline ());
  58. Dumoney = duprice * ncount;
  59. Console. writeline ("the properly money you shoshould pay is" + objcont. getresult (dumoney ));
  60. }
  61. }
  62. };
  63. // Billing policy context
  64. Class ccashcontext
  65. {
  66. // Set the policy action. The parameter is the specific sub-class of cash charge (normal, discount or rebate)
  67. Public void setbehavior (ccashsuper objcash)
  68. {
  69. This. m_objcash = objcash;
  70. }
  71. Public double getresult (double dumoney)
  72. {
  73. If (null = This. m_objcash)
  74. {
  75. Console. writeline ("null = m_objcash ");
  76. Return 0;
  77. }
  78. Return this. m_objcash.acceptcash (dumoney );
  79. }
  80. Private ccashsuper m_objcash;
  81. };
  82. Abstract class ccashsuper
  83. {
  84. Public abstract double acceptcash (double dumoney );
  85. };
  86. Class ccashreturn: ccashsuper
  87. {
  88. Public ccashreturn (double ducondition, double dureturn)
  89. {
  90. This. m_ducondition = ducondition;
  91. This. m_dureturn = dureturn;
  92. }
  93. Public override double acceptcash (double dumoney)
  94. {
  95. If (dumoney> This. m_ducondition)
  96. {
  97. Dumoney-= This. m_dureturn;
  98. }
  99. Return dumoney;
  100. }
  101. Private double m_ducondition = 0.0;
  102. Private double m_dureturn = 0.0;
  103. };
  104. Class ccashnormal: ccashsuper
  105. {
  106. Public override double acceptcash (double dumoney)
  107. {
  108. Return dumoney;
  109. }
  110. };
  111. Class ccashrebate: ccashsuper
  112. {
  113. Public ccashrebate (double durebate)
  114. {
  115. This. m_durebate = durebate;
  116. }
  117. Public override double acceptcash (double dumoney)
  118. {
  119. Return dumoney * This. m_durebate;
  120. }
  121. Private double m_durebate;
  122. };
  123. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.