银行管理系统java代码实现
时间: 2023-11-30 13:36:25 浏览: 87
非常抱歉,我是一名AI语言模型,无法提供完整的银行管理系统java代码实现。但是,我可以为您提供以下一些基本的代码框架和功能模块,供您参考:
1. 银行账户类(Account):
```java
public class Account {
private String accountNumber;
private double balance;
private String customerName;
private String email;
private String phoneNumber;
// 构造方法
public Account(String accountNumber, double balance, String customerName, String email, String phoneNumber) {
this.accountNumber = accountNumber;
this.balance = balance;
this.customerName = customerName;
this.email = email;
this.phoneNumber = phoneNumber;
}
// 存取器方法
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
// 存款方法
public void deposit(double amount) {
this.balance += amount;
System.out.println("存款成功,当前余额为:" + this.balance);
}
// 取款方法
public void withdraw(double amount) {
if (this.balance >= amount) {
this.balance -= amount;
System.out.println("取款成功,当前余额为:" + this.balance);
} else {
System.out.println("余额不足,取款失败!");
}
}
}
```
2. 银行客户类(Customer):
```java
public class Customer {
private String name;
private ArrayList<Account> accounts;
// 构造方法
public Customer(String name) {
this.name = name;
this.accounts = new ArrayList<Account>();
}
// 存取器方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Account> getAccounts() {
return accounts;
}
public void setAccounts(ArrayList<Account> accounts) {
this.accounts = accounts;
}
// 添加账户方法
public void addAccount(Account account) {
this.accounts.add(account);
System.out.println("账户添加成功!");
}
// 删除账户方法
public void removeAccount(Account account) {
if (accounts.contains(account)) {
accounts.remove(account);
System.out.println("账户删除成功!");
} else {
System.out.println("账户不存在,删除失败!");
}
}
// 查询账户列表方法
public void showAccounts() {
System.out.println("客户名:" + this.name);
System.out.println("账户列表:");
for (Account account : accounts) {
System.out.println(account.getAccountNumber());
}
}
}
```
3. 银行类(Bank):
```java
public class Bank {
private String name;
private ArrayList<Customer> customers;
// 构造方法
public Bank(String name) {
this.name = name;
this.customers = new ArrayList<Customer>();
}
// 存取器方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Customer> getCustomers() {
return customers;
}
public void setCustomers(ArrayList<Customer> customers) {
this.customers = customers;
}
// 添加客户方法
public void addCustomer(Customer customer) {
this.customers.add(customer);
System.out.println("客户添加成功!");
}
// 删除客户方法
public void removeCustomer(Customer customer) {
if (customers.contains(customer)) {
customers.remove(customer);
System.out.println("客户删除成功!");
} else {
System.out.println("客户不存在,删除失败!");
}
}
// 查询客户列表方法
public void showCustomers() {
System.out.println("银行名:" + this.name);
System.out.println("客户列表:");
for (Customer customer : customers) {
System.out.println(customer.getName());
}
}
}
```
4. 主程序(Main):
```java
public class Main {
public static void main(String[] args) {
Bank bank = new Bank("ABC Bank");
Customer customer1 = new Customer("张三");
Account account1 = new Account("001", 10000, "张三", "zhangsan@abc.com", "12345678901");
customer1.addAccount(account1);
bank.addCustomer(customer1);
Customer customer2 = new Customer("李四");
Account account2 = new Account("002", 20000, "李四", "lisi@abc.com", "12345678902");
customer2.addAccount(account2);
bank.addCustomer(customer2);
bank.showCustomers();
customer1.showAccounts();
customer2.showAccounts();
account1.deposit(5000);
account1.withdraw(8000);
}
}
```
以上代码仅为示例,实际开发中需要根据需求进行适当修改和完善。希望对您有所帮助!
阅读全文