在這一類的銀行中,存在銀行的基本功能,但真正的問題出現在開關情況循環中。如何在某些情況下已經運行後重新運行開關情況循環
class Bank{
private int Balance;
private int Withdrawal;
private int Deposit;
private int AccountNumber;
void Transaction(){
Scanner input = new Scanner(System.in);
System.out.println("Enter the account number to whose account you want
to transfer money");
AccountNumber = input.nextInt();
System.out.println("Enter your current Balance");
Balance= input.nextInt();
}
void Display(){
System.out.println("Account number "+AccountNumber);
System.out.println("Balance is "+ Balance);
}
void deposit(){
Scanner input = new Scanner(System.in);
System.out.println("Enter the amount to deposit");
int n =input.nextInt();
Balance+=n;
}
void withdraw(){
Scanner input = new Scanner(System.in);
System.out.println("Enter the amount to withdraw");
int n =input.nextInt();
try {
if(n>Balance)
throw new Exception("The balance you have is insufficient");
}
catch(Exception e){
System.out.println(e);
}
}//void
我試圖重新運行開關的情況下循環,輸入查詢一個值之後,我希望它再次詢問用戶的所有選項,我試圖用continue語句,但它表明繼續外循環的錯誤。請幫助
public static void main(String args[])throws Exception{
Bank b1=new Bank();
Scanner input = new Scanner(System.in);
System.out.println("Enter the number corrosponding to your option ");
System.out.println("1 Set ");
System.out.println("2 Display ");
System.out.println("3 Deposit");
System.out.println("4 Withdraw");
System.out.println("5 Exit");
int num=input.nextInt();
switch(num){
case 1:
b1.Transaction();
//int c =input.nextInt();
//wants user to input value again so switch loop works
//again
break;
case 2:
b1.Display();
break;
case 3:
b1.deposit();
break;
case 4:
b1.withdraw();
break;
case 5:
return;
}
}//psvm
}
編程語言是java –