Java编写的模拟ATM取款机程序
2007-10-17 15:38
686 查看
/**
* @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();
if(!pwd1.equals(pwd2))
{
System.out.println("两次输入不一致,请再次输入.");
}
else
{
System.out.println("密码修改成功,请使用新密码.");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter>3);
}
/**********锁定机器**********/
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.Welcome();
atm.Load_Sys();
// atm.Exit_Sys();
}
}
* @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();
if(!pwd1.equals(pwd2))
{
System.out.println("两次输入不一致,请再次输入.");
}
else
{
System.out.println("密码修改成功,请使用新密码.");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter>3);
}
/**********锁定机器**********/
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.Welcome();
atm.Load_Sys();
// atm.Exit_Sys();
}
}
相关文章推荐
- Java编写的模拟ATM取款机程序
- 【练习题】构造方法 编写Java程序,模拟简单的计算器。
- ATM银行取款机模拟程序(可连接数据库)
- java程序 升级版ATM取款机
- 用java编写模拟斗地主洗牌发牌程序
- JAVA--第九周实验--编写一个模拟用户帐户的程序(内测版)
- JAVA第九周任务1.编写一个模拟用户帐户的程序
- 一个用java模拟ATM操作的小程序
- c语言编写的ATM取款机程序
- 编写Java程序,模拟简单的计算器。 定义名为Number的类,其中有两个整型数据成员n1和n2,应声明为私有。 编写构造方法,用于初始化n1和n2,再为该类定义 加(addition)、 减(su
- 如何实现用Java编写程序,设计一个模拟电梯运行的类
- 简单Java Applet程序的编写
- Lesson_for_java_day21--java的多线程练习(ATM存取款机、多窗口卖票系统、5人赛跑)
- 使用Java语言编写程序最容易犯的21种错误
- 编写一个Java程序将当100,101,102,103,104,105个数以数组的形式写入到Dest.txt文件中,并以相反的顺序读出显示在屏幕上
- 利用记事本编写并运行一个java程序
- java编写程序输出下列结果
- 感觉今天一天没做什么事情啊QAQ,学习了一下java的基本语法,编写了几个小程序,还是总结一下吧
- 用Java程序编写兔子繁殖题目
- Java小程序之集合框架模拟数据库实现用户登录和注册功能