java银行系统包括开户,存款,取款,转账,查询,修改密码,销户
时间: 2023-11-25 11:38:54 浏览: 99
是的,Java银行系统确实包括这些常见的功能。以下是对这些功能的简要说明:
- 开户:为客户创建银行账户并记录其个人信息。
- 存款:将现金或支票存入客户的银行账户。
- 取款:从客户的银行账户中取出现金。
- 转账:将客户账户中的资金转移到另一个账户中。
- 查询:查询客户的账户余额或交易记录。
- 修改密码:让客户更改其银行账户的密码。
- 销户:关闭客户的银行账户。
Java银行系统还可能包括其他功能,例如计算利息、生成报表等。这些功能可以根据具体的需求进行添加和定制。
相关问题
java银行系统包括开户,存款,取款,转账,查询,修改密码,销户代码
以下是一个简单的 Java 银行系统的代码实现,包括开户,存款,取款,转账,查询,修改密码,销户功能。
```java
import java.util.ArrayList;
import java.util.Scanner;
public class BankSystem {
static Scanner scanner = new Scanner(System.in);
static ArrayList<Account> accounts = new ArrayList<>();
public static void main(String[] args) {
while (true) {
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("7. 销户");
System.out.println("8. 退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
newAccount();
break;
case 2:
deposit();
break;
case 3:
withdraw();
break;
case 4:
transfer();
break;
case 5:
query();
break;
case 6:
changePassword();
break;
case 7:
deleteAccount();
break;
case 8:
return;
default:
System.out.println("输入错误,请重新输入");
break;
}
}
}
// 开户
static void newAccount() {
System.out.println("请输入账号:");
String account = scanner.next();
System.out.println("请输入密码:");
String password = scanner.next();
System.out.println("请输入初始存款金额:");
double balance = scanner.nextDouble();
accounts.add(new Account(account, password, balance));
System.out.println("开户成功");
}
// 存款
static void deposit() {
System.out.println("请输入账号:");
String account = scanner.next();
System.out.println("请输入密码:");
String password = scanner.next();
Account acc = getAccount(account, password);
if (acc != null) {
System.out.println("请输入存款金额:");
double amount = scanner.nextDouble();
acc.deposit(amount);
System.out.println("存款成功");
}
}
// 取款
static void withdraw() {
System.out.println("请输入账号:");
String account = scanner.next();
System.out.println("请输入密码:");
String password = scanner.next();
Account acc = getAccount(account, password);
if (acc != null) {
System.out.println("请输入取款金额:");
double amount = scanner.nextDouble();
if (acc.withdraw(amount)) {
System.out.println("取款成功");
} else {
System.out.println("余额不足,取款失败");
}
}
}
// 转账
static void transfer() {
System.out.println("请输入源账号:");
String account1 = scanner.next();
System.out.println("请输入密码:");
String password1 = scanner.next();
Account acc1 = getAccount(account1, password1);
if (acc1 == null) {
return;
}
System.out.println("请输入目标账号:");
String account2 = scanner.next();
Account acc2 = getAccount(account2);
if (acc2 == null) {
return;
}
System.out.println("请输入转账金额:");
double amount = scanner.nextDouble();
if (acc1.withdraw(amount)) {
acc2.deposit(amount);
System.out.println("转账成功");
} else {
System.out.println("余额不足,转账失败");
}
}
// 查询
static void query() {
System.out.println("请输入账号:");
String account = scanner.next();
System.out.println("请输入密码:");
String password = scanner.next();
Account acc = getAccount(account, password);
if (acc != null) {
System.out.println("余额:" + acc.getBalance());
}
}
// 修改密码
static void changePassword() {
System.out.println("请输入账号:");
String account = scanner.next();
System.out.println("请输入旧密码:");
String oldPassword = scanner.next();
Account acc = getAccount(account, oldPassword);
if (acc != null) {
System.out.println("请输入新密码:");
String newPassword = scanner.next();
acc.setPassword(newPassword);
System.out.println("修改密码成功");
}
}
// 销户
static void deleteAccount() {
System.out.println("请输入账号:");
String account = scanner.next();
System.out.println("请输入密码:");
String password = scanner.next();
Account acc = getAccount(account, password);
if (acc != null) {
accounts.remove(acc);
System.out.println("销户成功");
}
}
// 根据账号和密码查找账户
static Account getAccount(String account, String password) {
for (Account acc : accounts) {
if (acc.getAccount().equals(account) && acc.getPassword().equals(password)) {
return acc;
}
}
System.out.println("账号或密码错误");
return null;
}
// 根据账号查找账户
static Account getAccount(String account) {
for (Account acc : accounts) {
if (acc.getAccount().equals(account)) {
return acc;
}
}
System.out.println("账号不存在");
return null;
}
}
// 账户类
class Account {
private String account;
private String password;
private double balance;
public Account(String account, String password, double balance) {
this.account = account;
this.password = password;
this.balance = balance;
}
public String getAccount() {
return account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public double getBalance() {
return balance;
}
public void deposit(double amount) {
balance += amount;
}
public boolean withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
return true;
} else {
return false;
}
}
}
```
使用java语言,设计一个银行账户挂历系统,具体功能为:开户、存款、取款、转账、查询、修改密码、销户
好的,下面是一个简单的银行账户管理系统的Java代码实现,主要包括如下功能:
1. 开户
2. 存款
3. 取款
4. 转账
5. 查询
6. 修改密码
7. 销户
```java
import java.util.ArrayList;
import java.util.Scanner;
public class BankAccountSystem {
// 定义一个内部类,用于表示银行账户
private static class Account {
private String name; // 账户名
private String password; // 账户密码
private double balance; // 账户余额
public Account(String name, String password, double balance) {
this.name = name;
this.password = password;
this.balance = balance;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
}
private ArrayList<Account> accountList; // 银行账户列表
public BankAccountSystem() {
accountList = new ArrayList<>();
}
// 开户
public void openAccount() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入账户名:");
String name = scanner.nextLine();
System.out.print("请输入密码:");
String password = scanner.nextLine();
System.out.print("请输入初始存款金额:");
double balance = scanner.nextDouble();
Account account = new Account(name, password, balance);
accountList.add(account);
System.out.println("开户成功!");
}
// 存款
public void deposit() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入账户名:");
String name = scanner.nextLine();
System.out.print("请输入密码:");
String password = scanner.nextLine();
System.out.print("请输入存款金额:");
double amount = scanner.nextDouble();
Account account = findAccount(name, password);
if (account != null) {
account.setBalance(account.getBalance() + amount);
System.out.println("存款成功!");
System.out.println("当前余额为:" + account.getBalance());
} else {
System.out.println("账户名或密码错误!");
}
}
// 取款
public void withdraw() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入账户名:");
String name = scanner.nextLine();
System.out.print("请输入密码:");
String password = scanner.nextLine();
System.out.print("请输入取款金额:");
double amount = scanner.nextDouble();
Account account = findAccount(name, password);
if (account != null) {
if (amount <= account.getBalance()) {
account.setBalance(account.getBalance() - amount);
System.out.println("取款成功!");
System.out.println("当前余额为:" + account.getBalance());
} else {
System.out.println("余额不足!");
}
} else {
System.out.println("账户名或密码错误!");
}
}
// 转账
public void transfer() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入转出账户名:");
String name1 = scanner.nextLine();
System.out.print("请输入转出账户密码:");
String password1 = scanner.nextLine();
System.out.print("请输入转入账户名:");
String name2 = scanner.nextLine();
System.out.print("请输入转账金额:");
double amount = scanner.nextDouble();
Account account1 = findAccount(name1, password1);
Account account2 = findAccount(name2);
if (account1 != null && account2 != null) {
if (amount <= account1.getBalance()) {
account1.setBalance(account1.getBalance() - amount);
account2.setBalance(account2.getBalance() + amount);
System.out.println("转账成功!");
System.out.println(account1.getName() + "当前余额为:" + account1.getBalance());
System.out.println(account2.getName() + "当前余额为:" + account2.getBalance());
} else {
System.out.println("余额不足!");
}
} else {
System.out.println("账户名或密码错误!");
}
}
// 查询
public void query() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入账户名:");
String name = scanner.nextLine();
System.out.print("请输入密码:");
String password = scanner.nextLine();
Account account = findAccount(name, password);
if (account != null) {
System.out.println("账户名:" + account.getName());
System.out.println("当前余额为:" + account.getBalance());
} else {
System.out.println("账户名或密码错误!");
}
}
// 修改密码
public void changePassword() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入账户名:");
String name = scanner.nextLine();
System.out.print("请输入原密码:");
String oldPassword = scanner.nextLine();
System.out.print("请输入新密码:");
String newPassword = scanner.nextLine();
Account account = findAccount(name, oldPassword);
if (account != null) {
account.password = newPassword;
System.out.println("密码修改成功!");
} else {
System.out.println("账户名或密码错误!");
}
}
// 销户
public void closeAccount() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入账户名:");
String name = scanner.nextLine();
System.out.print("请输入密码:");
String password = scanner.nextLine();
Account account = findAccount(name, password);
if (account != null) {
accountList.remove(account);
System.out.println("销户成功!");
} else {
System.out.println("账户名或密码错误!");
}
}
// 根据账户名和密码查找账户
private Account findAccount(String name, String password) {
for (Account account : accountList) {
if (account.getName().equals(name) && account.getPassword().equals(password)) {
return account;
}
}
return null;
}
// 根据账户名查找账户
private Account findAccount(String name) {
for (Account account : accountList) {
if (account.getName().equals(name)) {
return account;
}
}
return null;
}
// 启动银行账户管理系统
public void start() {
Scanner scanner = new Scanner(System.in);
while (true) {
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("7. 销户");
System.out.println("0. 退出");
System.out.print("请选择操作:");
int choice = scanner.nextInt();
switch (choice) {
case 1:
openAccount();
break;
case 2:
deposit();
break;
case 3:
withdraw();
break;
case 4:
transfer();
break;
case 5:
query();
break;
case 6:
changePassword();
break;
case 7:
closeAccount();
break;
case 0:
System.out.println("谢谢使用!");
System.exit(0);
default:
System.out.println("无效操作!");
}
System.out.println();
}
}
public static void main(String[] args) {
BankAccountSystem bankAccountSystem = new BankAccountSystem();
bankAccountSystem.start();
}
}
```
阅读全文