手机站
网通分站
电信主站
密 码:
用户名:
热门关键字:  虚拟主机  cn域名  域名注册  非法  seo
当前位置 : 主页>程序设计>Java技术>列表

Java编写的模拟ATM取款机程序

来源:互联网 作者:west263.com 时间:2008-02-23 点击:
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

/**
* @version 1.0
* @author Devil_Angel
* 该程序的功能为实现模拟银行ATM自动取款机提款,查询等功能.
*
*/

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;
}
}

/**********实现具体取款机功能*********/
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");
}

/**********登陆系统**********/
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
SysOpter();

}while(counter<3);
Lock_Sys();
}

/**********系统操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请选择您要操作的项目(1-4):");
num=br.read(); //num为ASICC码转换的整数
switch(num) {
case 49: BetBalance(); break;
case 50: Inqu_Info(); break;
case 51: Set_Password(); break;
case 52: Exit_Sys(); break;
}
System.exit(1);
}

/**********信息查询**********/
protected void Inqu_Info() {
System.out.print("---------------------\n"
act.get_Code() "\n"
act.get_Name() "\n"
act.get_Money() "\n"
"-----------------------");
}

/**********取款**********/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("请输入您要取的数目:");
str=br.readLine();
str1=String.valueOf(act.get_Money());
if(str.compareTo(str1)>0) {
System.out.println("超过已有的钱数,请重新输入您要取的数目:");
}
else {
/*操作成功*/
// act.set_Balance(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();

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

共2页: 上一页 1 [2] 下一页
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名
注册