我发表了一篇图片贴,大伙来看看吧~
澪滵吧
全部回复
仅看楼主
level 8
少年 楼主
2019年06月15日 10点06分 1
level 9
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Intrinsics.X86;
namespace ConsoleApp2
{
public class BankException : ApplicationException
{
public BankException()
{
}
public BankException(string message) : base(message)
{
}
public BankException(string message,Exception inner) : base(message, inner)
{
}
}
public interface GeneralATM
{
void Transaction(CreditBank bank);
}
public class ATM :GeneralATM
{
Bank bank;
public ATM(Bank bank)
{
this.bank = bank;
}
public void Transaction(CreditBank bank)
{
Show("这里是"+bank.bankname);
Show("请输入您的卡号");   //输入卡号
string id = GetInput();
Show("请输入您的密码");   //输入密码
string pwd = GetInput();
CreditAccount act=null;
foreach (CreditAccount account in bank.creditaccounts)
{
if (account.id == id && account.pwd==pwd) act = account;
};
if (act == null)
{
try
{
throw new BankException("卡号或密码错误");//卡号或密码错误
}
catch (BankException b)
{
Console.WriteLine(b.Message);
}
return;
}
Show("1: 查询余额; 2: 存钱; 3: 取钱");//成功登录,有三个选项对应三个功能
string op = GetInput();
if (op == "1")
{
Show("余额: " + act.getMoney());//显示当前账户余额
}
else if (op == "2")
{
Show("请输入想存的钱数");//给当前用户存钱
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.SaveMoney(money);
if (ok) Show("操作成功");
else Show("eeer");
Show("余额: " + act.getMoney());
}
else if (op == "3")  //从当前用户取钱
{
Show("请输入想取的钱数");
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.WithdrawMoney(money);
if (ok) Show("操作成功");//当取钱金额大于余额时,报错
else Show("eeer");
Show("余额: " + act.getMoney());
}
}
public void Show(string msg)
{
Console.WriteLine(msg);
}
public string GetInput()
{
return Console.ReadLine();// 输入字符
}
}
//--------------账号类--------------------
public class Account
{
double money; //decimal money;
public string id;
public string pwd;
//string name;
public Account(string id, string pwd, double money)
{
this.id = id;//账号
this.pwd = pwd;//密码
this.money = money;//余额
}
public double getMoney()
{
return money;
}
public void setMoney(double val)
{
this.money = val;
}
public string getId()
{
return id;
}
public void setId(string id)
{
this.id = id;
}
public string getpwd()
{
return pwd;
}
public void setPwd(string pwd)
{
this.pwd = pwd;
}
public bool SaveMoney(double money)
{
if (money < 0) return false; //卫语句
this.money += money;
return true;
}
public bool WithdrawMoney(double money)//取钱方法
{
if (this.money >= money)
{
this.money -= money;
return true;
}
return false;
}
public bool IsMatch(string id, string pwd)
{
return id == this.id && pwd == this.pwd;
}
}
2020年10月21日 11点10分 3
level 9
//信用类
public class CreditAccount : Account
{
double credit;//新增的信用额度字段
public CreditAccount(string id, string pwd, double money, double credit)
: base(id, pwd, money)
{
this.credit = credit;
this.setMoney(credit + this.getMoney());
}
public CreditAccount(string id, string pwd, double money)
: base(id, pwd, money)
{
this.credit = 0;
}
public bool changedebit(double debit)//重写方法
{
if (debit >= 0)
{
this.setMoney(this.getMoney() + (debit - this.credit));
this.credit = debit;
return true;
}
else
return false;
}
public double getdebit()
{
return credit;
}
}
//--------------------银行类----------------
public class Bank
{
public string bankname;
public ArrayList accounts = new ArrayList();
public Account OpenAccount(string id, string pwd,
double money)
{
Account account = new Account(id, pwd, money);
accounts.Add(account);
return account;
}
public bool CloseAccount(Account account)
{
int idx = accounts.IndexOf(account);
if (idx < 0) return false;
accounts.Remove(account);
return true;
}
public Account FindAccount(string id, string pwd)
{
foreach (Account account in accounts)
{
if (account.IsMatch(id, pwd))
{
return account;
}
}
return null;
}
}
public class CreditBank : Bank
{
public ArrayList creditaccounts = new ArrayList();
public CreditBank(string bankname)
{
this.bankname=bankname;
}
new public Account OpenAccount(string id, string pwd, double money)
{
CreditAccount account = new CreditAccount(id, pwd, money);
creditaccounts.Add(account);
return account;
}
public CreditAccount OpenAccount(string id, string pwd, double money, double debit)
{
CreditAccount creditaccount = new CreditAccount(id, pwd, money, debit);
creditaccounts.Add(creditaccount);
return creditaccount;
}
public CreditAccount getaccount(int i)
{
return (CreditAccount)creditaccounts[i];
}
public int getaccountsnum()
{
return creditaccounts.Count;
}
new public CreditAccount FindAccount(string id, string pwd)
{
foreach (CreditAccount account in creditaccounts)
{
if (account.IsMatch(id, pwd))
{
return account;
}
}
return null;
}
public class IndexedUsers
{
protected string[] userlist = new string[size];
static public int size = 3;
public string this[int index]
{
get
{
string tmp;
if (index >= 0 && index <= size - 1)
{
tmp = userlist[index];
}
else
{
tmp = "";
}
return (tmp);
}
set
{
if (index >= 0 && index <= size - 1)
{
userlist[index] = value;
}
}
}
public int this[string name]
{
get
{
int index = 0;
while (index < size)
{
if (userlist[index] == name)
{
return index;
}
index++;
}
return index;
}
}
}
2020年10月21日 11点10分 4
level 9
public class IndexedPasswords
{
protected string[] userlist = new string[size];
static public int size = 3;
public string this[int index]
{
get
{
string tmp;
if (index >= 0 && index <= size - 1)
{
tmp = userlist[index];
}
else
{
tmp = "";
}
return (tmp);
}
set
{
if (index >= 0 && index <= size - 1)
{
userlist[index] = value;
}
}
}
public int this[string name]
{
get
{
int index = 0;
while (index < size)
{
if (userlist[index] == name)
{
return index;
}
index++;
}
return index;
}
}
}
class Program
{
static void Main(string[] args)
{
CreditBank creditbank = new CreditBank("中国建设银行");
IndexedUsers users = new IndexedUsers();
users[0] = "222222";
users[1] = "333333";
users[2] = "444444";
IndexedPasswords passwords = new IndexedPasswords();
passwords[0] = "222222";
passwords[1] = "333333";
passwords[2] = "444444";
creditbank.OpenAccount(users[0], passwords[0], 2000);
creditbank.OpenAccount(users[1], passwords[1], 5000);
creditbank.OpenAccount(users[2], passwords[2], 5000, 100);
ATM atm = new ATM(creditbank);
while (true)
{
atm.Transaction(creditbank);
}
}
}
}
}
2020年10月21日 11点10分 5
level 9
2020年10月21日 11点10分 6
level 9
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Intrinsics.X86;
namespace ConsoleApp2
{
public class BankException : ApplicationException
{
public BankException()
{
}
public BankException(string message) : base(message)
{
}
public BankException(string message,Exception inner) : base(message, inner)
{
}
}
public interface GeneralATM
{
void Transaction(CreditBank bank);
}
public class ATM :GeneralATM
{
Bank bank;
public ATM(Bank bank)
{
this.bank = bank;
}
public void Transaction(CreditBank bank)
{
Show("这里是"+bank.bankname);
Show("请输入您的卡号");   //输入卡号
string id = GetInput();
Show("请输入您的密码");   //输入密码
string pwd = GetInput();
CreditAccount act=null;
foreach (CreditAccount account in bank.creditaccounts)
{
if (account.id == id && account.pwd==pwd) act = account;
};
if (act == null)
{
try
{
throw new BankException("卡号或密码错误");//卡号或密码错误
}
catch (BankException b)
{
Console.WriteLine(b.Message);
}
return;
}
Show("1: 查询余额; 2: 存钱; 3: 取钱");//成功登录,有三个选项对应三个功能
string op = GetInput();
if (op == "1")
{
Show("余额: " + act.getMoney());//显示当前账户余额
}
else if (op == "2")
{
Show("请输入想存的钱数");//给当前用户存钱
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.SaveMoney(money);
if (ok) Show("操作成功");
else Show("eeer");
Show("余额: " + act.getMoney());
}
else if (op == "3")  //从当前用户取钱
{
Show("请输入想取的钱数");
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.WithdrawMoney(money);
if (ok) Show("操作成功");//当取钱金额大于余额时,报错
else Show("eeer");
Show("余额: " + act.getMoney());
}
}
public void Show(string msg)
{
Console.WriteLine(msg);
}
public string GetInput()
{
return Console.ReadLine();// 输入字符
}
}
//--------------账号类--------------------
public class Account
{
double money; //decimal money;
public string id;
public string pwd;
//string name;
public Account(string id, string pwd, double money)
{
this.id = id;//账号
this.pwd = pwd;//密码
this.money = money;//余额
}
public double getMoney()
{
return money;
}
public void setMoney(double val)
{
this.money = val;
}
public string getId()
{
return id;
}
public void setId(string id)
{
this.id = id;
}
public string getpwd()
{
return pwd;
}
public void setPwd(string pwd)
{
this.pwd = pwd;
}
public bool SaveMoney(double money)
{
if (money < 0) return false; //卫语句
this.money += money;
return true;
}
public bool WithdrawMoney(double money)//取钱方法
{
if (this.money >= money)
{
this.money -= money;
return true;
}
return false;
}
public bool IsMatch(string id, string pwd)
{
return id == this.id && pwd == this.pwd;
}
}
2020年10月21日 12点10分 7
level 1
Java?
2021年12月01日 08点12分 10
你咋知道
2021年12月01日 11点12分
@少年 两年前学过,忘差不多了,基本的还记得点
2021年12月01日 11点12分
@梨悍 哈哈哈哈 还以为你跟我一个专业的
2021年12月01日 11点12分
@少年 你学的计算机我学的软件,侧重点可能不太一样但是殊途同归哈哈哈哈
2021年12月01日 13点12分
1