import java.util.Scanner;
class Test5{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请设置您的账号密码");
Bank b = new Bank();
String s= sc.nextLine();
b.setName(s);
String s1= sc.nextLine();
b.setPassword(s1);
b.load(b);
System.out.println("请设置您的账号密码");
Bank b1 = new Bank();
String s3= sc.nextLine();
b1.setName(s3);
String s4= sc.nextLine();
b1.setPassword(s4);
b1.load(b1);
System.out.println(b.balance+" "+b1.balance);
}
}
class Bank{
private String name;
private String password;
int sum =0;
int balance =100;
public void setName(String name){
this.name = name;
}
public void setPassword(String password){
this.password = password;
}
public String getName(){
return name;
}
public String getPassword(){
return password;
}
public void load(Bank b){
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的账号密码");
String s =sc.nextLine();
String s1 =sc.nextLine();
if (name.equals(s)&&password.equals(s1)){
System.out.println("登录成功");
b.Manu(b);
}
else{
System.out.println("输入错误,请重新输入");
sum++;
if(sum==3){
System.out.println("输错3次,账号冻结");
return;
}
b.load(b);
}
}
public void getMoney(Bank b){
Scanner sc = new Scanner(System.in);
System.out.println("请输入取款金额");
int a = sc.nextInt();
if(balance >=a){
balance = balance -a;
System.out.println("请提走您的现金");
b.Manu(b);
}
else {
System.out.println("您好,余额不够");
b.Manu(b);
}
}
public void keepMoney(Bank b){
Scanner sc = new Scanner(System.in);
System.out.println("请选择存款金额");
int a = sc.nextInt();
balance = balance +a;
System.out.println("您的当前余额为:"+ balance);
b.Manu(b);
}
public void Manu(Bank b){
Scanner sc = new Scanner(System.in);
System.out.println("请选择你所需要的服务");
System.out.println("0, 返回");
System.out.println("1, 存款");
System.out.println("2, 取款");
System.out.println("3, 查询余额");
System.out.println("4, 退卡");
int a = sc.nextInt();
switch(a){
case 0:
b.Manu(b);
break;
case 1:
b.keepMoney(b);
break;
case 2:
b.getMoney(b);
break;
case 3:
b.checkBalance(b);
break;
case 4:
b.getCard();
break;
default:
System.out.println("输入有误");
b.Manu(b);
break;
}
}
public void checkBalance(Bank b){
System.out.println("您的余额为:" + balance);
b.Manu(b);
}
public void getCard(){
System.out.println("谢谢使用,请取卡");
return;
}
}
|
|