我现写的: import javautilScanner;public class ATM {
private static String theName = "admin";
private static String thePassword = "123456";
private static int balance = 10000;
public static void getBalance(){
Systemoutprintln("当前余额:" + balance);
}
public static void drawMoney(Scanner sc){
int money = 0;
Systemoutprintln("请输入取款金额:");
money = scnextInt();
String type = "";
if (balance > 0) {
if (balance >= money) {
if (money <= 5000) {
balance = balance - money;
type = "请在30秒内提取现金\n剩余余额:"+balance;
} else if (money <= 0) {
type = "金额错误";
} else {
type = "超出最大限制金额";
}
} else {
type = "超出最大余额";
}
} else {
type = "余额不足";
}
Systemoutprintln(type);
}
public static void bankMoney(Scanner sc){
int money = 0;
Systemoutprintln("请输入存储金额:");
money = scnextInt();
String type = "";
if (money > 0) {
balance = balance + money;
type = "存储成功,现有余额:" + balance;
} else {
type = "存储金额不能为负";
}
Systemoutprintln(type);
}
public static void updatePass(Scanner sc){
String oldPass = "";
String newPass1 = "";
String newPass2 = "";
while(true){
Systemoutprintln("请输入原密码:");
oldPass = scnext();
if (oldPassequals(thePassword)) {
break;
} else {
Systemoutprintln("密码错误,请重新输入");
}
}
while(true){
Systemoutprintln("请输入新密码");
newPass1 = scnext();
Systemoutprintln("再次输入");
newPass2 = scnext();
if (newPass1equals(newPass2)) {
if (!isSame(newPass1)) {
thePassword = newPass1;
Systemoutprintln("修改成功");
break;
} else {
Systemoutprintln("所有字符不能相同,重新输入");
}
} else {
Systemoutprintln("两次输入不一致,重新输入");
}
}
}
public static boolean isSame(String string){
boolean bool = false;
for (int i = 0; i < stringlength() - 1; i++) {
char char1 = stringcharAt(i);
for (int j = i + 1; j < stringlength(); j++) {
char char2 = stringcharAt(j);
if (char1 == char2) {
bool = true;
break;
}
}
}
return bool;
}
public static void main(String[] args) {
Scanner sc = new Scanner(Systemin);
while(true){
String name = "";
String password = "";
Systemoutprintln("请输入账号:");
name = scnext();
Systemoutprintln("请输入密码:");
password = scnext();
if (nameequals(theName) && passwordequals(thePassword)) {
break;
} else {
Systemoutprintln("账号或密码错误,请重新输入!");
}
}
while(true){
int operate = 0;
Systemoutprintln("请选择你要进行的 *** 作:\n1、查询 2、取款 3、存款 4、修改密码 0、退出");
operate = scnextInt();
if (0 == operate) {
Systemoutprintln("谢谢使用!");
break;
} else if (1 == operate) {
getBalance();
} else if (2 == operate) {
drawMoney(sc);
} else if (3 == operate) {
bankMoney(sc);
} else if (4 == operate) {
updatePass(sc);
}
}
}
}
Java编写的模拟ATM取款机程序/ @version 10
@author Devil_Angel
该程序的功能为实现模拟银行ATM自动取款机提款,查询等功能
/import javaio;/该类为实现客户信息及部分功能/
class Account {
private String code =null; //xyk号
private String name =null; //客户姓名
private String password=null; //客户密码
private double money =00; //卡里金额
//
public Account(String code,String name,String password,double money)
{
thiscode=code;
thisname=name;
thispassword=password;
thismoney=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;
}
}/实现具体取款机功能/
class ATM {
Account act;
// private String name;
// private String pwd;
public ATM() {
act=new Account("000000","Devil","123456",50000);
}
/欢迎界面/
protected void Welcome()
{
String str="---------------------------------";
Systemoutprint(str+"\n"+
"欢迎使用Angel模拟自动取款机程序\n"+str+"\n");
Systemoutprint(" 1>取款"+"\n"+
" 2>查询信息"+"\n"+
" 3>密码设置"+"\n"+
" 4>退出系统"+"\n");
}
/登陆系统/
protected void Load_Sys() throws Exception
{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(Systemin));
do {
Systemoutprintln("请输入您的xyk号:");
card=brreadLine();
Systemoutprintln("请输入您的密码:");
pwd=brreadLine();
if(!isRight(card,pwd))
{
Systemoutprintln("您的卡号或密码输入有误");
counter++;
}
else
SysOpter();
}while(counter<3);
Lock_Sys();
}
/系统 *** 作/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(Systemin));
Systemoutprintln("请选择您要 *** 作的项目(1-4):");
num=brread(); //num为ASICC码转换的整数
switch(num) {
case 49: BetBalance(); break;
case 50: Inqu_Info(); break;
case 51: Set_Password(); break;
case 52: Exit_Sys(); break;
}
Systemexit(1);
}
/信息查询/
protected void Inqu_Info() {
Systemoutprint("---------------------\n"+
actget_Code()+"\n"+
actget_Name()+"\n"+
actget_Money()+"\n"+
"-----------------------");
}
/取款/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(Systemin));
do {
Systemoutprintln("请输入您要取的数目:");
str=brreadLine();
str1=StringvalueOf(actget_Money());
if(strcompareTo(str1)>0) {
Systemoutprintln("超过已有的钱数,请重新输入您要取的数目:");
}
else {
/ *** 作成功/
// actset_Balance(str);
Systemoutprintln("取款成功,请收好您的钱");
Welcome();
SysOpter();
}
}while(true);
}
/判断卡内是否有钱/
protected boolean isBalance() {
if(actget_Money()<0) {
// Systemoutprintln("对不起,您的钱数不够或卡已透支");
return false;
}
return true;
}
/卡号密码是否正确/
protected boolean isRight(String card,String pwd)
{
if(actget_Code()equals(card) && actget_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(Systemin));
do {
Systemoutprintln("请输入旧密码:");
pwd=brreadLine();
if(actget_Password()equals(pwd))
{
do {
Systemoutprintln("请输入新密码:");
String pwd1=brreadLine();
Systemoutprintln("请再次输入新密码:");
String pwd2=brreadLine();
if(!pwd1equals(pwd2))
{
Systemoutprintln("两次输入不一致,请再次输入");
}
else
{
Systemoutprintln("密码修改成功,请使用新密码");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter>3);
}
/锁定机器/
protected void Lock_Sys() {
Systemoutprintln("对不起,您的 *** 作有误,卡已被没收");
Systemexit(1);
}
/结束系统/
protected void Exit_Sys() {
Systemoutprintln("感谢您使用本系统,欢迎下次在来,再见!");
Systemexit(1);
}
}public class Text
{
public static void main(String[] args) throws Exception
{
ATM atm=new ATM();
atmWelcome();
atmLoad_Sys();
// atmExit_Sys();
}
} //模拟ATM取款机工作流程 import javautilScanner;public class Atm {
public Atm() {
}
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(Systemin);
int password = 0;
int count = 0;
int choice = 0;
int type = 0;
int input = 0;
int acount = 1000;
boolean exit = false;
int flag = 0;
do{
Systemoutprintln("请输入您的密码:");
password = scnextInt();
count++;
}while(password != 12345 && count<3);
if(password == 12345){
//密码正确继续后面的 *** 作。
do{
Systemoutprintln("请选择您的 *** 作,1查询 2取款");
choice = scnextInt();
switch(choice){
case 1:
do{
Systemoutprintln("请选择帐户类型:1 美元 2 人民币");
type = scnextInt();
if(type == 1){
Systemoutprintln("You have $"+acount+"!");
}else if(type == 2){
Systemoutprintln("您有"+acount+"圆!");
}else{
Systemoutprintln("类型选择错误,请重新选择!");
}
Systemoutprintln("1继续 2离开");
flag = scnextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}while(type!=1 && type!=2);
break;
case 2: do{
Systemoutprintln("请选择帐户类型:1 美元 2 人民币");
if(type == 1){
Systemoutprintln("Please input number of your money!");
input = scnextInt();
if(input > acount){
Systemoutprintln("You have not enough money!");
}else{
Systemoutprintln("You take care of your money!");
}
Systemoutprintln("1continue 2exit");
flag = scnextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else if(type == 2){
Systemoutprintln("请输入您要取的金额!");
input = scnextInt();
if(input > acount){
Systemoutprintln("您的余额不足!");
}else{
Systemoutprintln("请妥善保管您的钱!");
acount = acount - input;
}
Systemoutprintln("1继续 2离开");
flag = scnextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else{
Systemoutprintln("类型选择错误,请重新选择!");
}
}while(type!=1 && type!=2);
break;
default: Systemoutprintln("类型选择错误,请重新选择!");
}
}while(choice!=1 && choice!=2 || exit == false);
}else{
//密码错误,退出。
Systemoutprintln("三次密码错误,吞卡!");
}
}
}
很简单的例子,我把代码贴出来吧
import javautilScanner;
public class ATM {
/
@param args
/
public static void main(String[] args) {
Scanner in = null;
int result;
double drawMoney;
double depositMoney;
Account account = new Account();
while (true) {
Systemoutprintln("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆(ABC)中国农业银行ATM自动存取款机☆☆☆☆☆☆☆☆☆☆☆☆☆");
Systemoutprintln("\n\t\t\t\t1存款业务");
Systemoutprintln("\n\t\t\t\t2取款业务");
Systemoutprintln("\n\t\t\t\t3查询余额");
Systemoutprintln("\n\t\t\t\t4退出ATM系统");
Systemoutprintln("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆中国农业银行欢迎您的使用☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆");
in = new Scanner(Systemin);
switch (innextInt()) {
case 1:
Systemoutprintln("请输入您的存款数额!");
depositMoney = innextDouble();
if(depositMoney < 0)
Systemoutprintln("您的输入无效,请重新输入!");
result = accountdeposit(depositMoney);
if(result == 0){
Systemoutprintln("存款业务完成,是否显示余额?Y/N");
if("Y"equalsIgnoreCase(innext())){
Systemoutprintln("您当前的余额为:"+accountcheckCurrent());
}else {
break;
}
}else {
Systemoutprintln("无法完成交易!");
break;
}
break;
case 2:
Systemoutprintln("请输入您的取款数额!");
drawMoney = innextDouble();
if (drawMoney < 0) {
Systemoutprintln("您的输入无效,请重新输入!");
}
result = accountwithDraw(drawMoney);
if (result == 0) {
Systemoutprintln("存款业务完成,是否显示余额?Y/N");
if("Y"equalsIgnoreCase(innext())){
Systemoutprintln("您当前的余额为:"+accountcheckCurrent());
}else {
break;
}
} else {
Systemoutprintln("无法完成交易!");
break;
}
case 3:
Systemoutprintln("您当前的余额为:"+accountcheckCurrent());
break;
case 4:
break;
default:
break;
}
}
}
}
public class Account {
private double currentMoney;//当前余额
public double getCurrentMoney() {
return currentMoney;
}
public void setCurrentMoney(double currentMoney) {
if (currentMoney > 0) {
thiscurrentMoney = currentMoney;
}
}
/
取款业务
@param drawMoney
@return 0代表成功,1代表失败
/
public int withDraw(double drawMoney) {
if (currentMoney > 0 && drawMoney <= currentMoney) {
currentMoney -= drawMoney;
} else {
Systemoutprintln("您的余额已不足!");
return 1;
}
return 0;
}
/
存款业务
@param depositMoney
@return 0代表成功,1代表失败
/
public int deposit(double depositMoney) {
if (depositMoney > 0) {
currentMoney += depositMoney;
return 0;
}else {
Systemoutprintln("您提交的存款为负数,无法完成存款交易");
return -1;
}
}
/
查询余额业务
@return
/
public double checkCurrent() {
return currentMoney;
}
}
以上就是关于java编写的模拟ATM取款机程序全部的内容,包括:java编写的模拟ATM取款机程序、Java编程自动取款机步骤、使用Java语言中(类和对象)编写: ATM自动存取款机的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)