import java.util.*;
public class Jatm{
static String user = "123";
static String password = "123456";
static int sum = 5000;
static Scanner in = new Scanner(System.in);
//主函数
public static void main(String[] args) {
Jatm atm = new Jatm();
atm.login();
atm.mains();
}
//登录
public static void login(){
System.out.println("**************************");
System.out.println("***欢迎登录中华大衡银行***");
System.out.println("请输入用户名:");
String name = in.nextLine();
System.out.println("请输入密 码:");
String pw = in.nextLine();
if(name.equals(user) && pw.equals(password)){
System.out.println("登录成功!");
//mains();
}else{
System.out.println("登录失败,用户名或密码错误!请重新登录");
login();
}
}
//主页面
public static void mains(){
System.out.println("**************************");
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("请选择:");
int n = in.nextInt();
switch(n){
case 1: search();
break;
case 2: add();
break;
case 3: get();
break;
case 4: change();
break;
case 5: exit();
break;
default:
System.out.println("选择错误,请重新选择:1--5数字");
mains();
break;
}
}
//查询
public static void search(){
System.out.println("您的账户余额为:"+sum+"元");
mains();
}
//存款
public static void add(){
System.out.println("请输入存款金额:");
int counts = in.nextInt();
sum+=counts;
System.out.println("存款成功!");
mains();
}
//取款
public static void get(){
System.out.println("请输入取款金额:");
int counts = in.nextInt();
if(counts>=sum){
System.out.println("您的余额不足,请输入取款金额:");
get();
}else{
sum-=counts;
System.out.println("取款成功!");
mains();
}
}
//改密
public static void change(){
Scanner in = new Scanner(System.in);
System.out.println("请输入原密码:");
String oldpw =in.nextLine();
if(oldpw.equals(password)){
System.out.println("请输入新密码:");
String newpw = in.nextLine();
password = newpw;
System.out.println("密码修改成功");
mains();
}else{
System.out.println("原密码错误!");
change();
}
}
//退出
public static void exit(){
Scanner in = new Scanner(System.in);
System.out.println("确定退出?(yes/no):");
String conf = in.nextLine();
if(conf.equals("yes")){
System.out.println("请慢走,欢迎下次光临!");
}else if(conf.equals("no")){
mains();
}else{
System.out.println("没有此选项哟!");
mains();
}
}
}