import java.util.Scanner;
class Account {
private int[] id = new int[10];
private static double balance = 100;
Account(double balance) {
balance = 100;
}
public void getbalance() {
System.out.println(balance);
}
public void withdraw(double withdraw) {
System.out.println("your balance is " + (balance - withdraw));
}
public void deposit(double deposit) {
System.out.println("your balance is " + (balance + deposit));
}
public void menu() {
System.out.print("main menu\n" + "1: check balance\n" + ""
+ "2: withdraw\n" + "3: deposit\n" + "4: exit");
}
public void setId(int[] id) {
this.id = id;
}
public int[] getId() {
return id;
}
}
public class ATM_machine {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
do {
System.out.println("input your ID !");
int id = input.nextInt();
double money = 0;
Account account = new Account(id);
System.out.println("choice !");
account.menu();
int choice = input.nextInt();
if (choice == 2 || choice == 3) {
System.out.println("input the number of money !");
money = input.nextDouble();
}
switch (choice) {
case 1:
account.getbalance();
break;
case 2:
account.withdraw(money);
break;
case 3:
account.deposit(money);
break;
case 4:
account.menu();
break;
}
} while (true);
}
}
运行结果:
input your ID !
4
choice !
main menu
1: check balance
2: withdraw
3: deposit
4: exit
3
input the number of money !
10
your balance is 110.0
input your ID !