一、java测试题目(ATM自助取款机系统)
//信1905-2 20194021 马荣荣
package ATM;
public class Account {
private String accountID;
private String accountname;
private String operatedate;
private int operatetype;
private String accountpassword;
private int accountbalance;
private int amount;
//set函数
public void setaccountID(String m) {
accountID=m;
}
public void setaccountname(String m) {
accountname=m;
}
public void setoperatedate(String m) {
operatedate=m;
}
public void setoperatetype(int x) {
operatetype=x;
}
public void setaccountpassword(String m) {
accountpassword=m;
}
public void setaccountbalance(int x) {
accountbalance=x;
}
public void setamount(int x) {
amount=x;
}
public void Set(String ID,String name,String date,int type,String password,int balance,int t) {
setaccountID(ID);
setaccountname(name);
setoperatedate(date);
setoperatetype(type);
setaccountpassword(password);
setaccountbalance(balance);
setamount(t);
}
//get函数
public String getaccountID() {
return accountID;
}
public String getaccountname() {
return accountname;
}
public String getoperatedate() {
return operatedate;
}
public int getoperatetype() {
return operatetype;
}
public String getaccountpassword() {
return accountpassword;
}
public int getaccountbalance() {
return accountbalance;
}
public int getamount() {
return amount;
}
public Account() {
amount=0;
accountbalance = 0;
accountpassword="Hello";
operatetype = 0;
operatedate="2020-9-22";
accountname="李华";
accountID="20190001";
}//构造函数
//主函数
public static void main(String[] args) {
}
//信1905-2 20194021 马荣荣
package ATM;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Scanner;
public class AccountManager {
private Account numku[] = new Account[5];//数据组
//private String Infor="files/accountinformation.txt";
//private String List="files/accountlist.txt";
//private String Today= "2020-9-22";
public void Startm() throws IOException{//初始界面
Mainm(0);
/*System.out.println("***************************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入您的账号: ");
//判断输入账号位数是否有误
Scanner sc= new Scanner(System.in);
String x = sc.next();
int e = 5;
for(int i=0;i<5;i++)
if(numku[i].getaccountID().compareTo(x)==0)
{
e=i;
break;
}
if(e==5)
{
System.out.println(" 该卡不是工行卡!");
Startm();
}
else
Twom(e);*/
}
//密码输入
public void Twom(int p) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入您的密码:");
Scanner sc= new Scanner (System.in);
int times=0;
while(times<3) {
String saving = sc.nextLine();
if(numku[p].getaccountpassword().compareTo(saving)!=0)
System.out.println("密码录入错误");
else
break;
times++;
}
if(times==3)
Startm();
//else
//Mainm();
}
//系统主界面
public void Mainm(int p) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 1.存款");
System.out.println(" 2.取款");
System.out.println(" 3.转账汇款");
System.out.println(" 4.修改密码");
System.out.println(" 5.查询余额");
System.out.println("***************************************************************");
Scanner sc = new Scanner (System.in);
int l = sc.nextInt();
switch(l) {
case 1:numku[p].setoperatetype(1);writefile();fun1(p);break;
case 2:numku[p].setoperatetype(2);writefile();fun2(p);break;
case 3:numku[p].setoperatetype(3);writefile();fun3(p);break;
case 4:numku[p].setoperatetype(4);writefile();fun4(p);break;
case 5:numku[p].setoperatetype(5);writefile();fun5(p);break;
default:Mainm(p);break;
}
}
private void writefile() {
// TODO 自动生成的方法存根
}
//存款
public void fun1(int p) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入存款金额:");
int J= sc.nextInt();
Scanner sc = new Scanner (System.in);
Scanner sc = new Scanner (System.in);
if(J<=0)
System.out.println("输入金额有误");
fun1(p);
numku[p].setamount(numku[p].getamount()+J);
numku[p].setaccountbalance(numku[p].getaccountbalance()+J);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户存款操作成功。");
System.out.println(" 当前账户余额为:"+numku[p].getaccountbalance()+"元");
}
public void fun2(int p) throws IOException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户每日可以支取2万元。");
System.out.println(" 1、100元");
System.out.println(" 2、500元");
System.out.println(" 3、1000元");
System.out.println(" 4、1500元");
System.out.println(" 5、2000元");
System.out.println(" 6、5000元;");
System.out.println(" 7、其他金额");
System.out.println(" 8、退卡");
System.out.println(" 9、返回");
System.out.println("****************************************************************");
System.out.println(" #:请选择");
System.out.println("*****************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("*****************************************");
System.out.println(" 请输入取款金额: ");
System.out.println("*****************************************");
System.out.println("*****************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("*****************************************");
System.out.println(" 当前帐户账户款成功! ");
System.out.println(" 当前帐户余额为:"+numku[p].getaccountbalance());
System.out.println("*****************************************");
}
}
public void fun3(int p,int p1) throws IOException{
System.out.println("*****************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("*****************************************");
System.out.println(" 请输入转账账户: ");
System.out.println("*****************************************");
System.out.println("*****************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("*****************************************");
System.out.println("*****************************************");
System.out.println(" 请输入转账金额: ");
System.out.println("*****************************************");
public static void zhuazhang1() {
int flag=0;
Scanner con=new Scanner(System.in);
String str=con.next();
for(int i=0;i<5;i++) {
if(str.equals(acc[i].getaccountID())) {
flag=1;
sf=i;
break;
}
}
if(flag==0) System.out.println("该账户不存在!");
}
public static void zhuanzhang2() {
Scanner con=new Scanner(System.in);
int mo=con.nextInt();
if(numku[p].getaccountbalance()<mo)System.out.println("账户余额不足!");
else {
System.out.println("*****************************************");
System.out.println(" 欢迎"+numku[p].getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("*****************************************");
System.out.println(" 请确认是否向"+numku[p].getaccountname()+"转账"+mo+"元(Y/N)");
System.out.println("*****************************************");
String a=con.next();
}
}
public void fun4(int p,int p1) throws IOException{
Scanner con=new Scanner(System.in);
System.out.println("请输入新密码:");
String mima=con.next();
numku[p].setaccountpassword(mima);
System.out.println("修改密码成功!");
}
public void fun5(int p,int p1) throws IOException{
System.out.println("余额为:"+numku[p].getaccountbalance());
}
}
public static void main(String[] args) throws IOException {
AccountManager a = new AccountManager();
a.Startm();
}
}
测试截图:
二、心得体会: