「java写atm」java写ATM模拟程序

博主:adminadmin 2022-12-16 06:36:08 54

本篇文章给大家谈谈java写atm,以及java写ATM模拟程序对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

Java编程实现程序用于模拟ATM取款机。

package demo;

import java.util.Scanner;

public class Test3 {

public static void main(String[] args) {

Scanner scanner =new Scanner(System.in);

int cnt=3;

String username = null;

String password = null;

double money = 1000;

String targetName = "admin33";

double targetMoney = 1000;

while(true){

if(username!=nullpassword!=null){

if("admin".equals(username) "123".equals(password)){

System.out.println("欢迎光临");

while(true){

System.out.println("请选择您的操作 1 取钱 2 存钱 3 转账 4 查询 5 退出 ");

int n = scanner.nextInt();

if(n==1){//取钱

System.out.println("请输入金额");

int getter = scanner.nextInt();

if(getter=0){

if(getter=5000){

if(getter=money){

money-=getter;

}else{

System.out.println("余额不足");

}

}else{

System.out.println("单笔只能取5000及以下");

}

}else{

System.out.println("银行不到给");

}

}else if(n==2){//存钱

System.out.println("请输入金额");

int save = scanner.nextInt();

if(save=0){

money+=save;

}

}else if(n==3){//转账

System.out.println("请输入目标账户");

String target = scanner.next();

if(target.equals(targetName)){

System.out.println("请输入金额");

int getter = scanner.nextInt();

if(getter=0){

if(getter=5000){

if(getter=money){

money-=getter;

targetMoney+=getter;

}else{

System.out.println("余额不足");

}

}else{

System.out.println("单笔只能取5000及以下");

}

}else{

System.out.println("银行不到给");

}

}

}else if(n==4){//查询

System.out.println(money);

}else if(n==5){//退出

System.exit(0);

}else{

System.out.println("没有该项服务");

}

}

}else{

cnt--;

System.out.println("输入错误,您还有"+cnt+"次机会");

username=null;

password=null;

if(cnt=0){

System.out.println("对不起,您的账号被冻结,请到最近的营业厅解除冻结");

System.exit(0);

}

}

}else{

System.out.println("请输入您的账号");

username = scanner.next();

System.out.println("请输入您的密码");

password = scanner.next();

}

}

}

}

atm机的java怎么写啊

package demo;

import java.io.*;

/*该类为实现客户信息及部分功能*/

class Account {

private String code =null; //信用卡号

private String name =null; //客户姓名

private String password=null; //客户密码

private double money =0.0; //卡里金额

/********************/

public Account(String code,String name,String password,double money)

{

this.code=code;

this.name=name;

this.password=password;

this.money=money;

}

protected String get_Code() {

return code;

}

protected String get_Name() {

return name;

}

protected String get_Password() {

return password;

}

public double get_Money() {

return money;

}

/*得到剩余的钱的数目*/

protected void set_Balance(double mon) {

money -= mon;

}

/*得到剩余的钱的数目*/

protected void set_Deposit(double mon) {

money += mon;

}

}

/**********实现具体取款机功能*********/

class ATM {

Account act;

// private String name;

// private String pwd;

public ATM() {

act=new Account("000000","Devil","123456",50000);

}

/***********欢迎界面***********/

protected void Welcome()

{

String str="---------------------------------";

System.out.print(str+"\n"+

"欢迎使用Angel模拟自动取款机程序.\n"+str+"\n");

System.out.print(" 1.取款."+"\n"+

" 2.存款."+"\n"+

" 3.查询信息."+"\n"+

" 4.密码设置."+"\n"+

" 5.退出系统."+"\n");

}

/**********登陆系统**********/

protected void Load_Sys() throws Exception

{

String card,pwd;

int counter=0;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

do {

System.out.println("请输入您的信用卡号:");

card=br.readLine();

System.out.println("请输入您的密码:");

pwd=br.readLine();

if(!isRight(card,pwd))

{

System.out.println("您的卡号或密码输入有误.");

counter++;

}

else

Welcome();

SysOpter();

}while(counter3);

Lock_Sys();

}

/**********系统操作**********/

protected void SysOpter() throws Exception

{

int num;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("请选择您要操作的项目(1-5):");

num=br.read(); //num为ASICC码转换的整数

switch(num) {

case 49: BetBalance(); break;

case 50: Deposit(); break;

case 51: Inqu_Info(); break;

case 52: Set_Password(); break;

case 53: Exit_Sys(); break;

}

System.exit(1);

}

/**********信息查询

* @throws Exception **********/

protected void Inqu_Info() throws Exception {

System.out.print("---------------------\n"+

act.get_Code()+"\n"+

act.get_Name()+"\n"+

act.get_Money()+"\n"+

"-----------------------");

Welcome();

SysOpter();

}

/**********取款**********/

public void BetBalance() throws Exception

{

String str=null,str1;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int count=0;//取款错误超过3次自动退出

do {

System.out.println("请输入您要取的数目:");

str=br.readLine();

str1=String.valueOf(act.get_Money());

System.out.println(str1);

if(Double.parseDouble(str)Double.parseDouble(str1)) {

count++;

System.out.println("超过已有的钱数,请重新输入您要取的数目:");

if(count=3){

System.out.println("超过已有的钱数,请重新输入您要取的数目:");

Exit_Sys();

}

}

else {

/*操作成功*/

act.set_Balance(Double.parseDouble(str));

System.out.println("取款成功,请收好您的钱.");

Welcome();

SysOpter();

}

}while(true);

}

/*******存款********/

public void Deposit() throws Exception{

String str=null;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

do {

System.out.println("请输入您要存的数目:");

str=br.readLine();

/*操作成功*/

act.set_Deposit(Double.parseDouble(str));

System.out.println("取款成功,请收好您的钱.");

Welcome();

SysOpter();

}while(true);

}

/**********判断卡内是否有钱**********/

protected boolean isBalance() {

if(act.get_Money()0) {

System.out.println("对不起,您的钱数不够或卡已透支.");

return false;

}

return true;

}

/********卡号密码是否正确******/

protected boolean isRight(String card,String pwd)

{

if(act.get_Code().equals(card) act.get_Password().equals(pwd))

return true;

else

return false;

}

/**********密码修改**********/

protected void Set_Password() throws Exception

{

String pwd=null;

int counter=0;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

do {

System.out.println("请输入旧密码:");

pwd=br.readLine();

if(act.get_Password().equals(pwd))

{

do {

System.out.println("请输入新密码:");

String pwd1=br.readLine();

System.out.println("请再次输入新密码:");

String pwd2=br.readLine();

if(!pwd1.equals(pwd2))

{

System.out.println("两次输入不一致,请再次输入.");

}

else

{

System.out.println("密码修改成功,请使用新密码.");

Welcome();

SysOpter();

}

}while(true);

}

}while(counter3);

}

/**********锁定机器**********/

protected void Lock_Sys() {

System.out.println("对不起,您的操作有误,卡已被没收.");

System.exit(1);

}

/**********结束系统**********/

protected void Exit_Sys() {

System.out.println("感谢您使用本系统,欢迎下次在来,再见!");

System.exit(1);

}

}

public class Text

{

public static void main(String[] args) throws Exception

{

ATM atm=new ATM();

atm.Load_Sys();

// atm.Exit_Sys();

}

}

卡号:00000 密码123456 默认50000金额。简单版本的存取款。

ATM java

import java.util.Scanner;

public class Atm{

public static void main(String [] args){

Scanner input=new Scanner(System.in);

int a,b=0,c=0,d,e,f,g,h,i,j,k,l,m=10000,n=10000;

for(i=0;i3;i++){

System.out.print("请输入帐户"+" ");

a=input.nextInt();

System.out.print("请输入密码"+" ");

d=input.nextInt();

if(a==123456d==654321){System.out.println("输入成功");

break;}

else{System.out.println("输入密码或帐户错误");}

if(i==2){System.out.println("三次错误吞卡!!报警。你别跑");}

}

while(i3){

System.out.print("请输入你的操作:1:查询 2:取钱"+" ");

a=input.nextInt();

if(a==1){System.out.print("请输入你的帐户类型:1:美圆 2:人民币"+" ");

a=input.nextInt();

if(a==1){System.out.println("你还有"+(m=m-b)+"美圆");

System.out.print("请输入你的操作:1:继续2:离开"+" ");

a=input.nextInt();

if(a==1){continue;}

else{break;}

}

else{System.out.println("你还有"+(n=n-c)+"人民币");

System.out.print("请输入你的操作:1:继续2:离开"+" ");

a=input.nextInt();

if(a==1){continue;}

else{break;}

}

}

else{System.out.print("请输入你取钱的帐户类型:1:美圆 2:人民币"+" ");

a=input.nextInt();

if(a==1){while(true){System.out.print("请输入你取钱的金额(美圆):"+" ");

b=input.nextInt();

if(b=m){System.out.println("取钱成功!请妥善保管好你的钱");break;}

else{System.out.println("您的账户余额不足。请重新输入"+" ");continue;}}

System.out.print("请输入你的操作:1:继续2:离开"+" ");

a=input.nextInt();

if(a==1){continue;}

else{break;}

}

else{while(true){System.out.print("请输入你取钱的金额(人民币):"+" ");

c=input.nextInt();

if(c=n){System.out.println("取钱成功!请妥善保管好你的钱");break;}

else{System.out.println("您的账户余额不足。请重新输入"+" ");continue;}}

System.out.print("请输入你的操作:1:继续2:离开"+" ");

a=input.nextInt();

if(a==1){continue;}

else{break;}

}

}

}

}

}

你看看 我不明白你说的条件是什么意识

java如何用list map集合写ATM系统

你首先要了解什么是Map,可以理解为Map是一堆key和value的映射集合(或者说一堆键值对的集合)。 List list = new ArrayList(); Map map = new HashMap(); list.add("a"); list.add("c"); list.add("b"); for(int i =0;ilist.size();i++){ map.put(i, list.get(i));   } 然后你要用Map里的东西,可以使用map.get(依)这种形式获取,他和list.get(依); 相等都为“c”。 另外建议初始化Map和List的时候,定义好所存的数据类型。 List list = new ArrayList(); Map map = new HashMap()

求高手用JAVA编写一个模拟ATM机取款业务需求如下:

楼主您好,编码如下,直接运行即可:

import java.util.Scanner;

public class AtmGetMoney {

public static void main(String[] args) {

String password = "111111";

int count = 0;

int a = 0;

while(count3){

System.out.println("请输入银行卡密码: ");

Scanner scan = new Scanner(System.in);

String passwd = scan.nextLine();

while(passwd.equals(password)){

System.out.println("请输入取款金额: ");

int amount = scan.nextInt();

if(amount%100 == 0 amount = 1000){

System.out.println("您的取款金额为: "+amount);

System.out.println("交易完成,请读卡!");

a = a + 1;

break;

}

else {

System.out.println("只能提取100元纸币,要求最低0,最高1000!");

continue;

}

}

if (a == 1){

break;

}

else if (count 2) {

System.out.println("银行卡密码错误");

count = count + 1;

continue;

}

else {

System.out.println("密码错误请读卡");

break;

}

}

}

}

关于java写atm和java写ATM模拟程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-16,除非注明,否则均为首码项目网原创文章,转载请注明出处。