package bank;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class accountManagement {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw =new PrintWriter(new FileWriter("D:\\myIDEA\\ExperimentTen\\jilu.txt"),true);
User u = new User();
while (true) {
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("请输入你选择:");
int x = sc.nextInt();
switch (x) {
case 1:
System.out.println("账号:"+u.getID());
pw.println("显示账号:"+u.getID());
break;
case 2:
System.out.println("余额:"+u.getBalance());
pw.println("显示余额:"+u.getBalance());
break;
case 3:
System.out.println("请输入你的金额:");
int b = sc.nextInt();
u.setBalance(u.getBalance()+b);
pw.println("存款:"+b);
pw.println("余额:"+u.getBalance());
break;
case 4:
System.out.println("请输入你的金额:");
int c = sc.nextInt();
u.setBalance(u.getBalance()-c);
if (u.getBalance()-c<0){
System.out.println("你的余额不足!");
break;
}
pw.println("取款"+c);
pw.println("余额:"+u.getBalance());
break;
case 5:
System.out.println("谢谢使用!");
pw.println("退出");
System.exit(0);
}
}
}
}
package bank;
public class User {
private String ID="123456";
private int balance;
public User(){}
public User(String ID , int balance){
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public void setBalance(int balance) {
this.balance = balance;
}
public int getBalance() {
return balance;
}
}