Java 第一周源程序

package ATM;

public class Account {
private String accountID,accountname,operatedate,accountpassword;
private int operatetype,accountbalance=0,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 String getAccountpassword() {
return accountpassword;
}
public void setAccountpassword(String accountpassword) {
this.accountpassword = accountpassword;
}
public int getOperatetype() {
return operatetype;
}
public void setOperatetype(int operatetype) {
this.operatetype = operatetype;
}
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;
}

}

package ATM;
import java.util.Scanner;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
public class AccountManager {
static Scanner input=new Scanner(System.in);

public static void createFile(){//创建文件1

//path表示你所创建文件的路径
String path = "D:\\workspace\\ATM";
File f = new File(path);
if(!f.exists()){
f.mkdirs();
}
// fileName表示你创建的文件名;为txt类型;
String fileName="accountinformation.txt";
File file = new File(f,fileName);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void createFile1(){//创建文件2

//path表示你所创建文件的路径
String path = "D:\\workspace\\ATM";
File f = new File(path);
if(!f.exists()){
f.mkdirs();
}
// fileName表示你创建的文件名;为txt类型;
String fileName="accountlist.txt";
File file = new File(f,fileName);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

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

}
}
static void getzh()//功能一:输入账号;
{
String s;
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入您的账号: ");
System.out.println("**************************");
s=input.next();
if(s.length()!=8)
{
System.out.println("该卡不是工行卡");
getzh();
}
else getmm();
}


static void getmm()//功能输入密码
{
String s;
int j=0;
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入您的密码:");
System.out.println("**************************");
s=input.next();
for(int i=0;i<3;i++)
{
if(s.length()!=6)
{
System.out.println("密码录入错误");
getmm();
if(i==2)
{
System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");
getzh();
}
j++;
}

}
if(j!=3)
{
show();
}
}



static void cunkuan()//功能存款
{
int x;
String y;
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入存款金额:");
System.out.println("**************************");
y=input.next();
if(y=="q")
{
getzh();
}
else if(Float.parseFloat(y)>0||Float.parseFloat(y)%(int)Float.parseFloat(y)!=0)
{
System.out.println("输入金额有误");
qukuan();
}
else
{
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 当前账户存款操作成功 ");
System.out.println(" 当前账户余额为:XXXX元");
System.out.println("**************************");
}
}



static void qukuan()//功能取款
{
int x=0;
int y=0;
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
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("**************************");
x=input.nextInt();
switch(x)
{
case 7:
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入存款金额 ");
y=input.nextInt();
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 当前账户取款操作成功 ");break;
case 8:getzh();break;
case 9:show();break;
}
}
static void zzhk()//功能转账汇款
{
String x,z;
int y;
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入转账账户 ");
x=input.next();
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入转账账金额 ");
y=input.nextInt();
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请确认是否向"+x+"转账"+y+"元。 ");
z=input.next();
if(z=="N")
{
System.out.println("转账失败");
show();
}
else
{
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 当前账户向"+x+"转账"+y+"元。 ");
}
String k;
k=input.next();
if(k=="q")getzh();
}

static void xgmm()
{
String x,y;
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 请输入当前密码: ");
System.out.println(" 请输入修改密码: ");
System.out.println(" 请输入确认密码: ");
x=input.next();
y=input.next();
y=input.next();
System.out.println("**************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统 ");
System.out.println("**************************");
System.out.println(" 当前账户密码修改成功 ");
y=input.next();
if(y=="q")getzh();
}
static void show()//主界面
{
int x;
System.out.println("**************************");
System.out.println("欢迎xxxx使用中国工商银行自助柜员系统");
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("**************************");
System.out.println("**************************");

x=input.nextInt();
switch(x)
{
case 1: cunkuan();break;
case 2: qukuan();break;
case 3:zzhk();break;
case 4:xgmm();break;
}
}


public static void main(String[] args) {
// TODO Auto-generated method stub
createFile();
createFile1();

/*try { // 防止文件建立或读取失败,用catch捕捉错误并打印,也可以throw
/* 写入Txt文件 */
/* File writename = new File("D:\\\\workspace\\\\ATM"); // 相对路径,如果没有则要建立一个新的output。txt文件
writename.createNewFile(); // 创建新文件
BufferedWriter out = new BufferedWriter(new FileWriter(writename));
out.write("我会写入文件啦\r\n"); // \r\n即为换行
out.flush(); // 把缓存区内容压入文件
out.close(); // 最后记得关闭文件

} catch (Exception e) {
e.printStackTrace();
}*/
//contentToTxt("accountlist.txt","D:\\workspace\\ATM" );
getzh();
}

}

猜你喜欢

转载自www.cnblogs.com/liyuchao/p/9697297.html