public class Account {
private int id;
private double balance = 100;
public Account(int id, double money) {
this.id = id;
this.balance = money;
}
public double getBalance() {
return balance;
}
public void withDraw(double value) {
balance = balance - value;
}
public void deposit(double value) {
balance = balance + value;
}
public int getId (){
return id;
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Account[] accounts = new Account[10];
for (int i=0;i<10;i++){
accounts[i]=new Account(i,100);
}
while (true) {
System.out.print("Enter the id: ");
Scanner input = new Scanner(System.in);
int in = input.nextInt();
if (in < 0 || in > 9) {
System.out.println("ERROR ID");
continue;
}
Account account = accounts[in];
System.out.println(account.getId());
boolean stop = false;
while (!stop) {
System.out.println("\nMain menu");
System.out.printf("%-15s\n%-15s\n%-15s\n%-15s\n", "1: check balance", "2: withdraw", "3: deposit", "4: exit");
System.out.print("Enter a choice: ");
switch (input.nextInt()) {
case 1:
System.out.println("The balance is " + account.getBalance());
break;
case 2:
System.out.print("Enter an amount to withdraw: ");
account.withDraw(input.nextDouble());
break;
case 3:
System.out.print("Enter an amount to deposit: ");
account.deposit(input.nextDouble());
break;
default:
stop = true;
}
}
}
}
}
"D:\java 12.0\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\lib\idea_rt.jar=56657:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\26601\Desktop\library_management_sys-master\untitled10\out\production\untitled10 Test
Enter the id: 2
2
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 100.0
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 2
Enter an amount to withdraw: 10
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 90.0
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice:
ATM机
最新推荐文章于 2025-03-19 19:55:12 发布
本文详细探讨了ATM(自动取款机)的工作原理,包括其硬件组成部分、软件系统、安全机制以及与银行系统的交互流程。同时,还讨论了现代ATM机中采用的最新技术,如生物识别和移动支付集成。
1061

被折叠的 条评论
为什么被折叠?



