using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ATM.Day02
{
class Bank
{ public int index; public Account[] accounts = new Account[]; public Account account = new Account(); public CreditAccount credit = new CreditAccount(); /// <summary>
/// 用户开户方法
/// </summary>
/// <param name="id">银行账户</param>
/// <param name="passWord">密码</param>
/// <param name="passWords">确认密码</param>
/// <param name="name">姓名</param>
/// <param name="userId">身份证号</param>
/// <param name="email">邮箱</param>
/// <param name="type">类型</param>
/// <returns>Account实体类</returns>
public Account Register(long id,string passWord,string passWords,string name, string userId,string email,string type)
{
account.Id = id;
account.PassWord = passWord;
account.Name = name;
account.PersonId = userId;
account.Email = email;
account.Type = type;
if (!account.PassWord.Equals(passWords))
{
Console.WriteLine("确认密码不匹配,请核对后重新填写。");
return null;
}
if (accounts == null || accounts.Length == )
{
index = ;
}
else
{
index = accounts.Length - ;
}
accounts[index] = account; return account;
} /// <summary>
/// 登录方法
/// </summary>
/// <param name="id">银行卡号</param>
/// <param name="passWord">取款密码</param>
/// <returns>Account实体类</returns>
public Account Login(long id, string passWord)
{
for (int i = ; i < accounts.Length; i++)
{
if (id == accounts[i].Id)
{
account.Id = accounts[i].Id;
account.PassWord = passWord;
account.Name = accounts[i].Name;
account.PersonId = accounts[i].PersonId;
account.Email = accounts[i].Email;
account.Type = accounts[i].Type;
return account;
}
}
return null;
} /// <summary>
/// 存钱方法
/// </summary>
/// <param name="id">银行账户</param>
/// <param name="money">钱</param>
/// <returns>Account实体类</returns>
public Account Deposit(long id,double money)
{
if (account.Id!=id)
{
Console.WriteLine("当前用户不存在,请核对后进行操作。");
return null;
}
else if (money<=)
{
Console.WriteLine("金额数据不正确,请核对后进行操作。");
return null;
}
account.Balance += money; return account;
} /// <summary>
/// 取钱方法
/// </summary>
/// <param name="id">银行卡号</param>
/// <param name="passWord">取款密码</param>
/// <param name="money">金额</param>
/// <returns>返回Account类型实体类</returns>
public Account Withdraw(long id,string passWord,double money)
{
if (account.Id == id && passWord.Equals(account.PassWord) && account.Type.Equals(""))
{
if (account.Balance < money )
{
Console.WriteLine("当前账户余额不足!");
return null;
}
else if (account.Id == id && passWord.Equals(account.PassWord) && account.Type.Equals(""))
{
credit = (CreditAccount)account;
return credit.Withdraw(money);
} }
else
{
Console.WriteLine("当前账户:用户名或密码输入错误,请重新输入");
return null;
}
return credit;
} /// <summary>
/// 设置信用额度
/// </summary>
/// <param name="id">银行卡号</param>
/// <param name="passWord">银行密码</param>
/// <param name="money">钱</param>
/// <returns>返回Account类型实体类</returns>
public Account UpdateCeiling(long id,string passWord,double money)
{
if (account.Type.Equals(""))
{
credit.Ceiling = money;
return credit;
}
return null;
} /// <summary>
/// 转账方法
/// </summary>
/// <param name="id">账户号码</param>
/// <param name="passWord">密码</param>
/// <param name="fromId">转入账号</param>
/// <param name="money">金额</param>
/// <returns>返回bool值</returns>
public bool Transfer(long id, string passWord, long fromId, double money)
{
if (account.Id == id && passWord.Equals(account.PassWord))
{
for (int i = ; i < accounts.Length; i++)
{
if (fromId == accounts[i].Id)
{
if (accounts[i].Id > money)
{
accounts[i].Balance -= money;
return true;
}
else
{
Console.WriteLine("账号余额不足 不允许转账");
return false;
}
}
}
}
return false;
} public override string ToString()
{
string toString = string.Empty;
return toString = "账号余额:" + account.Balance + "用户姓名:" + account.Name + "账户类型:" + account.Type;
}
}
}
public class CreditAccount : Account
{ public CreditAccount()
{ } private double ceiling; public double Ceiling
{
set { this.ceiling = value; }
get { return this.ceiling; }
} public override Account Withdraw(double money)
{
if (this.Ceiling + this.Balance < money)
{
Console.WriteLine("当前账户信用额度不足!");
return null;
}
if (this.Balance < money)
{
this.Ceiling = (this.Balance + this.Ceiling) - money;
this.Balance = ;
}
return this;
} }

方法不一定最好,主要练习一下项目。

本系列教程:

C#基础总结之八面向对象知识点总结-继承与多态-接口-http://www.cnblogs.com/spring_wang/p/6113531.html

C#基础总结之七面向对象知识点总结1http://www.cnblogs.com/spring_wang/p/6113526.html

C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习http://www.cnblogs.com/spring_wang/p/6113520.html

C#基础总结之五Dictionary<string, string[]>和while循环http://www.cnblogs.com/spring_wang/p/6113514.html

C#基础总结之四List-Hashtable-冒泡排序http://www.cnblogs.com/spring_wang/p/6113504.html

C#基础总结之三循环控制-for-数组-乘法表-arraylisthttp://www.cnblogs.com/spring_wang/p/6113496.html

C#基础总结之二循环控制-运算符http://www.cnblogs.com/spring_wang/p/6113484.html

C#基础总结之一变量常量-if嵌套语句-witch结构-类型转换http://www.cnblogs.com/spring_wang/p/6113476.html

C#基础课程之六(临时表)DataTable使用方法http://www.cnblogs.com/spring_wang/p/6113454.html

C#基础课程之五集合(HashTable,Dictionary)http://www.cnblogs.com/spring_wang/p/6113404.html

C#基础课程之四集合(ArrayList、List<泛型>)http://www.cnblogs.com/spring_wang/p/6113396.html

C#基础课程之三循环语句http://www.cnblogs.com/spring_wang/p/6113383.html

C#基础课程之二变量常量及流程控制http://www.cnblogs.com/spring_wang/p/6113372.html

C#基础课程之一注释和控制台、一些常识http://www.cnblogs.com/spring_wang/p/6113361.html

C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113291.html

C#基础第九天-作业-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113285.html

C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113274.html

C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113258.html

C#基础第七天-作业答案-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113232.html

C#基础第七天-作业-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113224.html

C#基础第六天-作业-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113028.html

C#基础第六天-作业答案-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113033.html

C#基础第五天-作业答案-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113022.html

C#基础第五天-作业-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113013.html

C#基础第四天-作业答案-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113005.html

C#基础第四天-作业-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113000.html

C#基础第三天-作业答案-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112888.html

C#基础第三天-作业-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112885.html

C#基础第二天-作业答案-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112881.html

C#基础第二天-作业-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112875.html

C#基础第一天-作业答案http://www.cnblogs.com/spring_wang/p/6112872.html

C#基础第一天-作业http://www.cnblogs.com/spring_wang/p/6112867.html

C#-string.Format对C#字符串格式化http://www.cnblogs.com/spring_wang/p/6077098.html

C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账的更多相关文章

  1. C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账

    要求1:完成以下两种账户类型的编码.银行的客户分为两大类:储蓄账户(SavingAccount)和信用账户(CreditAccount),两种的账户类型的区别在于:储蓄账户不允许透支,而信用账户可以透 ...

  2. C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount)

    class Bank { //Dictionary<long,Account> dictionary=new Dictionary<long,Account>(); DataT ...

  3. C#基础第二天-作业答案-九九乘法表-打印星星

    题一:九九乘法表的答案 //正三角 ; i < ; i++) { ; j <= i; j++) { Console.Write("{0}*{1}={2} ", j, i ...

  4. C#基础第一天-作业答案

    题一答案: Console.WriteLine("请输入a"); int a = Convert.ToInt32(Console.ReadLine()); Console.Writ ...

  5. C#基础第七天-作业答案-利用面向对象的思想去实现名片-动态添加

    class Card { private string name; public string Name { get { return name; } set { name = value; } } ...

  6. C#基础第六天-作业答案-利用面向对象的思想去实现名片

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. C#基础第五天-作业答案-用DataTable制作名片集

    .DataTable 实现 DataTable PersonCard = new DataTable(); //创建一个DataTable DataTable PersonCardCopy = new ...

  8. C#基础第四天-作业答案-Hashtable-list<KeyValuePair>泛型实现名片

    .Hashtable 实现 Hashtable table = new Hashtable(); while (true) { Console.WriteLine("------------ ...

  9. C#基础第三天-作业答案-集合-冒泡排序-模拟名片

    .冒泡排序 Console.WriteLine("对集合里的数进行排序,请输入第一个数:"); int a = int.Parse(Console.ReadLine()); Con ...

随机推荐

  1. vuejs组件交互 - 03 - vuex状态管理实现组件交互

    组件交互模式的使用场景 简单应用直接使用props down,event up的模式就可以了 小型应用使用事件中心模式即可 中大型应用使用vuex的状态管理模式 vuex 包含要管理的应用数据和更新数 ...

  2. A Dog's Way Home插曲列表

    The movie songs A Dog's Way Home   文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论

  3. 跟 Google 学 machineLearning [2] -- 关于 classifier.fit 的 warning

    tensorfllow 的进化有点快.学习的很多例子已经很快的过时了,这里记录一些久的例子里被淘汰的方法,供后面参考. 我系统现在安装的是 tensorflow 1.4.1. 主要是使用了下面的代码后 ...

  4. Canvas动画 位图缓存提高效率和对应的内存问题

    对一个矢量图动画,开启位图缓存能大大提高运行效率.所谓开启位图缓存,其实要自己动手,先创建一个临时canvas,然后把矢量图绘制到这个canvas上,到了实际绘制时,直接把这个临时canvas拷贝到真 ...

  5. oracle 12c 官方文档 及软件下载

    oracle 12c 官方文档 http://www.oracle.com/pls/db121/homepage oracle 12c 软件下载 http://www.oracle.com/techn ...

  6. maven-war-plugin 插件 web.xml 缺失时忽略

    我们很多时候开发Spring MVC 项目时我们完全可以使用Java Bean 和 Annotation 的方式来配置 Spring MVC 的 DispatcherServlet,而不再采用传统的 ...

  7. 配置Jenkins的slave节点的详细步骤适合windows等其他平台

    @  新建一个slave节点在Jenkins服务器上 1,进入Jenkins的主界面,进入"Manage Jenkins" 页面: 2,点击如下图中的"Manage  N ...

  8. Java中的Random()函数 【转载】

        今天在做Java练习的时候注意到了Java里面的一个随机函数——Random,刚开始只是知道这个函数具有随机取值的作用,于是上网搜索了资料一番,做了一下一些关于Random函数的总结:   J ...

  9. VS 2013 with update 5 编译程序出现A task was cancel

    打开进程管理器看,有一堆MSBuild.exe的实例,于是用 Taskkill /IM MSBuild.exe /F 杀死了所有实例.然后再重新打开VS2013,就work了. references: ...

  10. C#几个小知识点

    一.float数据类型 小数在C#中需要用浮点型表示,浮点值就是.后面的小数点.C#语言中有两种小数类型,分别为32位单精度浮点型(float) 和64位双精度浮点型(double).其中精度指的是小 ...