Java模拟简易ATM机运行(无界面、无数据库)

这个Java程序模拟了一个无界面、无数据库连接的ATM机。用户通过控制台输入进行登录、密码验证、选择服务(如查询余额、取款、存款、转账等操作)。程序限制了每日取款和存款的总额度,以及连续错误输入的次数。
摘要由CSDN通过智能技术生成
package testATM;
/*
* code by Xu Xingrui
*/
public class Atm {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Operation o = new Operation();

		o.welcome();
		o.login();
		o.serviceAll();
	}

}

package testATM;

public class Services {

	private int t=0;//t记录密码输入错误次数及选择服务项目时的输入错误次数
	private String password;
	private int balance;
	private int depositAll;
	private int drawAll;
	public Services(){
		password="123456";
		balance=20000;
		depositAll=0;
		drawAll=0;
	}
	public int getT() {
		return t;
	}

	public void setT(int t) {
		this.t = t;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public int getBalance() {
		return balance;
	}
	public void setBalance(int balance) {
		this.balance = balance;
	}
	public int getDepositAll() {
		return depositAll;
	}
	public void setDepositAll(int depositAll) {
		this.depositAll = depositAll;
	}
	public int getDrawAll() {
		return drawAll;
	}
	public void setDrawAll(int drawAll) {
		this.drawAll = drawAll;
	}
	

}

package testATM;

import java.util.Scanner;

public class Operation {

	private int f = 0;

	Services ser;
	public Operation(){
		ser = new Services();
		
	}

	Scanner scan = new Scanner(System.in);
	
	public void login() {
//进入系统
		System.out.println("1、进入系统\t2、退出");
		int i1 = scan.nextInt();
		boolean flag = true;
		while (flag) {
			switch (i1) {
			case 1:
//				welcome();
				flag = false;
				break;
			case 2:
				rewelcome();
				System.exit(0);
			default:
				System.out.println("请重新输入:");
				i1 = scan.nextInt();
			}
		}
//输入密码及其验证
		System.out.println("请输入密码:");
		String pw = scan.next();
		while (ser.getT() < 2) {

			if (ser.getPassword().equals(pw)) 
  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值