BAM银行账户管理系统java类Word文档下载推荐.docx
- 文档编号:3636875
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:27
- 大小:148.34KB
BAM银行账户管理系统java类Word文档下载推荐.docx
《BAM银行账户管理系统java类Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《BAM银行账户管理系统java类Word文档下载推荐.docx(27页珍藏版)》请在冰点文库上搜索。
publicabstractclassAccount{
//属性
ﻩprotectedlongid;
ﻩprotectedStringpassword;
ﻩprotectedString name;
ﻩprotectedStringpersonId;
ﻩprotected intaccountType;
protecteddoublebalance;
//构造方法
ﻩpublicAccount(){
super();
ﻩ}
public Account(longid,Stringpassword,Stringname,StringpersonId,
ﻩintaccoutType,double balance){
ﻩsuper();
ﻩthis。
id = id;
this。
password=password;
this。
name = name;
ﻩthis.personId=personId;
this.accountType= accountType;
ﻩthis.balance=balance;
ﻩ}
ﻩ//getXxx,setXxx方法
public long getId(){
ﻩreturn id;
ﻩpublicvoidsetId(longid){
ﻩthis.id=id;
}
ﻩpublicStringgetPassword(){
ﻩreturn password;
ﻩpublicvoidsetPassword(Stringpassword) {
ﻩthis.password= password;
publicString getName(){
ﻩreturnname;
ﻩpublicvoidsetName(Stringname) {
ﻩthis.name= name;
ﻩpublicString getPersonId(){
ﻩreturnpersonId;
}
public voidsetPersonId(StringpersonId){
ﻩthis.personId=personId;
ﻩpublicintgetAccountType(){
returnaccountType;
ﻩpublicvoid setAccountType(intaccountType) {
ﻩthis。
accountType =accountType;
publicdouble getBalance(){
ﻩreturnbalance;
ﻩpublic voidsetBalance(double balance){
ﻩthis.balance=balance;
ﻩ/**
*存款
public void deposit(doublemoney){
ﻩbalance+= money;
ﻩ/**
ﻩ*取款(取款方式由账户类型决定,所以设为抽象方法,相应的Account类应设为抽象类)
publicabstractvoid withdraw(doublemoney);
}
SavingAccount类
packagecom.qx;
/**
*储蓄账户类
*/
publicclassSavingAccountextendsAccount {
//构造函数
ﻩpublicSavingAccount(){
ﻩsuper();
publicSavingAccount(long id,String password,Stringname,
ﻩString personId,intaccountType,double balance){
ﻩsuper(id, password,name, personId,accountType, balance);
ﻩ//对父类的withdraw()实现
ﻩpublicvoid withdraw(double money){
ﻩif(balance 〈money){
ﻩﻩSystem。
out.println("
对不起,账户余额不足!
"
);
ﻩﻩ}
ﻩﻩelse
ﻩﻩ{
balance-= money;
ﻩ}
}
CresitAccount类
packagecom。
qx;
/**
*信用账户类,增加一个信用额度ceiling属性
publicclassCreditAccount extendsAccount{
privateintceiling;
ﻩ//构造函数
ﻩpublic CreditAccount(){
ﻩsuper();
publicCreditAccount(longid,Stringpassword,Stringname,
ﻩStringpersonId,intaccountType,doublebalance,intceiling){
ﻩsuper(id,password,name,personId,accountType,balance);
ﻩﻩthis.ceiling =ceiling;
//getXxx,setXxx方法
publicintgetCeiling() {
returnceiling;
public voidsetCeiling(intceiling){
this.ceiling=ceiling;
//实现父类的withdraw()
ﻩpublic voidwithdraw(double money){
if((balance +ceiling)<
money){
ﻩSystem。
out.println("
对不起,已超出您的信用额度!
”);
}
ﻩelse
ﻩ{
ﻩﻩﻩbalance-=money;
}
Bank类
packagecom.qx;
importjava.io.BufferedReader;
importjava。
io.BufferedWriter;
import java.io.File;
import java.io。
;
importjava.io.;
import java。
io。
;
importjava.io.IOException;
importjava。
util.Properties;
/**
*Bank类
*编写Bank类,属性:
1.当前所有的账户对象的集合,存放在数组中
2.当前账户数量
方法:
1.用户开户,需要的参数:
id,密码,密码确认,姓名,身份证号码,账户类型,返回新创建的Account对象的账号,
提示:
用s1。
equals(s2)可以比较s1,s2两个字符串的值是否相等.账户类型是一个整数,为0的时候表示储蓄账户,为1的时候表示信用账户
2.用户登录,参数:
id,密码返回登录账户的账号
3.用户存款,参数:
id,存款数额,返回void
4.用户取款,参数:
id,取款数额,返回void
5.查询余额,参数:
id,返回该账户的余额 double
用户会通过调用Bank对象以上的方法来操作自己的账户,请分析各个方法需要的参数
publicclassBank{
privateAccount[]accounts=newAccount[20];
privateintnumber;
//账户数目
ﻩprivateintid=1001;
//确定银行账号从1001开始生成,即第一个账户的账号是1001
ﻩpublicBank(){
accounts=newAccount[20];
//以后不足时扩容。
number=0;
ﻩBufferedReaderbufReader =null;
ﻩﻩPropertiesprops=System。
getProperties();
ﻩﻩStringpath=props.getProperty("
user。
dir”);
try{
ﻩﻩbufReader=newBufferedReader(new (new,"
account.txt"
)));
ﻩString s =bufReader。
readLine();
ﻩﻩwhile(s!
=null){
ﻩString[] str =s.split("
,”);
ﻩﻩﻩif(str[4].equals(”0"
))
ﻩ{
ﻩﻩﻩﻩﻩAccountsavingAcc=newSavingAccount(Long。
parseLong(str[0]),
ﻩﻩﻩﻩstr[1].toString(),str[2]。
toString(),
ﻩﻩstr[3].toString(),Integer.parseInt(str[4]),
ﻩﻩﻩﻩDouble.parseDouble(str[5]));
ﻩaccounts[number] =savingAcc;
ﻩﻩ}
ﻩﻩﻩﻩelse
ﻩﻩ{
ﻩﻩﻩﻩAccountcreditAcc= new CreditAccount(Long.parseLong(str[0]),
ﻩstr[1]。
toString(), str[2].toString(),
ﻩﻩﻩﻩﻩﻩstr[3].toString(),Integer.parseInt(str[4]),
ﻩDouble.parseDouble(str[5]),5000);
ﻩﻩaccounts[number]=creditAcc;
ﻩ
ﻩ}
ﻩﻩnumber++;
ﻩﻩid++;
ﻩs=bufReader.readLine();
}
ﻩ}catch(NumberFormatExceptione) {
ﻩﻩ//TODOAuto—generated catchblock
ﻩe.printStackTrace();
ﻩﻩ}catch(e){
ﻩﻩ//TODOAuto-generatedcatch block
ﻩﻩe。
printStackTrace();
}catch (IOExceptione) {
ﻩ//TODO Auto-generatedcatchblock
ﻩﻩe.printStackTrace();
ﻩ}finally{
ﻩtry {
ﻩﻩﻩif(bufReader!
=null)
ﻩﻩﻩﻩbufReader。
close();
ﻩﻩﻩﻩ}
ﻩﻩ}catch(IOExceptione) {
ﻩﻩﻩﻩ//TODOAuto—generatedcatchblock
ﻩe。
printStackTrace();
ﻩﻩ}
//getXxx,setXxx
ﻩpublic Account[]getAccounts(){
return accounts;
ﻩpublic void setAccounts(Account[]accounts){
this。
accounts= accounts;
ﻩpublic intgetNumber(){
ﻩreturnnumber;
ﻩpublicvoid setNumber(intnumber){
number=number;
publicintgetId() {
ﻩreturnid;
publicvoid setId(intid){
ﻩthis.id=id;
/**
*开户
ﻩ*/
ﻩpublicAccount openAccount(Stringpasswd1, String passwd2,Stringname,
ﻩﻩStringpersonId,inttype){
ﻩ//创建一个新账户
ﻩAccount account= null;
ﻩﻩ//判断两次密码是否一致
ﻩif(passwd1.equals(passwd2)){
ﻩﻩﻩ//若一致,再判断账户类型(根据type的值)
ﻩﻩif(type ==1){
ﻩﻩ//可令开始余额为10,信用额度为5000
ﻩﻩaccount=new CreditAccount(id,passwd1, name,personId, type, 10,5000);
ﻩﻩelse
ﻩﻩﻩ{
ﻩﻩaccount=newSavingAccount(id, passwd1, name, personId,type,10);
ﻩﻩ}
ﻩﻩ//将账户存入账户数组accounts[]中
ﻩ//判断是否超出存储空间
ﻩif(number >=accounts.length)
{//扩容
ﻩﻩAccount[]newAccounts=newAccount[accounts。
length*2];
ﻩ//copy原来的相关数据
ﻩﻩﻩSystem。
arraycopy(accounts,0, newAccounts,0, accounts.length);
ﻩﻩﻩ//将newAccounts[]赋给accounts[]
accounts=newAccounts;
ﻩﻩﻩaccounts[number]=account;
ﻩﻩ}
ﻩﻩelse
ﻩaccounts[number]= account;
ﻩSystem.out。
println("开户成功!
!
账户信息见下”);
ﻩﻩSystem。
out。
println("您的卡号为:
+id+”\n"
+”您的密码为:
+passwd1+"
\n”+”您的户名为:
+name+"
\n”
ﻩﻩ+"
您的身份证号为:
”+personId+"\n"
+"
您的账户类型为:
+type+"\n”);
ﻩaccount。
accountType =type;
ﻩﻩnumber++;
ﻩﻩid++;
ﻩreturnaccount;
//此时开户成功
else
{
ﻩSystem.out.println("
对不起!
您两次密码输入不匹配,开户失败!
!
");
ﻩﻩreturn null;
//此时开户失败
ﻩ/**
*保存数据
publicvoidsaveAccountDate(){
ﻩﻩBufferedWriterbufWriter=null;
ﻩﻩtry{
ﻩﻩﻩProperties props=System.getProperties();
ﻩStringpath=props。
getProperty("
user.dir");
ﻩﻩbufWriter=newBufferedWriter(new(new,”account。
txt"
)));
for(int i =0;
i〈 accounts。
length;
i++)
ﻩﻩ{//若存在账户
ﻩﻩif(accounts[i] !
=null)
ﻩﻩ{ﻩ
ﻩﻩ//写入账户信息到account.txt
ﻩbufWriter。
write(accounts[i].id+”,");
ﻩﻩﻩﻩbufWriter。
write(accounts[i]。
getPassword()+”,"
ﻩﻩﻩbufWriter.write(accounts[i].getName()+”,");
ﻩﻩﻩbufWriter。
write(accounts[i]。
getPersonId()+","
ﻩbufWriter。
write(accounts[i]。
getAccountType()+",”);
ﻩﻩﻩbufWriter.write(Double.toString(accounts[i]。
getBalance()));
ﻩbufWriter.newLine();
ﻩ}
ﻩﻩﻩelse
ﻩﻩ{
ﻩﻩbreak;
ﻩ}
ﻩﻩ}ﻩﻩﻩ
ﻩﻩbufWriter。
flush();
//清空缓存中的内容
}catch(IOExceptione){
// TODOAuto—generatedcatch block
ﻩe.printStackTrace();
}finally{
ﻩﻩtry{
ﻩif(bufWriter!
=null){
ﻩﻩﻩbufWriter。
close();
ﻩﻩ}
} catch(IOExceptione){
ﻩﻩ//TODOAuto-generated catchblock
ﻩﻩﻩe.printStackTrace();
}
ﻩ/**
*登录验证
public AccountverifyAccount(longid,String password){
ﻩAccount account=null;
ﻩ
ﻩﻩfor(inti=0;
i<
accounts.length;
i++)
{//若存在账户
ﻩﻩif(accounts[i]!
=null)
{ﻩ//验证id号和password
if(id == accounts[i]。
getId()&
&
password.equals(accounts[i].getPassword()))
ﻩﻩ{
ﻩﻩaccount = accounts[i];
ﻩﻩﻩbreak;
}
ﻩﻩﻩ}
ﻩﻩ{
ﻩﻩbreak;
ﻩﻩ}
ﻩreturn account;
/**
ﻩ *转账验证(方法的重载)
*/
publicAccountverifyAccount(longid){
Accountaccount=null;
ﻩﻩfor(inti=0;
i< accounts。
ﻩﻩ{//若存在账户
ﻩﻩﻩif(accounts[i]!
= null)
ﻩ{//验证id号和password
ﻩif(id==accounts[i]。
getId())
ﻩﻩ{
ﻩﻩﻩaccount=accounts[i];
ﻩﻩbreak;
ﻩﻩ}
ﻩ}
ﻩﻩelse
ﻩ{
ﻩbreak;
ﻩﻩﻩ}
ﻩreturnaccount;
ﻩ/**
ﻩ *转账
ﻩ */
publicvoidtransferAccount(Accountaccount1,Accountaccount2,double money){
ﻩﻩaccount1。
withdraw(money);
ﻩaccount2.deposit(money);
ﻩ*/
publicvoiddeposit(Accountaccount, doublemoney){
ﻩﻩaccount.deposit(money);
/**
ﻩ *取款
public voidwithdraw(Accountaccount,doublemoney){
account.withdraw(money);
ATM类
packagecom.qx;
import java.io.BufferedReader;
import java。
io.BufferedWriter;
importjava。
io.File;
importjava.io。
importjava.io.;
importjava。
util.Properties;
import java.util.Scanner;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- BAM 银行 账户 管理 系统 java