首页 期权学习期权知识正文

JAVA测试

xiaojiucai 期权知识 2020-08-18 377 0

  本周我们上JAVA课的时候进行了一次测试,本次测试以模拟中国工商银行自助机ATM的功能为大致要求,要求我们进行编写调试,以求达到试题要求。

  测试要求我们能模拟ATM的功能设计,当用户插卡后显示,输入密码界面,用户输入正确密码(用户输入错误密码,则提示该卡已被锁定,无法操作),则弹出选择界面:存款、取款、转账汇款、修改密码、查询余额。对accountinformation.txt和accountlist.txt数据库中的信息进行读写操作时,必须调用get()和set()方法。

程序开始运行模拟用户插卡显示用户输入账号功能,

1、用户在该界面输入账号信息,如果输入账号位数有误,提示“该卡不是工行卡”,如果输入账号信息在accountinformation.txt不存在,则提示“该账号不存在”,账号输入不成功,系统提示错误信息后返回输入账号界面;输入账号成功后,系统跳转到输入密码界面。

2、用户在该界面输入账号密码信息,如果密码录入错误(出现位数不对或与文件中该账号对应的密码不服),则提示“密码录入错误”,如果密码录入三次错误,则提示“该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理”。单次密码输入不成功,系统提示错误信息,返回输入密码界面;三次密码输入不成功,系统提示错误信息,返回输入账号界面,密码输入成功,系统跳转到主界面。

3、用户在该界面输入存款金额后,如果输入不是正整数,提示用户“输入金额有误,返回取款界面;输入字母“q”,则返回系统输入账号界面,表示退出柜员机操作;输入正整数,则跳转到下图存款成功界面。

4、存款成功后将该条记录作为操作流水信息记录到accountlist.txt文件中,并修改accountinformation.txt中的账户余额。

取款功能:

则显示100元、500元、1000元、1500元、2000元、5000元、其他金额、退卡、返回操作供用户选择。

转账汇款功能。

1.用户在该界面输入判断该账户是否存在accountinformation.txt文件中,如果没有提示“该账户不存在”,如果有则跳转到转账金额界面。

2.判断账户余额是否不小于录入金额,如果小于,则提示“账户余额不足”,如果大于,则跳转到下图转账确认成功界面。

3.单击“N”表示不确认转账,系统跳转到系统主界面;单击“Y”表示确认转账,系统跳转到转账成果界面,。

4.转账汇款成功后将该条记录作为操作流水信息记录到accountlist.txt文件中,并修改accountinformation.txt中的账户余额。

修改密码功能:

1. 系统进入修改密码界面:

2.当前密码录入错误,提示“当前密码录入错误”,系统返回修改密码界 面,清空数据重新录入;修改后密码与确认密码不一致,提示“修改密码与确认密码不一致”,系统返回修改密码界面,清空数据重新录入。

3. 密码修改成功后将该条记录作为操作流水信息记录到accountlist.txt文件中,并修改accountinformation.txt中的账户密码。

查询功能:

1.系统显示当前用户余额和操作流水信息:

2.点击“q”键,退回系统录入账号界面。

该程序源代码为:

//Account.java

//梁汉丞 信1705-3 20173643

package account1;

public class Account {

private String accountID;

private String accountname;

private String operatedate;

private int operatetype;

private int accountpassword;

private int accountbalance;

private int amount;

public String getAccountID() {

return accountID;

}

public void setAccountID(String accountID) {

this.accountID = accountID;

}

public String getAccountname() {

return accountname;

}

public void setAccountname(String accountname) {

this.accountname = accountname;

}

public String getOperatedate() {

return operatedate;

}

public void setOperatedate(String operatedate) {

this.operatedate = operatedate;

}

public int getOperatetype() {

return operatetype;

}

public void setOperatetype(int operatetype) {

this.operatetype = operatetype;

}

public int getAccountpassword() {

return accountpassword;

}

public void setAccountpassword(int accountpassword) {

this.accountpassword = accountpassword;

}

public int getAccountbalance() {

return accountbalance;

}

public void setAccountbalance(int accountbalance) {

this.accountbalance = accountbalance;

}

public int getAmount() {

return amount;

}

public void setAmount(int amount) {

this.amount = amount;

}

public void set(String id,String name,int password,int yuer)

{

accountID=id;

accountname=name;

accountpassword=password;

accountbalance=yuer;

}

public void set_1(String data,int liushui)

{

operatedate=data;

amount=liushui;

}

}

//AccountManage.java

//梁汉丞 信1705-3 20173643

package account1;

import java.io.BufferedReader;

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.*;

 

//梁汉丞 20173643 信1705-3

public class AccountManager {

private static/*静态*/ Scanner/*输入*/can=new Scanner(System.in);

private Vector<Account> map=new Vector/*矢量*/<Account>();

private Iterator<Account> it;

private String cnum;//定义cnum,go,index,an变量

private int go;

private int index;

private int an;

private Account me=new Account();

public static void main(String[] args) { //String args[]的意思是用于接收用户输入的参数,如果程序中需要用户输入参数,那么这些参数就保存在数据args中.

AccountManager a=new AccountManager();

try {

a.daoru_1();

a.daoru_2();

} catch (IOException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

a.start();

}

public void start()//线程开启的方法

{

go=3;//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)//如果输入的账号长度为8,则执行如下操作

{

// TODO 自动生成的方法存根

if(isfind(cnum))//如果在信息库里找到了相同账号,则跳转到下一界面

{

index=lookp(cnum)-1;

showpass();

}

else//否则输出"没有找到相关账户信息,请重新输入"

{

System.out.println("\t没有找到相关账户信息,请重新输入");

start();

}

}

else//如果账号长度不为8,则输出"输入的账户信息不是八位数,请重新输入"

{

System.out.println("\t输入的账户信息不是八位数,请重新输入");

start();

}

}

public void showpass()//声明showpass

{

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)//如果输入的数字长度为6,则执行如下操作

{

if(Integer.parseInt(cnum)==me.getAccountpassword())//如果输入的密码正确,则跳转至下一界面

{

insystem();

}

else//否则执行如下操作

{

if(go>0)

{

go--;

System.out.println("\t密码错误,请重新输入,还剩"+go+"次机会重新输入");

showpass();

}

else//如果输入次数达到三次,则输出"密码错误输入次数过多,返回账号输入菜单"并且返回第一界面

{

System.out.println("\t密码错误输入次数过多,返回账号输入菜单");

start();

}

}

}

else//输入的密码不是六位,输出"输入的密码信息不是六位数,请重新输入"

{

System.out.println("\t输入的密码信息不是六位数,请重新输入");

showpass();

}

}

public void insystem()

{

System.out.println("***************************************************************");

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.查询余额");

int type=0;//声明type为0

if(can.hasNextInt())

{

type=can.nextInt();

}

func(type);//传递函数体的规则

}

public void func(int type)

{

if(type==1)//输入1为存款

{

cunkuan();

}

else if(type==2)//输入2为取款

{

qukuan();

}

else if(type==3)//输入3为转账

{

zhuanzhang();

}

else if(type==4)//输入4为修改密码

{

xiugai();

}

else if(type==5)//输入5为查询

{

chaxun();

}

}

public void zhuanzhang()//声明转账

{

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)!=0)//

{

jine();

}

}

public void jine()//声明金额

{

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

ss=me;

map.get(an).setAccountbalance(map.get(an).getAccountbalance()+c);

map.get(an).setAmount(map.get(an).getAmount()+c);

map.setElementAt(ss, index);

try {

daochu_2();

daochu_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("\t当前账户余额为:"+me.getAccountbalance());

System.out.println("***************************************************************");

insystem();

}

else

{

System.out.println("金额不够,不能转");

zhuanzhang();

}

}

public void xiugai()

{

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密码输入格式错误,请重新输入");

xiugai();

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

ss=me;

map.setElementAt(ss, index);

try {

daochu_2();

daochu_1();

} catch (IOException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

System.out.println("\t密码修改成功");

insystem();

}

}

}

public void chaxun()//声明查询

{

System.out.println("***************************************************************");

System.out.println("\t欢迎 "+me.getAccountname()+" 使用中国工商银行自助柜员系统");

System.out.println("***************************************************************");

System.out.println("\t当前账户余额为:"+me.getAccountbalance());

System.out.println("***************************************************************");

insystem();

}

public void qukuan()//声明取款

{

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();

}

cunkuani(type);

}

public void cunkuani(int type)//声明存款

{

boolean g_test=false;

Account ss=new Account();

if(type==1)//输入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)//输入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)//输入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)//输入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)//输入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)//输入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)//输入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)//输入8

{

System.out.println("\t8.退卡成功");

start();

return;

}

else if(type==9)//输入9

{

insystem();

return;

}

if(g_test)

{

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("***************************************************************");

insystem();

}

}

public void cunkuan()//声明存款

{

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"))//实现输入q的时候返回第一界面

{

System.out.println("已经退出系统,返回账号界面");

}

else

{

System.out.println("输入错误,请重新输入");//

cunkuan();

}

}

}

if(num>0)

{

Account ss=new Account();

me.setAccountbalance(me.getAccountbalance()+num);

me.setAmount(me.getAmount()+num);

ss=me;

map.setElementAt(ss, index);

try {

daochu_2();

daochu_1();

} catch (IOException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

}

else

{

System.out.println("输入错误,请重新输入");

cunkuan();

}

qukuanchenggong();

insystem();

}

void qukuanchenggong()

{

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("***************************************************************");

}

public void daoru_1() throws IOException//声明导入1

{

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;

while((line = bufr.readLine())!=null){

Account st=new Account();

String ook[]=line.toUpperCase().split(" ");

st.set(ook[0],ook[1], Integer.parseInt(ook[2]),Integer.parseInt(ook[3]));

map.add(st);

me=st;

}

bufr.close();

//System.out.println(sb.toString());

}

c.close();

b.close();

}

public void daoru_2() throws IOException//声明导入2

{

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;

int i=0;

//map.clear();

while((line = bufr.readLine())!=null){

Account st=new Account();

String ook[]=line.toUpperCase().split(" ");

st.set(map.get(i).getAccountID(),map.get(i).getAccountname(),map.get(i).getAccountpassword(),map.get(i).getAccountbalance());

st.set_1(ook[0],Integer.parseInt(ook[1]));

String temp_str=""; 

Date dt = new Date(); 

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 

temp_str=sdf.format(dt);

if(!temp_str.equals(ook[0]))

{

st.setAmount(0);

st.setOperatedate(temp_str);

//index=i;

}

me=st;

map.setElementAt(st, i);

i++;

}

bufr.close();

//System.out.println(sb.toString());

}

c.close();

b.close();

}

public void daochu_1() throws IOException//声明导出1

{

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();

int i=0;

while(it.hasNext())

{

i++;

if(i!=1)

c.append("\r\n");

st=it.next();

c.append(st.getAccountID()+" "+st.getAccountname()+" "+st.getAccountpassword()+" "+st.getAccountbalance());

}

c.close();

b.close();

}

public void daochu_2() throws IOException//声明导出2

{

Account st=new Account();

File a=new File("accountlist.txt");

FileOutputStream b = new FileOutputStream(a);

OutputStreamWriter c=new OutputStreamWriter(b,"UTF-8");

it=map.iterator();

int i=0;

while(it.hasNext())

{

i++;

if(i!=1)

c.append("\r\n");

st=it.next();

c.append(st.getOperatedate()+" "+st.getAmount());

}

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 ok=false;

while(it.hasNext())

{

st=it.next();

if(st.getAccountID().equals(xuehao))

{

me=st;

ok=true;

break;

}

}

return ok;

}

}

我们在调试这个程序之前需要创建accountinformation.txt和accountlist.txt两个文件,文件里保存用户信息。

截图如下:

以上是我的制作过程,经过这次测验,让我感受颇深。

原文链接:https://www.qiquanji.com/post/8368.html

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注

更新实时通知

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论