C#ATM

2021-07-03 13:06

阅读:412

标签:构造函数   thread   convert   one   use   epo   NPU   []   ali   

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 - numOfTakeOut;
return true;
}
else return false;
}
}
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");
Console.WriteLine("你想?1.存钱 2.取钱 3.离开");
Keypad pad = new Keypad();
pad.GetInput();
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();
}
}

}

C#ATM

标签:构造函数   thread   convert   one   use   epo   NPU   []   ali   

原文地址:https://www.cnblogs.com/wavexu/p/9893351.html


评论


亲,登录后才可以留言!