using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ATM
{
public class Bankcard
{
public string num;
public string pwd;
public string name;
public float money;
public static int count = 5;
public Bankcard()
{
}
public Bankcard(string num, string pwd, string name, float money)
{
this.num = num;
this.pwd = pwd;
this.name = name;
this.money = money;
}
}
class Program
{
static Bankcard[] a = new Bankcard[5];
static void init()
{
a[0] = new Bankcard("123", "000", "a", 10000);
a[1] = new Bankcard("1234", "000", "a", 10000);
a[2] = new Bankcard("12345", "000", "a", 10000);
a[3] = new Bankcard("123456", "000", "a", 10000);
a[4] = new Bankcard("1234567", "000", "a", 10000);
}
public static int checknum()
{
string num1;
Console.WriteLine("请输入卡号:");
num1 = Console.ReadLine();
for (int i = 0; i < Bankcard.count; i++)
{
if (num1 == a[i].num)
{
return i;
}
}
return -1;
}
public static bool checkpwd(int b)
{
int count = 0;
do
{
Console.WriteLine("请输入密码:");
String pwd1 = Console.ReadLine();
if (pwd1 == a[b].pwd)
{
return true;
}
else
{
count++;
}
}
while (count < 3);
return false;
}
public static void getmoney(int b)
{
Console.WriteLine("1.100" + "\t" + "2.300");
Console.WriteLine("3.500" + "\t" + "4.其他");
Console.WriteLine("请选择取款金额:");
Console.ReadLine();
int choice = Console.Read();
switch (choice)
{
case '1':
if (a[b].money > 100)
{
Console.WriteLine("100");
a[b].money = a[b].money - 100;
Console.WriteLine("你的余额是:" + a[b].money);
}
else
Console.WriteLine("你的余额不足!");
break;
case '2':
if (a[b].money > 300)
{
Console.WriteLine("300");
a[b].money = a[b].money - 300;
Console.WriteLine("你的余额是:" + a[b].money);
}
else
Console.WriteLine("你的余额不足!");
break;
case '3':
if (a[b].money > 500)
{
Console.WriteLine("500");
a[b].money = a[b].money - 500;
Console.WriteLine("你的余额是:" + a[b].money);
}
else
Console.WriteLine("你的余额不足!");
break;
case '4':
int money2;
do
{
Console.WriteLine("输入取款金额:");
money2 = Console.Read();
}
while (money2 % 100 != 0 || money2 > 3000);
if (a[b].money > money2)
{
a[b].money = a[b].money - money2;
Console.Write("您的余额是:" + a[b].money);
}
else
Console.Write("你的余额不足!");
break;
default:
Console.Write("你的输入有误!");
break;
}
}
public static void chaxun(int b)
{
Console.WriteLine("你的余额是:" + a[b].money);
}
public static void zhuanzhang(int b)
{
bool flag;
Console.ReadLine();
do
{
Console.WriteLine("请输入转入的帐号;");
string num1 = Console.ReadLine();
flag = true;
for (int i = 0; i < Bankcard.count; i++)
{
if (num1 == a[i].num)
{
Console.WriteLine("请输入金额;");
float m1 = float.Parse(Console.ReadLine());
if (a[b].money > m1)
{
a[b].money = a[b].money - m1;
a[i].money = a[i].money + m1;
Console.Write("您的余额是:" + a[b].money);
}
else
Console.Write("你的余额不足!");
flag = true;
break;
}
else
flag = false;
}
} while (flag == false);
}
public static void xiugaimima()
{
// string pwd1;
// string pwd2;
// Console.Write("请输入新密码:");
//string pwd1 = Console.WriteLine();
// Console.Write("请确认密码:");
// pwd2 = Int32.Parse (Console.WriteLine());
// if (pwd1.Equals(pwd2))
// {
// pwd = pwd1;
// Console.Write("密码修改成功!");
//}
//else
// Console.Write("两次输入密码不一致!");
}
public static void welcome(int b)
{
int a = b;
Console.WriteLine("====欢迎使用自动取款机!======");
Console.WriteLine("1.取款" + "\t" + "2.查询");
Console.WriteLine("3.转帐" + "\t" + "4.修改密码");
Console.WriteLine("5.退出");
Console.WriteLine("请选择要操作的数字(1—4):");
int choice = Console.ReadLine();
switch (choice)
{
case '1':
getmoney(b);//取款
break;
case '2':
chaxun(b);//查询
break;
case '3':
zhuanzhang(b);//转帐
break;
case '4':
xiugaimima();//修改密码
break;
case '5':
Environment.Exit(0);//转帐
break;
default :
Console .WriteLine ("您的输入有误!");
}
}
static void Main(string[] args)
{
init();//初始化
int a = checknum();//判断帐号
if (a != -1)
{
if (checkpwd(a) == true)//判断密码
{
welcome(a);
}
}
else
{
Console.WriteLine("卡号有误!");
}
Environment.Exit(0);//退出
}
}
}
简单的ATM的存取款
最新推荐文章于 2020-07-20 19:34:41 发布