ATM取款机
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
import java.util.*;
private Vector<Account> map=new Vector<Account>();
private Vector<Account> maplist=new Vector<Account>();
private final String szM[]=new String[]{"存款","取款","转账","修改密码","查询"};
private Iterator<Account> it;
private String cnum;
private int go;
private int index;
private int an;
private Account me=new Account();
public static void main(String[] args) {
AccountManager a=new AccountManager();
try {
a.insert_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
a.start();
}
public void start()
{
go=3;
index=0;
an=0;
System.out.println("***************************************************************");
System.out.println("\t欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的账号:");
if(can.hasNext())
{
cnum=can.next();
}
if(cnum.length()==8)
{
// TODO 自动生成的方法存根
if(isfind(cnum))
{
index=lookp(cnum)-1;
showpass();
}
else
{
System.out.println("\t没有找到相关账户信息,请重新输入");
start();
}
}
else
{
System.out.println("\t输入的账户信息不是八位数,请重新输入");
start();
}
}
public void showpass()
{
try {
insert_2();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入您的密码:");
if(can.hasNext())
{
cnum=can.next();
}
if(cnum.length()==6)
{
if(Integer.parseInt(cnum)==me.getAccountpassword())
{
insystem();
}
else
{
if(go>0)
{
System.out.println("\t密码错误,请重新输入,还剩"+go+"次机会重新输入");
showpass();
go--;
}
else
{
System.out.println("\t密码错误输入次数过多,返回账号输入菜单");
start();
}
}
}
else
{
System.out.println("\t输入的密码信息不是六位数,请重新输入");
showpass();
}
}
public void insystem()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t1.存款");
System.out.println("\t2.取款");
System.out.println("\t3.转账汇款");
System.out.println("\t4.修改密码");
System.out.println("\t5.查询余额");
System.out.println("\tq.登录菜单");
int type=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
else
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else
{
System.out.println("输入错误,请重新输入");
insystem();
return;
}
}
func(type);
public void func(int type)
{
if(type==1)
{
deposit_1();
}
else if(type==2)
{
draw();
}
else if(type==3)
{
transfer();
}
else if(type==4)
{
change();
}
else if(type==5)
{
inquiry();
}
}
public void transfer()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入你要转账的账号:");
String type=null;
if(can.hasNext())
{
type=can.next();
}
if((an=lookp(type)-1)!=-1)
{
jiner();
}
else
{
System.out.println("\t查无此账号");
}
}
public void jiner()
{
int c=0;
System.out.println("\t请输入你要转账的金额:");
if(can.hasNextInt())
{
c=can.nextInt();
}
if(me.getAccountbalance()>=c)
{
Account ss=new Account();
me.setAccountbalance(me.getAccountbalance()-c);
me.setAmount(me.getAmount()-c);
me.setOperatetype(3);
ss=me;
map.get(an).setAccountbalance(map.get(an).getAccountbalance()+c);
map.get(an).setAmount(map.get(an).getAmount()+c);
map.get(an).setOperatetype(1);
map.setElementAt(ss, index);
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户向"+map.get(an).getAccountname()+"成功转账"+c+"元。");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
insystem();
}
else
{
System.out.println("金额不够,不能转");
transfer();
}
}
public void change()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入你原来的密码:");
int type=0,g_old=0,g_new=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
if(type==me.getAccountpassword())
{
System.out.println("\t请输入你要修改的密码:");
if(can.hasNextInt())
{
g_old=can.nextInt();
}
if(!(g_old>=100000&&g_old<=999999))
{
System.out.println("\t密码输入格式错误,请重新输入");
change();
return;
}
System.out.println("\t请再次你输入你要修改的密码:");
if(can.hasNextInt())
{
g_new=can.nextInt();
}
if(g_new==g_old)
{
Account ss=new Account();
me.setAccountpassword(g_old);
me.setOperatetype(4);
ss=me;
map.setElementAt(ss, index);
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t密码修改成功");
System.out.println("***************************************************************\n");
System.out.println("\t按q输入回车回到账号输入菜单,按其他任意键回到主菜单\n");
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面\n");
start();
return;
}
else insystem();
}
}
}
}
public void inquiry()
{
me.setOperatetype(5);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("\t账号清单信息为:");
it=maplist.iterator();
int i=1;
Account st=new Account();
while(it.hasNext())
{
st=it.next();
if(st.getAccountID().equals(me.getAccountID()))
{
System.out.println("\t"+i+"、"+st.getOperatedate()+" "+szM[st.getOperatetype()-1]+" "+st.getAmount());
i++;
}
}
if(i==1)
System.out.println("用户尚无操作");
System.out.println("***************************************************************\n");
Account ss=new Account();
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
//1
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
insystem();
}
public void draw()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户每日可以支取2万元。");
System.out.println("\t1.100元");
System.out.println("\t2.500元");
System.out.println("\t3.1000元");
System.out.println("\t4.1500元");
System.out.println("\t5.2000元");
System.out.println("\t6.5000元");
System.out.println("\t7.其他金额");
System.out.println("\t8.退卡");
System.out.println("\t9.返回");
int type=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
deposit(type);
}
public void deposit(int type)
{
boolean g_test=false;
Account ss=new Account();
if(type==1)
{
if(me.getAccountbalance()>=100)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-100);
me.setAmount(me.getAmount()-100);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==2)
{
if(me.getAccountbalance()>=500)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-500);
me.setAmount(me.getAmount()-500);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==3)
{
if(me.getAccountbalance()>=1000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-1000);
me.setAmount(me.getAmount()-1000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==4)
{
if(me.getAccountbalance()>=1500)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-1500);
me.setAmount(me.getAmount()-1500);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==5)
{
if(me.getAccountbalance()>=2000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-2000);
me.setAmount(me.getAmount()-2000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==6)
{
if(me.getAccountbalance()>=5000)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-5000);
me.setAmount(me.getAmount()-5000);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==7)
{
int num=0;
if(can.hasNextInt())
{
type=can.nextInt();
}
if(me.getAccountbalance()>=num)
{
g_test=true;
me.setAccountbalance(me.getAccountbalance()-num);
me.setAmount(me.getAmount()-num);
ss=me;
map.setElementAt(ss, index);
}
}
else if(type==8)
{
System.out.println("\t8.退卡成功");
start();
return;
}
else if(type==9)
{
insystem();
return;
}
if(g_test)
{
me.setOperatetype(2);
ss.setOperatetype(2);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户取款成功");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
//1
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("\t输入q退出到账号菜单,按其他任意键回到主菜单\n");
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else insystem();
}
}
}
public void deposit_1()
{
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t请输入存款金额:");
int num=0;
if(can.hasNextInt())
{
num=can.nextInt();
}
else
{
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else
{
System.out.println("输入错误,请重新输入");
deposit_1();
}
}
}
if(num>0)
{
Account ss=new Account();
me.setAccountbalance(me.getAccountbalance()+num);
me.setAmount(me.getAmount()+num);
ss=me;
map.setElementAt(ss, index);
achieve();
}
else
{
System.out.println("输入错误,请重新输入");
deposit_1();
}
}
void achieve()
{
me.setOperatetype(1);
System.out.println("***************************************************************");
System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println("\t当前账户存款成功");
System.out.println("\t当前账户余额为:"+me.getAccountbalance());
System.out.println("***************************************************************\n");
System.out.println("\t输入q退出到账号菜单,按其他任意键回到主菜单\n");
//1
Account ss=new Account();
ss.set_1(me.getOperatedate(), me.getAmount(), me.getOperatetype());
ss.setAccountID(me.getAccountID());
maplist.add(ss);
try {
output_2();
output_1();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
if(can.hasNext())
{
cnum=can.next();
if(cnum.equals("q"))
{
System.out.println("已经退出系统,返回账号界面");
start();
return;
}
else insystem();
}
}
public void insert_1() throws IOException
{
File a=new File("accountinformation.txt");
FileInputStream b = new FileInputStream(a);
map.clear();
InputStreamReader c=new InputStreamReader(b,"UTF-8");
{
BufferedReader bufr =new BufferedReader(c);
String line = null;
boolean g_tr=false;
while((line = bufr.readLine())!=null){
if(!g_tr)
{
g_tr=true;
continue;
}
Account st=new Account();
String ook[]=line.split(" "); //字符串变成字符串数组
st.set(ook[0],ook[1], Integer.parseInt(ook[2]),Integer.parseInt(ook[3]));
map.add(st);
}
bufr.close();
//System.out.println(sb.toString());
}
c.close();
b.close();
}
public void insert_2() throws IOException
{
File a=new File("accountlist.txt");
FileInputStream b = new FileInputStream(a);
InputStreamReader c=new InputStreamReader(b,"UTF-8");
{
BufferedReader bufr =new BufferedReader(c);
String line = null;
maplist.clear();
boolean g_tr=false;
String ostr="",temp_str="";
while((line = bufr.readLine())!=null){
if(!g_tr)
{
g_tr=true;
continue;
}
Account st=new Account();
String ook[]=line.split(" ");
st.setAccountID(ook[3]);
st.set_1(ook[0],Integer.parseInt(ook[1]),Integer.parseInt(ook[2]));
if(me.getAccountID().equals(ook[3]))
{
ostr=ook[0];
me.setAmount(Integer.parseInt(ook[1]));
me.setOperatedate(ook[0]);
}
maplist.add(st);
}
Date dt = new Date(); //获取时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //对时间格式化
temp_str=sdf.format(dt);
if(!ostr.equals(temp_str))
{
me.setAmount(0);
me.setOperatedate(temp_str);
}
bufr.close();
}
c.close();
b.close();
}
public void output_1() throws IOException
{
Account st=new Account();
File a=new File("accountinformation.txt");
FileOutputStream b = new FileOutputStream(a);
OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");
it=map.iterator();
while(it.hasNext())
{
c.append("\r\n");
st=it.next();
c.append(st.getAccountID()+" "+st.getAccountname()+" "+st.getAccountpassword()+" "+st.getAccountbalance());
}
c.close();
b.close();
}
public void output_2() throws IOException
{
File a=new File("accountlist.txt");
FileOutputStream b = new FileOutputStream(a,true);
String temp_str="";
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
temp_str=sdf.format(dt);
OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");
{
c.append("\r\n");
c.append(temp_str+" "+me.getAmount()+" "+me.getOperatetype()+" "+me.getAccountID());
}
c.close();
b.close();
}
//-----------------------------
public int lookp(String xuehao)
{
Account st=new Account();
int i=0;
it=map.iterator();
while(it.hasNext())
{
i++;
st=it.next();
if(st.getAccountID().equals(xuehao))
break;
}
return i;
}
public boolean isfind(String xuehao)
{
Account st=new Account();
it=map.iterator();
boolean flag=false;
while(it.hasNext())
{
st=it.next();
if(st.getAccountID().equals(xuehao))
{
me=st;
flag=true;
break;
}
}
return flag;
}
ATM取款机的更多相关文章
- 大话JS面向对象之开篇万物皆对象------(ATM取款机引发的深思)
一,总体概要 OO(面向对象)概念的提出是软件开发工程发展的一次革命,多年来我们借助它使得很多大型应用程序得以顺利实现.如果您还没有掌握并使用OO进行程序设计和开发,那么您无疑还停留在软件开发的石器时 ...
- Oracle实战训练——ATM取款机业务
ATM取款机的数据库模拟开发和实战总结 一.ATM实战开发的简介. 学习了几天的Oracle,开始着手用数据库PL/SQL语言做一个简单的ATM取款机业务,主要是为了巩固数据库的知识,并非真正的去实现 ...
- 第一周:设计一个简易ATM取款机简易程序(2)
1.了解用户对ATM取款机功能需求如下: 2.新建一个login函数使用for循环方法和if选择方法编写登陆界面用来及设置ATM内用户的金额和取款机内的金额: 3.使用新建函数方法及if选择方法编写登 ...
- ATM取款机的数据库模拟开发和实战总结
一.ATM实战开发的简介. 学习了几天的Oracle,开始着手用数据库PL/SQL语言做一个简单的ATM取款机业务,主要是为了巩固数据库的知识,并非真正的去实现高端的业务.有兴趣的可以看看,希望对同胞 ...
- ATM取款机模拟——数据结构课设
今天帮人写的第二篇课设 . ;-) 机智的窝 要求:大概说一下吧,就是要创建一个用户(初始化一账户),模拟ATM的业务(取款,100的整数倍,改密 码,查剩余金额.等等,各 ...
- LinuxC语言实现ATM取款机实验Socket
链接:https://pan.baidu.com/s/1sZt4qhYc6CDJVpoJHbtw-Q 提取码:53ot 复制这段内容后打开百度网盘手机App,操作更方便哦 本实验用的是Centos7t ...
- Linux下C语言实现ATM取款机,消息队列版本
链接:https://pan.baidu.com/s/1oBavXBuZul7ZAEBL1eYfRA 提取码:ffhg Mybank ATM取款机实验,消息队列实现本实验用的是Centos71.在服务 ...
- 设计模式(十二):通过ATM取款机来认识“状态模式”(State Pattern)
说到状态模式,如果你看过之前发布的重构系列的文章中的<代码重构(六):代码重构完整案例>这篇博客的话,那么你应该对“状态模式”并不陌生,因为我们之前使用到了状态模式进行重构.上一篇博客我们 ...
- ATM取款机优化需求的用例设计
案例设计需求 有一个ATM取款系统,现对于取款功能进行了如何需求变更:碑只能取面额是100元(如取500,输出5张100元),现在功能修改为,可以取面额是10元.50元和100元的,其余功能不变,用户 ...
- java基础:模拟ATM取款机
package com.atm; import java.util.Scanner; /** * ATM类实现 * * @author 向往的生活 */ public class ATM { publ ...
随机推荐
- 第5章 实现windows程序的数据绑定
1:连接式: command 对象负责对数据库的执行命令 DataReader 对象负责从数据源中读取数据 connection 对象负责链接数据库 断开式: 数据集的Dataset存放在独立的数据源 ...
- Oracle 11g服务详细介绍及哪些服务是必须开启的
成功安装Oracle 11g后,共有7个服务,这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Service: Oracle卷映射拷贝写入服务,VSS(Volume Sh ...
- cordava打包vue项目成app
注意:安装目录不要以中文命名 1.安装cordova :npm install -g cordova 2.安装java jdk :配置环境变量: 1.系统变量:名:JAVA_HOME 值:C:\ ...
- cloud-api-service和cloud-iopm-web提交merge方法
cloud-api-service应该push to '自己的分支',然后去gitserver请求合并 cloud-iopm-web(master分支)应该push to Upstream,然后去gi ...
- Linux命令:lsof
简介 lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传输控 ...
- (转)java调用python脚本
这篇博客旨在吐血分享今天遇到的java调用python脚本遇到的坑,折腾了3个多小时终于可以跑通了,代码超级短,但网上的好多资料都是抄来抄去的,很少有能够直接跑通的,尤其是针对你的python文件中用 ...
- Linux修改IP网络配置
文件路径:/etc/sysconfig/networe-scripts/ifcfg-eth0 BOOTPROTO="static" IPADDR=IP地址 NETMASK=掩码 G ...
- NPOI设置单元格格式
转自:http://www.cr173.com/html/18143_2.html //创建一个常用的xls文件 private void button3_Click(object sender, E ...
- vue路由(一个包含重定向、嵌套路由、懒加载的main.js如下)and 路由跳转传参的query和params的异同
import Vue from 'vue'import VueRouter from 'vue-router'import App from './App'Vue.use(VueRouter)cons ...
- cocos2d-x -Lua 字符串
字符串或串(String)是由数字.字母.下划线组成的一串字符. Lua 语言中字符串可以使用以下三种方式来表示: 单引号间的一串字符. 双引号间的一串字符. [[和]]间的一串字符. 以上三种方式的 ...