概述
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 menun" + "1: check balancen" + ""
+ "2: withdrawn" + "3: depositn" + "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 !
最后
以上就是健忘短靴为你收集整理的java atm程序_JAVA版ATM(自动取款机)的实现的全部内容,希望文章能够帮你解决java atm程序_JAVA版ATM(自动取款机)的实现所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复