下载地址(文章指定相关附件):www.pan38.com/dow/share.p… 提取密码:6465
分享源码是我们的自己,其实把已经把这个APP的源码给扒拉出来了,希望能帮助到大家哈,网上有开源的,但是开源的这些没有把纯源码给分享出来了,所以我们这边分享的是纯代码部分,希望能帮助到加,纯代码部分我们就不需要二次加工了,直接用就行了,代码也可以直接注入进去。
java开源部分的源码哈:
com.virtualbank.model; import java.util.ArrayList; import java.util.List; import java.util.UUID;
public class Account { private final String accountId; private String accountName; private double balance; private List transactions; private String password;
public Account(String name, String pwd) {
this.accountId = "VB" + UUID.randomUUID().toString().substring(0,8).toUpperCase();
this.accountName = name;
this.balance = 10000.00; // 初始余额
this.password = pwd;
this.transactions = new ArrayList<>();
recordTransaction("开户成功", 10000.00);
}
public synchronized boolean transferTo(Account target, double amount) {
if(amount <= 0 || this.balance < amount) return false;
this.balance -= amount;
target.balance += amount;
this.recordTransaction("转出至" + target.accountId, -amount);
target.recordTransaction("转入自" + this.accountId, amount);
return true;
}
private void recordTransaction(String memo, double amount) {
transactions.add(new Transaction(memo, amount, this.balance));
}
// Getter方法省略...
}
com.virtualbank.model;
import java.text.SimpleDateFormat; import java.util.Date;
public class Transaction { private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final String transactionId; private final String timestamp; private final String description; private final double amount; private final double balanceAfter;
public Transaction(String desc, double amt, double balance) {
this.transactionId = "T" + System.currentTimeMillis();
this.timestamp = sdf.format(new Date());
this.description = desc;
this.amount = amt;
this.balanceAfter = balance;
}
@Override
public String toString() {
return String.format("[%s] %-15s %+10.2f 余额: %10.2f",
timestamp, description, amount, balanceAfter);
}
}
com.virtualbank.model;
import java.text.SimpleDateFormat; import java.util.Date;
public class Transaction { private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final String transactionId; private final String timestamp; private final String description; private final double amount; private final double balanceAfter;
public Transaction(String desc, double amt, double balance) {
this.transactionId = "T" + System.currentTimeMillis();
this.timestamp = sdf.format(new Date());
this.description = desc;
this.amount = amt;
this.balanceAfter = balance;
}
@Override
public String toString() {
return String.format("[%s] %-15s %+10.2f 余额: %10.2f",
timestamp, description, amount, balanceAfter);
}
}
package com.virtualbank;
import com.virtualbank.service.BankService; import com.virtualbank.model.Account; import java.util.Scanner;
public class MainApp { public static void main(String[] args) { BankService bank = new BankService(); Scanner scanner = new Scanner(System.in);
System.out.println("=== 虚拟银行转账模拟器 ===");
Account acc1 = bank.createAccount("张三", "123456");
Account acc2 = bank.createAccount("李四", "654321");
while(true) {
System.out.println("\n1. 转账 2. 生成凭证 3. 退出");
int choice = scanner.nextInt();
switch(choice) {
case 1:
System.out.print("输入转账金额: ");
double amount = scanner.nextDouble();
if(acc1.transferTo(acc2, amount)) {
System.out.println("转账成功!");
System.out.println(bank.generateVirtualReceipt(
acc1.getAccountId(), acc2.getAccountId(), amount));
} else {
System.out.println("转账失败: 余额不足");
}
break;
case 3:
System.exit(0);
}
}
}
}