Posted on 2008-04-21 20:45
橡皮人 阅读(210)
评论(0) 编辑 收藏
package com.nicholas.java;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
abstract class Bank {
abstract void userInformation();
}
class Person extends Bank {
isRight ir=new isRight();
public void userInformation() {
Welcome welcome=new Welcome();
System.out.println("欢迎使用ATM自动提款机!");
int temp=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try {
for(int i=0;i<3;i++) {
System.out.println("请输入你的卡号:");
String cord=br.readLine();
if(cord.equals(ir.getName())){
System.out.println("请输入你的密码:");
String pwd=br.readLine();
if(pwd.equals(ir.getpwd())){
welcome.WelcomeDisktop();
}
}
else{
System.out.println("账号或密码错误,请重新输入!");
temp++;
if(temp>=3) {
System.out.println("你输入错误次数过多,有重大嫌疑,现已没收你的卡!!!");
System.exit(1);
}
continue;
}
}
}
catch(Exception e) {
}
}
}
class PutMoney extends Thread{
private String s1;
private String s2;
private String s3;
private String s4;
private String s5;
int money=5000;
int a=100;
int b=300;
int c=500;
int d=1000;
int e=2000;
public String getS1() {
return s1;
}
public String getS2() {
return s2;
}
public String getS3() {
return s3;
}
public String getS4() {
return s4;
}
public String getS5() {
return s5;
}
public void putMoney(){
Welcome welcome=new Welcome();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i;
try{
System.out.println("请输入你要取款的数额");
System.out.print("1.100元"+"\n"+"2.300元"+"\n"+"3.500元"+"\n"+"4.1000元"+"\n"+"5.2000元"+"\n"+"6.返回"+"\n");
if(money<=0) {
System.out.println("你已无余额,卡不能透支!");
}
i=br.read();
switch(i){
case 49:{
money-=a;
System.out.println("正在出款,请稍侯~~~~");
sleep(2000);
Calendar c1=Calendar.getInstance();
SimpleDateFormat f1=new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
s2=f1.format(c1.getTime());
System.out.println("交易成功!");
break;
}
case 50:{
money-=b;
System.out.println("正在出款,请稍侯~~~~");
sleep(2000);
Calendar c2=Calendar.getInstance();
SimpleDateFormat f2=new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
s2=f2.format(c2.getTime());
System.out.println("交易成功!");
break;
}
case 51:{
money-=c;
System.out.println("正在出款,请稍侯~~~~");
sleep(2000);
Calendar c3=Calendar.getInstance();
SimpleDateFormat f3=new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
s2=f3.format(c3.getTime());
System.out.println("交易成功!");
break;
}
case 52:{
money-=d;
System.out.println("正在出款,请稍侯~~~~");
sleep(2000);
Calendar c4=Calendar.getInstance();
SimpleDateFormat f4=new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
s2=f4.format(c4.getTime());
System.out.println("交易成功!");
break;
}
case 53:{
money-=e;
System.out.println("正在出款,请稍侯~~~~");
sleep(2000);
Calendar c5=Calendar.getInstance();
SimpleDateFormat f5=new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
s2=f5.format(c5.getTime());
System.out.println("交易成功!");
break;
}
case 48 :{
welcome.WelcomeDisktop();
break;
}
default :{
System.out.println("输入错误!");
break;
}
}
}catch(Exception e){
}
}
isRight ir=new isRight();
public void chaXun() {
System.out.println("账号为:"+ir.getName());
System.out.println("余额为:"+money);
}
public void jiaoyiInformation() {
System.out.println("账号为"+ir.getName());
}
}
class isRight {
private String name="nicholas";
private String pwd="402944054";
public String getName(){
return name;
}
public String getpwd(){
return pwd;
}
}
class Welcome{
public void WelcomeDisktop(){
PutMoney putmoney =new PutMoney();
int i;
try{
while(true) {
System.out.print("1.取款"+"\n"+"2.查询余额"+"\n"+"3.查看交易记录"+"\n"+"4.返回"+"\n"+"0.退出系统"+"\n"+"\n");
System.out.println("请输入你要操作的模块:");
// ir.reset();
//i=52b;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
i=br.read();
br=null;
switch(i){
case 49:{
putmoney.start();
putmoney.putMoney();
break;
}
case 50: {
putmoney.chaXun();
break;
}
case 51: {
if(putmoney.money==4900) {
System.out.println("交易时间为:"+putmoney.getS1());
System.out.println("取走金额为:"+putmoney.a);
}
else if(putmoney.money==4700) {
System.out.println("交易时间为:"+putmoney.getS2());
System.out.println("取走金额为:"+putmoney.b);
}
else if(putmoney.money==4500) {
System.out.println("交易时间为:"+putmoney.getS3());
System.out.println("取走金额为:"+putmoney.c);
}
else if(putmoney.money==4000) {
System.out.println("交易时间为:"+putmoney.getS4());
System.out.println("取走金额为:"+putmoney.d);
}
else if(putmoney.money==3000) {
System.out.println("交易时间为:"+putmoney.getS5());
System.out.println("取走金额为:"+putmoney.e);
}
else {
System.out.println("余额为:"+putmoney.money+"未进行取款交易!");
}
break;
}
case 52: {
WelcomeDisktop();
break;
}
case 48: {
System.exit(1);
break;
}
default: {
System.out.println("输入错误请返回重新输入!!!");
break;
}
}
}
}catch(Exception e) {
}
}
}
public class ATM {
/**
* @param args
*/
public static void main(String[] args) {
Person person =new Person();
person.userInformation();
}
}