📄 view.java
字号:
package view;
import biz.Bank;
import biz.BankImpl;
import com.kettas.common.SystemIn;
import entity.Account;
import exception.AccountNotExistException;
import exception.BalanceNotEnoughException;
import exception.RegisterException;
public class View {
Bank bank=new BankImpl();
long id;
public void main(){
System.out.println("1:注册");
System.out.println("2:登陆");
System.out.println("请输入您的选择:");
int a=SystemIn.readInt();
if(a==1){
register();
}
if(a==2) {
login();
}
}
void register(){
//(String personId,
// String password, String password2,String name,int type) throws RegisterException;
System.out.println("请输入您的身份证号:");
String personId=SystemIn.readString();
System.out.println("请输入您的帐户密码:");
String password=SystemIn.readString();
System.out.println("请再次输入您的帐户密码:");
String password2=SystemIn.readString();
System.out.println("请输入您的姓名:");
String name=SystemIn.readString();
System.out.println("请输入您的帐户类型,1为普通帐户,2为信用帐户");
int type=SystemIn.readInt();
try {
id=bank.register(personId, password, password2, name, type);
} catch (RegisterException e) {
System.out.println(e.getMessage());
}
System.out.println("注册成功,卡号是:"+id);
biz();
}
void login(){
System.out.println("请输入您的卡号:");
String iid=SystemIn.readString();
long cardId=Long.parseLong(iid);
System.out.println("请输入您的帐户密码:");
String password=SystemIn.readString();
try {
id=bank.login(cardId, password);
} catch (AccountNotExistException e) {
System.out.println(e.getMessage());
}
if(id!=-1) {
System.out.println("登陆成功");
biz();
}
else System.out.println("登陆失败");
}
void biz(){
System.out.println("1:存钱");
System.out.println("2:取钱");
System.out.println("3:查询");
System.out.println("4:返回");
int i=SystemIn.readInt();
if(i==1){
System.out.println("请输入存多少钱:");
int money=SystemIn.readInt();
bank.deposit(id, money);
biz();
}
else if(i==2){
System.out.println("请输入取多少钱:");
int money=SystemIn.readInt();
try {
bank.withDraw(id, money);
} catch (BalanceNotEnoughException e) {
System.out.println(e.getMessage());
}
biz();
}
else if(i==3){
System.out.println("你的余钱为:"+bank.select(id));
biz();
}else{
main();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -