package ATM;
//信1705-3 20173517 赵家明
import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
@SuppressWarnings("unused")
public class ATM {
public static void main(String[] args) {
// 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<Account> atm=new ArrayList<Account>();
ArrayList<FileOperation> x=new ArrayList<FileOperation>();
FileOperation f= new FileOperation();
int select=1;
for(;;)
{
do
{
select=input.nextInt();
}while(select<1||select>5);
switch(select)
{
case 1:withdraw(atm);break;
case 2:deposit(atm);break;
case 4:change();break;
}
input.close();
}
}
public static void deposit(){
System.out.println("请输入存款金额");
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
int amount=in.nextInt();
int accountbalance=in.nextInt();
if(amount<0){
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<Account> 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<Account> 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<0){
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");
}
}
}
package ATM;
//信1705-3 20173517 赵家明
public class Account {
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)
{
accountID=a;
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;
}
public String get_accountID()
{
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;
}
}
package ATM;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.RandomAccessFile;
@SuppressWarnings("unused")
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;
}
public static void contentToTxt(String filePath, String content) {
String str = new String(); //原有txt内容
String s1 = new String();//内容更新
try {
File f = new File(filePath);
if (f.exists()) {
System.out.print("文件存在");
} else {
System.out.print("文件不存在");
f.createNewFile();// 不存在则创建
}
BufferedReader input = new BufferedReader(new FileReader(f));
while ((str = input.readLine()) != null) {
s1 += str + "\n";
}
System.out.println(s1);
input.close();
s1 += content;
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
问题:
1.Java语言不熟练,不能迅速编写
2.文件导入出现问题
3.总会忘掉实例化
4.不够专注,不能静心
最后日常催眠,热爱Java!
原文地址:https://www.cnblogs.com/zjm15511858030/p/9687997.html