📄 textview.java
字号:
package view;
import biz.*;
import com.kettas.common.*;
import Exception.LoginException;
import Exception.RegisterException;
public class TextView {
private IBank bank;
private long currentId;
public TextView(IBank bank){
this.bank=bank;
}
public void showMain() throws LoginException{
System.out.println("-------------------");
System.out.println("1:开户");
System.out.println("2:登录");
System.out.println("3:退出");
System.out.println("-------------------");
System.out.print("请选择");
int choice=SystemIn.readInt();
switch(choice){
case 1:{ kaihu(); break;}
case 2:{ denglu(); break;}
case 3:{ System.exit(0);}
default: showMain();
}
}
public void kaihu() throws LoginException{
int type;
do{
System.out.print("请输入帐户类型(0:储蓄账号1:信用账号):");
type=SystemIn.readInt();
}
while(type!=0 && type!=1);
System.out.print("请输入密码:");
String pass=SystemIn.readString();
System.out.print("再一次输入密码: ");
String pass2=SystemIn.readString();
System.out.print("请输入姓名");
String name=SystemIn.readString();
System.out.print("请输入帐户ID: ");
String personId=SystemIn.readString();
try {this.currentId=bank.regist(name,pass, pass2, personId, type);
if(this.currentId!= -1){
System.out.println("注册成功,您的ID是"+currentId);
jiaoyi();
// showMain();
}
}
catch(Exception e){
e.printStackTrace();
showMain();
}
}
public void denglu() throws LoginException{
System.out.print("请输入帐户ID: ");
long id=SystemIn.readInt();
System.out.print("请输入密码: ");
String pass=SystemIn.readString();
try {
this.currentId=bank.login(id, pass);
} catch (LoginException e) {
e.printStackTrace();
showMain();
}
if( currentId != -1){
System.out.println("您是第 "+currentId+"个使用者");
jiaoyi();
}else{
System.out.println("密码错误");
}
}
public void jiaoyi() throws LoginException{
System.out.println("-------------------");
System.out.println("1: 存钱");
System.out.println("2: 取钱 ");
System.out.println("3: 查询余额");
System.out.println("4: 返回到主菜单");
System.out.println("-------------------");
System.out.print("请选择: ");
int choice=SystemIn.readInt();
if (choice==1){
System.out.print("请输入存钱数额: ");
double money=SystemIn.readDouble();
bank.deposit(this.currentId, money);
jiaoyi();
}
else if (choice==2){
System.out.print("请输入取钱数额: ");
double money=SystemIn.readDouble();
try{
bank.withdraw(this.currentId, money);
jiaoyi();
}
catch(Exception e){
e.printStackTrace();
jiaoyi();
}
// bank.withdraw(this.currentId, money);
}
else if (choice==3){
double b=bank.queryBalance(this.currentId);
System.out.println("你帐户余额为 "+b);
jiaoyi();
}
else if (choice==4){
showMain();
}
else jiaoyi();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -