银行账户管理系统java报告,银行管理系统JAVA
本文实例为大家分享了爪哇实现银行账户管理子系统的具体代码,供大家参考,具体内容如下
所用到的知识点:面向对象基础语法,封装,方法覆盖(重写)、继承、多态
话不多说,直接上代码
Account.java
包com.task1导入Java。util。扫描仪;公共类别帐户{ //规定账户类型: //0 储蓄账户1 信用账户2 可贷款储蓄账户3 可贷款信用账户私有长id;//账户号码私有字符串密码;//账户密码私有字符串名称;//真实姓名私有字符串personId//身份证号码私人字符串电子邮件;//客户的电子邮箱私人双平衡;//账户余额私有int类型;//账户类型//无参的构造方法公共帐户(){ } //有参的构造方法公众账号(长id,字符串密码,字符串名称,字符串personId,字符串电子邮件,双余额,int类型){ super();this.id=idthis.password=密码;this . name=name this . personid=personid this . email=email this . balance=balance this . type=type }//get、set方法public Long getId(){ return id;} public void setId(long id){ this。id=id}公共字符串get password(){返回密码;} public void set password(字符串密码){ this。密码=密码;} public String getName(){ return name;} public void set name(String name){ this。name=名称;}公共字符串getPersonId(){ return personId;} public void set personId(String personId){ this。personId=personId}公共字符串getEmail() {返回邮件;} public void set email(String email){ this。email=email} public double get balance(){ return balance;} public void set balance(double balance){ this。余额=余额;} public int getType(){ return type;} public void setType(int type){ this。type=类型;} //存款对公账户存款(双钱){ this.balance=money//余额增加还这个;} //取款公共账户取款(double money){ if(balance-money=0){//判断余额是否足够余额-=钱;//余额减少//System.out.println(存款成功);} else { System.out.println(您的余额不足!);}还这个;} //重写到
String方法 @Override public String toString() { return "Account [id=" + id + ", password=" + password + ", name=" + name + ", personId=" + personId + ", email=" + email + ", balance=" + balance + ", type=" + type + "]"; } }SavingAccount.java
package com.task1;public class SavingAccount extends Account { public SavingAccount() { super(); // TODO Auto-generated constructor stub } public SavingAccount(long id, String password, String name, String personId, String email, double balance, int type) { super(id, password, name, personId, email, balance, type); // TODO Auto-generated constructor stub } @Override public String toString() { return "SavingAccount [getId()=" + getId() + ", getPassword()=" + getPassword() + ", getName()=" + getName() + ", getPersonId()=" + getPersonId() + ", getEmail()=" + getEmail() + ", getBalance()=" + getBalance() + ", getType()=" + getType() + "]"; }}
CreditAccpunt.java
package com.task1;public class CreditAccount extends Account{ private double ceiling; public CreditAccount() { super(); } public CreditAccount(long id, String password, String name, String personId, String email, double balance, int type,double ceiling) { super(id, password, name, personId, email, balance, type); this.ceiling = ceiling; } public double getCeiling() { return ceiling; } public void setCeiling(double ceiling) { this.ceiling = ceiling; } @Override public String toString() { return "CreditAccount [getCeiling()=" + getCeiling() + ", getId()=" + getId() + ", getPassword()=" + getPassword() + ", getName()=" + getName() + ", getPersonId()=" + getPersonId() + ", getEmail()=" + getEmail() + ", getBalance()=" + getBalance() + ", getType()=" + getType() + "]"; } @Override public Account withdraw(double money) { if(getBalance() >= money) { setBalance(getBalance() - money); }else if(getBalance() + getCeiling() >= money) { setCeiling(getCeiling()-(money-getBalance())); setBalance(0); }else { System.out.println("对不起,您的余额不足"); } return this; } }
Bank.java
package com.task1;import java.util.Scanner;public class Bank { int index = 0; //当前用户数量 Account [] accounts = new Account [100];//数据库 Account account = null; /* * 用户开户(register) 参数列表: Long 账号, String密码, String确认密码,String 姓名,String身份证号码,String邮箱,int 账户类型;(Long id, String password, String repassword, String name, String personID, String email, int type) 返回类型:Account 规定账户类型:0 – 储蓄账户 1 – 信用账户 2 – 可贷款储蓄账户 3– 可贷款信用账户 */ //用户开户 public Account register(Long id, String password, String repassword, String name, String personId, String email, int type) { if(password.equals(repassword)) { // 判断两次输入密码是否一致 switch (type) { //根据用户类型创建不同账户 case 0: account = new SavingAccount(id, repassword, name, personId, email, 0, type); //创建储蓄账户 break; case 1: account = new CreditAccount(id, repassword, name, personId, email, 0, type,1000); //创建信用账户 } accounts[index++] = account; //账户信息存到数据库,用户数量+1 }// else {// System.out.println("两次输入的密码不一致");// } return account; } //用户登录 public Account login(Long id, String password) { int find = searchIdPassword(index, id, password); //当前用户数组下标 if(find >= 0) { //判断账户密码是否正确// System.out.println("登录成功"); return accounts[find]; //返回当前对象 }// else {// System.out.println("用户名密码错误");// } return null; //如果账户密码错误返回空 } //用户存款 public Account deposit(Long id, double money) { int find = searchId(index, id);当前用户数组下标 if(find >= 0) { //判断账户是否存在 accounts[find].deposit(money); //调用Account类的存款方法// System.out.println("存款成功"); return accounts[find]; //返回当前对象// accounts[find].setBalance(accounts[find].getBalance()+money); }// else {// System.out.println("用户不存在");// } return null; //如果账户不存在返回空 } //用户取款 public Account withdraw(Long id, String password, double money) { int find = searchIdPassword(index, id, password);//当前用户数组下标 if(find >= 0) { //判断账户密码是否正确 accounts[find].withdraw(money); //调用当前对象的取款方法 // System.out.println("取款成功"); return accounts[find]; //返回当前对象 } return null; } //设置透支额度 public Account updateCeiling(Long id, String password, double money) { int find = searchIdPassword(index, id, password);//获取当前用户数组下标 if((find >= 0) && (accounts[find].getType()) == 1){ //判断账户号码和密码是否正确,账户类型是否为信用账户 ((CreditAccount)accounts[find]).setCeiling(((CreditAccount)accounts[find]).getCeiling() + money); //调用set方法设置透支额度 return accounts[find]; } return null; } // 转账功能 // 参数:from转出账户,passwordFrom 转出账号的密码,to转入账户,money转账的金额 public boolean transfer(Long from, String passwordFrom, Long to, double money) { int find = searchIdPassword(index, from, passwordFrom); //转账账户数组下标 int find2 = searchId(index, to); //收款账户数组下标 if(find >= 0 && find2 >= 0 && accounts[find].getBalance() >= money) { //判断转账账户密码、收款账户是否匹配,判断转账用户余额是否足够 accounts[find].withdraw(money);//转账用户转账操作==取款 accounts[find2].deposit(money);//收款用户 == 存款 return true; } return false; } //统计银行所有账户余额总数 public double balanceSum() { double sum = 0; //初始化所有账户余额 for(int i = 0; i < index; i++) { //遍历数组 sum += accounts[i].getBalance();//求和(账户余额) } return sum; } //统计所有信用账户透支额度总数 public double ceilingSum() { double sum = 0; //初始化所有透支额度和 for(int i = 0; i < index; i++) { //遍历 if(accounts[i].getType() == 1) { //判断账户类型是否为信用账户 sum += ((CreditAccount)accounts[i]).getCeiling(); //求和 } } return sum; } //搜索Id与密码返回数组下标位置 public int searchIdPassword(int index, Long id, String password) { for(int i = 0; i < index; i++) { if(id.equals(accounts[i].getId()) && password.equals(accounts[i].getPassword())){ //比较账户和密码是否匹配 return i ; //匹配则返回账户数组下标 } } return -1; //不匹配则返回-1 } //搜索Id public int searchId(int index, Long id) { for(int i = 0; i < index; i++) { if(id.equals(accounts[i].getId())){ //比较账户是否匹配 return i ; //匹配则返回账户数组下标 } } return -1; //不匹配则返回-1 }}
TestAccount.java
package com.task1;public class TestAccount { public static void main(String[] args) { Account a =new Account(123456L, "123456","张三", "421356", "tt@tt.com", 100.0, 0); System.out.println(a); }}
TestBank.java
package com.task1;import java.util.Scanner;public class TestBank { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Bank bank = new Bank(); String action =null; do { System.out.println("菜单:"); System.out.println("---[1.开户]---"); System.out.println("---[2.登录]---"); System.out.println("---[3.存款]---"); System.out.println("---[4.取款]---"); System.out.println("---[5.设置透支额度]---"); System.out.println("---[6.转账]---"); System.out.println("请选择服务"); int choice =sc.nextInt(); switch(choice) { case 1: //开户 &nbs
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。