?? 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 + -