Java测试总结(ATM)
2021-06-20 17:05
标签:读取 swa 工商银行 read 语言 出现 exists 创建文件 rgs Java测试总结(ATM) 标签:读取 swa 工商银行 read 语言 出现 exists 创建文件 rgs 原文地址:https://www.cnblogs.com/zjm15511858030/p/9687997.html
import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
public class ATM {
// TODO Auto-generated method stub
put1();
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
@SuppressWarnings("unused")
String str = null;
str = s.next();
put2();
@SuppressWarnings("resource")
Scanner s1 = new Scanner(System.in);
@SuppressWarnings("unused")
String str1 = null;
str1 = s1.next();
put3();
Scanner input=new Scanner(System.in);
ArrayList atm=new ArrayList();
ArrayList
FileOperation f= new FileOperation();
int select=1;
for(;;)
{
do
{
select=input.nextInt();
}while(select5);
switch(select)
{
case 1:withdraw(atm);break;
case 2:deposit(atm);break;
case 4:change();break;
}
input.close();
}
}
System.out.println("请输入存款金额");
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
int amount=in.nextInt();
int accountbalance=in.nextInt();
if(amount System.out.println("存款金额不能小于0");
}else{
accountbalance=accountbalance+amount;
System.out.println("您已成功存入:"+amount+"元,您现在总余额为:"+accountbalance+"元"+"\n");
}
}
private static void put1()
{
System.out.println("***************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************");
System.out.println(" 请输入您的账号:");
System.out.println("***************************************************");
}
private static void put2()
System.out.println("***************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************");
System.out.println(" 请输入您的密码:");
System.out.println("***************************************************");
}
private static void put3() {
System.out.println(" 请选择你要执行的功能");
System.out.println(" 1.存款");
System.out.println(" 2.取款");
System.out.println(" 3.转账汇款");
System.out.println(" 4.修改密码");
System.out.println(" 5.查询余额");
}
private static void put4()
{
System.out.println(" ***************************************************************\r\n" +
" 欢迎XXXXXXXX(账户名称)使用中国工商银行自助柜员系统\r\n" +
" ****************************************************************当前账户每日可以支取2万元。\r\n" +
" 1、100元\r\n" +
" 2、500元\r\n" +
" 3、1000元\r\n" +
" 4、1500元\r\n" +
" 5、2000元\r\n" +
" 6、5000元;\r\n" +
" 7、其他金额\r\n" +
" 8、退卡\r\n" +
" 9、返回\r\n" +
" ****************************************************************1.存款");
private static void withdraw(ArrayList atm)
{
System.out.println("请输入取款金额:");
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
put4();
int amount=in.nextInt();
Account x= new Account();
int accountbalance=x.get_accountbalance();
if(amount>5000){
System.out.println("取款金额不能大于5000"+"\n");
}else{
if(amount%100!=0){
System.out.println("取款金额必须为100的整数倍"+"\n");
}else{
accountbalance=accountbalance-amount;
System.out.println("您取出了"+amount+"元,您现在的余额为:"+accountbalance+"元"+"\n");
}
}
}
private static void deposit(ArrayList atm) {
System.out.println("请输入存款金额");
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
int amount=in.nextInt();
Account x= new Account();
int accountbalance=x.get_accountbalance();
if(amount System.out.println("存款金额不能小于0");
}else{
accountbalance=accountbalance+amount;
System.out.println("您已成功存入:"+amount+"元,您现在总余额为:"+accountbalance+"元"+"\n");
}
}
public static void change(){
System.out.println("请输入您的密码:");
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
Account x= new Account();
String accountpassword=x.get_accountpassword();
String accountpassword1=in.nextLine();
if(accountpassword1==accountpassword){
System.out.println("请输入新密码:");
@SuppressWarnings("unused")
String accountpassword2=in.nextLine();
System.out.println("您的密码已修改为:"+accountpassword2+"\n");
}else{
System.out.println("密码输入错误:"+"\n");
}
}
}
//信1705-3 20173517 赵家明
private String accountID;
private String accountname;
private String operatedate;
private int operatetype;
private String accountpassword;
private int accountbalance;
private int amount;
Account ()
{
accountID="20173517";
accountname="zjm";
operatedate="2018-09-20";
operatetype=1;
accountpassword="042669";
accountbalance=1000;
amount=100;
}
Account (String a,String b,String c,int d,String e,int f,int g)
{
accountname=b;
operatedate=c;
operatetype=d;
accountpassword=e;
accountbalance=f;
amount=g;
}
public void set_accountID(String str)
{
accountID=str;
}
public void set_accountname(String str)
{
accountname=str;
}
public void set_operatedate(String str)
{
operatedate=str;
}
public void set_operatetype(int n)
{
operatetype=n;
}
public void set_accountpassword(String str)
{
accountpassword=str;
}
public void set_accountbalance(int n)
{
accountbalance=n;
}
public void set_amount(int n)
{
amount=n;
}
{
return accountID;
}
public String get_accountname()
{
return accountname;
}
public String get_operatedate()
{
return operatedate;
}
public int get_operatetype()
{
return operatetype;
}
public String get_accountpassword()
{
return accountpassword;
}
public int get_accountbalance()
{
return accountbalance;
}
public int get_amount()
{
return amount;
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.RandomAccessFile;
public class FileOperation {
//创建文件
public static boolean createFile(File fileName)throws Exception{
@SuppressWarnings("unused")
Boolean flag=false;
try{
if(!fileName.exists()){
fileName.createNewFile();
flag=true;
}
}
catch(Exception e){
e.printStackTrace();
}
return true;
}
//读TXT文件内容
public static String readTxtFile(File fileName)throws Exception{
String result=null;
FileReader fileReader=null;
BufferedReader bufferedReader=null;
try{
fileReader=new FileReader(fileName);
bufferedReader=new BufferedReader(fileReader);
try{
String read=null;
while((read=bufferedReader.readLine())!=null){
result=result+read+"\r\n";
}
}
catch(Exception e){
e.printStackTrace();
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
if(bufferedReader!=null){
bufferedReader.close();
}
if(fileReader!=null){
fileReader.close();
}
}
System.out.println("读取出来的文件内容是:"+"\r\n"+result);
return result;
}
}
1.Java语言不熟练,不能迅速编写