Bank项目

Bank项目总共需要三个类来实现

首先创建一个自定义的卡类

卡类里面有四个属性:

卡号;持卡人;密码;余额。

class Card
      {
          private string cardNo;//卡号
          private string cardOwner;//持卡人
          private string cardPwd;//密码
          private double balance;//余额
  
          public double Balance
          {
             get { return balance; }
             set { balance = value; }
         }
         public string CardPwd
         {
             get { return cardPwd; }
             set { cardPwd = value; }
         }
        
         public string CardOwner
         {
             get { return cardOwner; }
             set { cardOwner = value; }
         }
         
         public string CardNo
         {
             get { return cardNo; }
             set { cardNo = value; }
         }
         
     }

然后再创建一个银行类
银行类有8个功能:

1.开户  2.存款 3.取款  4.查询余额 5.转账  6.修改密码  7.退出  8.输出所有账户的持卡人以及余额

//开户模块
  Console.WriteLine("欢迎进入开户模块");
              Console.WriteLine("请输入卡号");
              string cardNo = Console.ReadLine();
              Console.WriteLine("请输入密码");
              string cardPwd = Console.ReadLine();
              Console.WriteLine("请输入用户名");
              string cardOwner = Console.ReadLine();
              Console.WriteLine("请输入开户后要存储的金额");
              double balance = double.Parse(Console.ReadLine());
             //将bank里的值重新赋给Card中
             Card card = new Card();
             card.CardNo = cardNo;
             card.CardPwd = cardPwd;
             card.CardOwner = cardOwner;
             card.Balance = balance;
 
             //将card对象赋值给数组第一个为null的项目
             for (int i = 0; i < cards.Length; i++)
             {
                 if (cards[i]==null)
                 {
                     cards[i] = card;
                     Console.WriteLine("开户成功!");
                     break;
                 }
             }

  //存款模块
 Console.WriteLine("请输入您的账号");
             string cardno = Console.ReadLine();
             for (int i = 0; i < cards.Length; i++)
            {
                     if (cards[i] != null && cards[i].CardNo == cardno)
                     {
                          flag = true;
                          Console.WriteLine("请输入密码");
                          string pwd = Console.ReadLine();
                         if (cards[i].CardPwd == pwd)
                         {
                             Console.WriteLine("恭喜您登陆成功!请输入您要存款的金额:");
                             double GiveMoney = double.Parse(Console.ReadLine());
                             cards[i].Balance = cards[i].Balance + GiveMoney;
                             Console.WriteLine("恭喜您存款成功,您的当前余额为:{0}", cards[i].Balance);
                             break;
                         }
                         else
                         {
                             Console.WriteLine("您输入的密码有误!");
                             break;
                         }
                     }
             }

 //取款模块


 Console.WriteLine("请输入您的账号");
             string cardno = Console.ReadLine();
             for (int i = 0; i < cards.Length; i++)
             {
                 if (cards[i] != null && cards[i].CardNo == cardno)
                 {
                     flag1 = true;
                     Console.WriteLine("请输入密码");
                     string pwd = Console.ReadLine();
                     if (cards[i].CardPwd == pwd)
                     {
                         Console.WriteLine("恭喜您登陆成功!请输入您要取款的金额:");
                         double TakeMoney = double.Parse(Console.ReadLine());
                         cards[i].Balance = cards[i].Balance - TakeMoney;
                         Console.WriteLine("恭喜您存款成功,您的当前余额为:{0}", cards[i].Balance);
                         break;
                     }
                     else
                     {
                         Console.WriteLine("您输入的密码有误!");
                         break;
                     }
                 }
             }

//转账模块

 Console.WriteLine("请输入您的账号");
             string cardno = Console.ReadLine();
             for (int i = 0; i < cards.Length; i++)
             {
                 if (cards[i] != null && cards[i].CardNo == cardno)
                 {
                     flag2 = true;
                     Console.WriteLine("请输入密码");
                     string pwd = Console.ReadLine();
                     if (cards[i].CardPwd == pwd  && cards[i].Balance!=0)
                     {
                         if (cards[i].Balance!=0)
                         {
                         Console.WriteLine("恭喜您登陆成功!请输入您要转账的对象账户:");
                         string Target = Console.ReadLine();
                         for (int j = 0; j < cards.Length; j++)
                         {
                             if (cards[j].CardNo.Equals( Target) || cards[j].CardNo!=null )
                             {
                                 Console.WriteLine("请输入您的操作金额:");
                                 double Transform = double.Parse(Console.ReadLine());
                                if (Transform < cards[i].Balance && Transform != 0)
                                 {
                                     cards[i].Balance -= Transform;
                                     cards[j].Balance += Transform;
                                     Console.WriteLine("恭喜您转账成功!您的当前余额为:{0}", cards[i].Balance);
                                  break;
                                 }
                                 else 
                                 {
                                     Console.WriteLine("请输入正确的操作金额:");
                                 }
                             }
                             break;
                         }
                         break;
                         }
                         else
                         {
                             Console.WriteLine("您当前的余额不足!不能进行转账!");
                         }
                     }
                     else
                     {
                         Console.WriteLine("您输入的密码有误!");
                         break;
                     }
                 }
             }
             return flag2;
         }
 
         //查询余额
         public bool SelectMoney()
         {
             bool flag3 = false;
             Console.WriteLine("===================");
             Console.WriteLine("这里是查询余额模块");
             Console.WriteLine("===================");
 
             Console.WriteLine("请输入您的账号");
             string cardno = Console.ReadLine();
             for (int i = 0; i < cards.Length; i++)
             {
                 if (cards[i] != null && cards[i].CardNo == cardno)
                 {
                     flag3 = true;
                     Console.WriteLine("请输入密码");
                     string pwd = Console.ReadLine();
                     if (cards[i].CardPwd == pwd)
                     {
                         Console.WriteLine("恭喜您登陆成功!您的当前余额为:{0}:",cards[i].Balance);
                         Welcome();
                         break;
                     }
                     else
                     {
                         Console.WriteLine("您输入的密码有误!");
                         break;
                     }
                 }
             }

 

   

//修改密码

 Console.WriteLine("请输入您的账号");
             string cardno = Console.ReadLine();
             for (int i = 0; i < cards.Length; i++)
             {
                 if (cards[i] != null && cards[i].CardNo == cardno)
                 {
                     flag4= true;
                    Console.WriteLine("请输入你的密码");
                     string pwd = Console.ReadLine();
                    if (cards[i].CardPwd == pwd)
                     {
                         Console.WriteLine("请输入您的新密码:");
                         string pwd3=Console.ReadLine();
                         Console.WriteLine("请再次输入您的新密码:");
                         string pwd2=Console.ReadLine();
                         if (pwd2==pwd3)
                         {
                             cards[i].CardPwd = pwd3;
                         }
                         Console.WriteLine("恭喜您密码修改成功!您的新密码是{0}",cards[i].CardPwd);
                         Welcome();
                         break;
                     }
                     else
                     {
                         Console.WriteLine("您输入的密码有误!");
                         break;
                     }
                 }
             }


最后就是在Main()方法里面调用前两个类里的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bank
{
    class Program
    {
        static void Main(string[] args)
        {
            Bank bank=new Bank();
            bank.InitialData();//保证数组中前3项有值
            bank.PrintCustomerInfo();

            bank.Welcome();
            Console.ReadKey();
        }
    }
}


好了,我的Bank项目就是这样!虽然代码不是我自己打的,但是;也没有什么好但是的了,就这样吧。谢谢!!!

帅的人都点赞了   你还在犹豫什么?!!!

 

posted @ 2015-10-25 22:26  向着10K踏步走  阅读(146)  评论(0编辑  收藏  举报