java银行存取款系统
时间: 2023-11-03 11:05:16 浏览: 85
很抱歉,由于我是一名AI语言模型,无法提供完整的Java银行存取款系统。但是,我可以给您一些示例代码,以帮助您了解Java语言的实现方式。以下是一个简单的Java银行存取款系统的示例代码:
```
import java.util.Scanner;
public class BankSystem {
private static double balance = 0.0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the Bank System!");
while (true) {
System.out.println("Please choose an action:");
System.out.println("1. Check balance");
System.out.println("2. Deposit money");
System.out.println("3. Withdraw money");
System.out.println("4. Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("Your current balance is " + balance);
break;
case 2:
System.out.println("Enter the amount you want to deposit:");
double depositAmount = scanner.nextDouble();
balance += depositAmount;
System.out.println("Deposit successful!");
break;
case 3:
System.out.println("Enter the amount you want to withdraw:");
double withdrawAmount = scanner.nextDouble();
if (withdrawAmount > balance) {
System.out.println("Insufficient balance!");
} else {
balance -= withdrawAmount;
System.out.println("Withdrawal successful!");
}
break;
case 4:
System.out.println("Goodbye!");
System.exit(0);
default:
System.out.println("Invalid choice!");
}
}
}
}
```
以上示例代码实现了一个简单的银行存取款系统,其中用户可以通过输入数字选择不同的操作,包括查看余额、存款、取款和退出系统。在运行程序时,用户可以根据提示输入相应的金额。该程序只是一个基本的示例,实际的银行系统需要更多的功能和安全措施来保护用户的财产。
阅读全文