我是靠谱客的博主 健忘短靴,最近开发中收集的这篇文章主要介绍java atm程序_JAVA版ATM(自动取款机)的实现,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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(自动取款机)的实现所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部