//基本功能已经完善,文件读取没有问题,文件重写尚未完成。
Account类
public class Account {
//初始化参数
private String accountID;
private String accountname;
private String operatedate;
private int operatetype;
private String accountpassword;
private int accountbalance=0;
private int amount;
//构造读取和设置变量信息的方法
public void setAccountID(String accountID) {this.accountID=accountID;}
public String getAccountID() {return accountID;}
public void setAccountname(String accountname) {this.accountname=accountname;}
public String getAccountname() {return accountname;}
public void setOperatedate(String operatedate) {this.operatedate=operatedate;}
public String getOperatedate() {return operatedate;}
public void setOperatetype(int operatetype){this.operatetype=operatetype;}
public int getOperatetype() {return operatetype;}
public void setAccountpassword(String accountpassword) {this.accountpassword=accountpassword;}
public String getAccountpassword() {return accountpassword;}
public void setAccountbalance(int accountbalance) {this.accountbalance=accountbalance;}
public int getAccountbalance() {return accountbalance;}
public void setAmount(int amount) {this.amount=amount;}
public int getAmount() {return amount;}
//构造方法有参数
public Account(String accountID,String accountname,String operatedate,int operatetype,String accountpassword,int accountbalance,int amount) {
this.accountID=accountID;
this.accountname=accountname;
this.operatedate=operatedate;
this.operatetype=operatetype;
this.accountpassword=accountpassword;
this.accountbalance=accountbalance;
this.amount=amount;
}
//构造方法无参数
public Account() {}
//参数统一类型
public String toString() {
return (accountID+" "+accountname+" "+operatedate+" "+operatetype+" "+accountpassword+" "+accountbalance+" "+amount);
}
}
AccountManager类
//20173685 任伟强 信1705-2 import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.util.Scanner; public class AccountManager extends Account{
//继承父类
public AccountManager(String accountID,String accountname,String operatedate,int operatetype,String accountpassword,int accountbalance,int amount) {
super(accountID,accountname,operatedate,operatetype,accountpassword,accountbalance,amount);
}
public AccountManager() {
}
//全局定义
static Account a=new Account();
static Scanner s=new Scanner(System.in);
//选择
public static void main(String[]args) {
try {
fileout();
waterout();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
if(loginAccount()&&loginPwd()) {
Menu();
String option;
do {
option=s.next();
switch(option) {
case"1": handmoney();break;
case"2": getmoney();break;
case"3": moneygogogo();break;
case"4": update();break;
case"5": moneyhere();break;
case "q": ;break;
default: System.out.println("错误,请重新输入!\n");
}}while(!"q".equals(option));
System.out.println("成功退出系统!\n");}
} catch (IOException e) {
e.printStackTrace();
}
}
//读取账户基本信息库
public static void fileout() throws FileNotFoundException {
try {
FileReader fr=new FileReader("D:\\eclipse\\eclipse\\Account\\src\\accountinformation.txt");
Scanner sc=new Scanner(fr);
while(sc.hasNext()) {
a.setAccountID(sc.next());
a.setAccountname(sc.next());
a.setAccountpassword(sc.next());
a.setAccountbalance(sc.nextInt());
}
sc.close();
fr.close();
} catch (IOException e) {
System.out.println("文件导出成功\n");
}
}
//读取账户流水信息库
public static void waterout() throws FileNotFoundException {
try {
FileReader fr=new FileReader("D:\\eclipse\\eclipse\\Account\\src\\accountlist.txt");
Scanner sc=new Scanner(fr);
while(sc.hasNext()) {
a.setAccountID(sc.next());
a.setAccountname(sc.next());
a.setOperatedate(sc.next());
a.setOperatetype(sc.nextInt());
a.setAmount(sc.nextInt());
}
sc.close();
fr.close();
} catch (IOException e) {
System.out.println("文件导出成功\n");
}
}
//导入账户基本信息库
public static void filein() throws IOException {
int i;
FileReader fr=new FileReader("D:\\eclipse\\eclipse\\Account\\src\\accountinformation.txt");
FileWriter fw=new FileWriter("D:\\eclipse\\eclipse\\Account\\src\\accountinformation.txt");
i=fr.read();
while(i!=-1) {
fw.write(i);
fr.read();
}
fr.close();
fw.close();
}
//导入账户基本信息库
public static void waterin() throws IOException {
int i;
FileReader fr=new FileReader("D:\\eclipse\\eclipse\\Account\\src\\accountlist.txt");
FileWriter fw=new FileWriter("D:\\eclipse\\eclipse\\Account\\src\\accountlist.txt");
i=fr.read();
while(i!=-1) {
fw.write(i);
fr.read();
}
fr.close();
fw.close();
}
//打印菜单
public static void Menu(){
StringBuffer s=new StringBuffer("\n");
s.append("\t*************************************************\n");
s.append("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
s.append("\t*************************************************\n");
s.append("\t\t\t1.存款;\n");
s.append("\t\t\t2.取款;\n");
s.append("\t\t\t3.转账汇款;\n");
s.append("\t\t\t4.修改密码;\n");
s.append("\t\t\t5.查询余额;\n");
s.append("\t*************************************************\n");
s.append("\t(输入q退出系统)\n");
s.append("请操作\n");
System.out.println(s);
}
//打印登陆账号界面
public static boolean loginAccount() throws IOException {
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t请输入您的账号:\n");
String checkAccount = s.next();
if (a.getAccountID().equals (checkAccount)){
System.out.println("输入账号成功,系统跳转到输入密码界面\n");
return true ;
}else {
System.out.println("该账号不存在\n");
return false ;
}
}
//打印登陆密码界面
public static boolean loginPwd() throws IOException {
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
for (int i = 3 ;i>0;i--){
System.out.println("\t\t请输入您的密码:\n");
String checkPwd = s.next();
if (a.getAccountpassword().equals (checkPwd)){
System.out.println("输入密码成功,系统跳转到主界面!\n");
return true ;
}else {
if ( i ==1 ){
System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理\n");
return false ;
}
System.out.println("密码录入错误!今日剩余次数:"+ (i-1));
}
}
return false; }
//存款
private static void handmoney() {
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t请输入存款金额:\n");
int number=s.nextInt();
a.setAccountbalance(a.getAccountbalance() + number);
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t当前账户存款操作成功\n");
System.out.println("\t\t当前账户余额为"+a.getAccountbalance()+"元\n");
System.out.println("\t*************************************************\n");
Menu();
System.out.println("\t\t请继续操作\n");
}
//取款
public static void getmoney() {
a.setAccountbalance(a.getAccountbalance());
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t当前账户每日可以支取2万元\n");
System.out.println("\t\t1.100元\n");
System.out.println("\t\t2.500元\n");
System.out.println("\t\t3.1000元\n");
System.out.println("\t\t4.1500元\n");
System.out.println("\t\t5.2000元\n");
System.out.println("\t\t6.5000元\n");
System.out.println("\t\t7.其他金额\n");
System.out.println("\t\t8.退卡\n");
System.out.println("\t\t9.返回\n");
System.out.println("\t*************************************************\n");
int num1=100,num2=500,num3=1000,num4=1500,num5=2000,num6=5000;
int str=s.nextInt();
if (a.getAccountbalance() <str ){
System.out.println("账户余额不足!!\n");
str=0;
}else if(str==1){
a.setAccountbalance(a.getAccountbalance() - num1);
}else if(str==2){
a.setAccountbalance(a.getAccountbalance() - num2);
}else if(str==3){
a.setAccountbalance(a.getAccountbalance() - num3);
}else if(str==4){
a.setAccountbalance(a.getAccountbalance() - num4);
}else if(str==5){
a.setAccountbalance(a.getAccountbalance() - num5);
}else if(str==6){
a.setAccountbalance(a.getAccountbalance() - num6);
}else if(str==7){ str=s.nextInt();
a.setAccountbalance(a.getAccountbalance() - str);
}else if(str==8){
System.out.println("退卡成功\n");
}else if(str==9){
System.out.println("返回成功\n");
}
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t当前账户存款操作成功\n");
System.out.println("\t\t当前账户余额为"+a.getAccountbalance()+"元\n");
System.out.println("\t*************************************************\n");
Menu();
} //转账汇款
public static void moneygogogo() {
a.setAccountbalance(a.getAccountbalance());
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t请输入转账账户\n");
String str=s.next();
if(a.getAccountID().equals(str)) {
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t请输入转账金额\n");
int num=s.nextInt();
if(a.getAccountbalance()<=num){
System.out.println("账户余额不足\n");
}else {
a.setAccountbalance(a.getAccountbalance() - num);
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t当前账户向"+a.getAccountID()+"成功转账"+str+"元");
System.out.println("\t\t当前账户余额为"+a.getAccountbalance()+"元\n");
System.out.println("\t*************************************************\n");
}
}
Menu();
}
//修改密码
public static void update() throws IOException {
fileout();
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t请输入当前密码:\n");
String str=s.next();
if(!a.getAccountpassword().equals(str)) {
System.out.println("当前密码录入错误");
}else {
System.out.println("\t\t请输入修改密码:\n");
String str1=s.next();
System.out.println("\t\t请输入确认密码:\n");
String str2=s.next();
if(!str1.equals(str2)) {
System.out.println("修改密码与确认密码不一致\n");
}else {
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.println("\t\t当前账户密码修改成功");
System.out.println("\t*************************************************\n");
}
}
Menu();
}
//查询余额
public static void moneyhere() {
System.out.println("\t*************************************************\n");
System.out.println("\t 欢迎全世界最有钱的人使用中国工商银行自助柜员系统\n");
System.out.println("\t*************************************************\n");
System.out.print("\t\t当前账户余额为"+a.getAccountbalance()+"元\n");
System.out.print("\t\t账户清单信息为:\n");
System.out.print("\t\t操作日期"+a.getOperatedate()+" 操作类型"+a.getOperatetype()+"操作金额"+a.getAmount()+"\n");
System.out.println("\t*************************************************\n");
Menu();
}
}