C#ATM

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

namespace ConsoleApplication2
{
public class Account//定义一个类Account
{
private int accountnumber;//定义一个变量卡号
private int pin;//定义一个变量密码
public int Balance;//定义一个变量余额
public Account(int number, int password, int userbalance)
{
accountnumber = number;
pin = password;
Balance = userbalance;
}//构造函数Account,输入姓名,密码和余额
public int Number
{
get { return accountnumber; }
}//设置账户为只读属性
public int Userbalance
{
get { return Balance; }
}//设置余额为只读属性
public bool ValidatePIN(int userPIN)
{
return (userPIN == pin);
}//验证输入密码是否正确
public void Credit(int amount)
{
Balance += amount;
}//存款
public void Debit(int amount)
{
Balance -= amount;
}//取款
public bool toDeposit(int numOfDeposit)
{
if (numOfDeposit >= 0) //存储金额为正数
{
Balance = Balance + numOfDeposit;
return true;
}
else
{
return false;
}
}

//取钱
public bool toTakeOut(int numOfTakeOut)
{
if ((numOfTakeOut >= 0) && (numOfTakeOut <= Balance)) //要保证取钱数为正数,且要小于余额
{
Balance = Balance - numOfTakeOut;
return true;
}
else
{
Console.WriteLine("你的余额不足!");
return false;
}
}
public void zhanghao(int number,int k)
{
Console.WriteLine("请输入账号:");
k = 1;
while (k>0)
{
int str = Convert.ToInt32(Console.ReadLine());
if (str != number)
{
Console.WriteLine("账号输入错误,请重新输入。");
k = k;

}
else k = 0;
}
}
public void mima(int password,int y)
{
Console.WriteLine("请输入密码:");
y=1;
while (y > 0)
{
int s = Convert.ToInt32(Console.ReadLine());
if (s != password)
{
Console.WriteLine("密码输入错误,请重新输入。");
y = y;
}
else y = 0;
}
}
}
public class role//create a class named role
{
private string administrators;
private string administratorpin;
public role(string Admin, string Adminpin)
{
administrators = Admin;
administratorpin = Adminpin;
}//构造一个函数,输入管理员的账号,密码
public string Administratorsnumber
{
get { return administrators; }
}//设置管理员账号只读
public bool Apin(string ADMpin)
{
return (administratorpin == ADMpin);
}//验证密码是否正确

}
public class Keypad
{
public int GetInput()
{
return Convert.ToInt32(Console.ReadLine());
} //根据用户输入,返回一个整型
}
class program
{
static void Main(string[] args)
{
Account user = new Account(12345, 12345, 10000);
role roleone = new role("roleone", "impassword");
user.zhanghao(12345,1);
user.mima(12345,1);
Keypad pad = new Keypad();
pad.GetInput();
Console.WriteLine("你想?1.存钱 2.取钱 3.离开");
int a = pad.GetInput();
while (a > 0)
{
if (a == 1)
{
Console.WriteLine("请输入你存入的金额");
int b = pad.GetInput();
user.toDeposit(b);
Console.WriteLine("你的余额为{0}元", user.Balance);
}
else
{
if (a == 2)
{
Console.WriteLine("请输入你取出的金额");
int b = pad.GetInput();
user.toTakeOut(b);
Console.WriteLine("你的余额为{0}元", user.Balance);
}
else
{
if (a == 3)
{
Console.WriteLine("再见!");
a = -1;
break;
}
else
{
Console.WriteLine("非法输入,请重新输入。");
}
}


}
Console.WriteLine("你想?1.存钱 2.取钱 3.离开");
int d = pad.GetInput();
a = d;
}
Console.ReadKey();
}
}

}

转载于:https://www.cnblogs.com/wavexu/p/9893351.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值