网站首页 > 文章中心 > 其它

银行转账系统java代码

作者:小编 更新时间:2023-09-06 20:16:48 浏览量:248人看过

java银行系统代码 如何实现转账

①.、设置断点

=============================

作用域 功能 快捷键

全局 调试上次启动 F11

全局 添加/去除断点 Ctrl+Shift+B

全局 显示 Ctrl+D

全局 运行上次启动 Ctrl+F11

银行转账系统java代码-图1

全局 运行至行 Ctrl+R

全局 执行 Ctrl+U

用Java实现ATM的转账,取款,改密码,查询功能, 要代码!

银行转账系统java代码-图2

import javax.swing.JOptionPane;

public class Account

{

private String name;

private String account;

private String data;

private String ID;

private double balance;

public Account(String name,double balance,String data,String ID)

this.name = name;

this.balance = balance;

this.data=data;

this.ID=ID;

}

public String getaccount()

this.account=String.valueOf((int)(Math.random()*100000)+1);

return account;

public String getdata()

return data;

public String getID()

return ID;

public String getName()

return name;

public double getbalance()

return balance;

//查看账户余额

public double balance()

//查看开户时间

public String data()

//存款操作

public boolean put(double value)

if (value0)

this.balance += value;

return true;

return false;

//取款操作

public double get(double value)

if (value=this.balance)

this.balance -= value;

else

value = this.balance;

this.balance = 0;

return value;

return 0;

public static void main(String args[]){

String str;

int b;

int x=Integer.parseInt(s);

while(x!=0){

if(x==1)

str=JOptionPane.showInputDialog("输入您要存入的数额");

b=Integer.parseInt(str);

if( user.put(b)){

JOptionPane.showMessageDialog(null, "请放入钞票!");

JOptionPane.showMessageDialog(null,"开户账号为"+user.getaccount()+"\n"+user.getName()+"\n开户时间为"+user.data()+"\n您的余额为"+user.balance());

JOptionPane.showMessageDialog(null, "你所输入的存款数额有误!");

else{

str=JOptionPane.showInputDialog("输入您要取出的数额");

if(buser.balance())

JOptionPane.showMessageDialog(null, "余额不足");

JOptionPane.showMessageDialog(null, "请取出钞票!");

user.get(b);

x=Integer.parseInt(s);

如何用Java代码编写银行转账

public interface ITransfer{ /* * 银行内部转账,从转出账号中扣除转账金额,给转入账号增加转账金额,需要保证以上两个操作 * 要么同时成功,要么同时失败 * fromAccountId 转出账号 * outAccountId 转入账号 * amount 转账金额 */ public void transferInner(String fromAccountId,String outAccountId,BigDecimal amount); /* * 外部转账-转出,从转出账号中扣除转账金额 * fromAccoutnId 转出账号 * amount 转账金额 */ public void transferOut(String fromAccountId,String outAccountId,BigDecimal amount); /* * 外部转账-转入,从转入账号中增加转账金额 * toAccoutnId 转出账号 * amount 转账金额 */ public void transerIn(String toAccountId,BigDecimal amount); } public interface ITransfer{ /* * 银行内部转账,从转出账号中扣除转账金额,给转入账号增加转账金额,需要保证以上两个操作 * 要么同时成功,要么同时失败 * fromAccountId 转出账号 * outAccountId 转入账号 * amount 转账金额 */ public void transferInner(String fromAccountId,String outAccountId,BigDecimal amount); /* * 外部转账-转出,从转出账号中扣除转账金额 * fromAccoutnId 转出账号 * amount 转账金额 */ public void transferOut(String fromAccountId,String outAccountId,BigDecimal amount); /* * 外部转账-转入,从转入账号中增加转账金额 * toAccoutnId 转出账号 * amount 转账金额 */ public void transerIn(String toAccountId,BigDecimal amount); }

用java语言编写一个小型的银行系统代码

private?int?balance?=?0;

private?String?username?=?"A";

private?String?password?=?"B";

public?void?bank()?{

Scanner?scan?=?new?Scanner(System.in);

String?temp;

while?(true)?{

System.out.println("输入账号:");

if?(scan.hasNext())?{

temp?=?scan.next();

if?(temp.equals(username))?{

break;

}?else?{

System.out.println("输入错误");

System.out.println("输入密码:");

if?(temp.equals(password))?{

System.out.println("登录成功");

System.out.println("输入操作:");

switch?(temp)?{

case?"存款":

int?x?=?0;

System.out.println("输入存款金额:");

if?(scan.hasNextInt())?{

x?=?scan.nextInt();

scan.next();

balance?+=?x;

case?"取款":

int?y?=?0;

System.out.println("输入取款金额:");

y?=?scan.nextInt();

if?(balance?y)?{

System.out.println("余额不足");

continue;

balance?-=?y;

case?"余额":

System.out.println("余额:"?+?balance);

case?"终止":

System.exit(0);

default:

System.out.println("未知操作");

JAVA 简单银行系统的代码

import java.io.BufferedReader;

银行转账系统java代码-图3

import java.io.IOException;

import java.io.InputStreamReader;

public class AccountDemo {

public static double MONEY = 0;// 初始化金额是100元.

public static void main(String[] args) {

final String USER_NAME = "zhangsan";// 用户名

while (true) {

System.out.print("请输入用户名:");

String user_name = getString();

System.out.print("请输入密码:");

String password = getString();

if (user_name != null user_name.equals(USER_NAME)

password != null password.equals(PASSWORD)) {

System.out.println("登陆成功!你要干什么?");

System.out.println("1:存款");

System.out.println("q:退出程序");

System.out.print("请选择:");

String userIn = getString();

int in = 0;

if (userIn != null userIn.equals("1")) {

in = Integer.parseInt(userIn);

} else if (userIn != null

userIn.trim().toUpperCase().equals("Q")) {

} else {

System.out.println("你输入的指令不正确!请重新输入.");

switch (in) {

case 1:

double add_money = 0;

System.out.print("请输入你要存入的金额:");

try {

add_money = Double.parseDouble(getString());

} catch (Exception e) {

System.out.println("金额输入不正确!");

MONEY += add_money;

System.out.println("存入的金额是" + add_money

+ "\r\n请选择你要的操作:");

double money = 0;

System.out.print("请输入你要取出的金额:");

money = Double.parseDouble(getString());

if (money MONEY) {

System.out.println("取出的金额大于现有存款,请重新输入要取出的金额!");

MONEY -= money;

System.out.println("取出的金额是" + money + "\r\n请选择你要的操作:");

System.out.println("你的余额是:" + MONEY + "\r\n请选择你要的操作:");

System.out.println("程序退出!");

return;

System.out.println("错误:用户名与密码不匹配!\r\n");

System.out.println("按任意键:重新输入用户名和密码.");

System.out.println("q:退出程序.");

System.out.print("请选择:");

String in = getString();

if (in.trim().toUpperCase().equals("Q")) {

public static String getString() {

String str = null;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

str = br.readLine();

} catch (IOException e) {

e.printStackTrace();

return str;

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章