0
package BankingSystem;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Bank {
public static void main (String [] args){
//User verifies Account
SignIn Valid = new SignIn();
Valid.AccountLogin();
Scanner choice = new Scanner (System.in); //allow user to choose menu option
int option = 0; //Menu option is set to 0
// Menu For User
do{
System.out.println("Welcome");
System.out.println();
System.out.println("1:Deposit Cash");
System.out.println("2: Withdraw Cash");
System.out.println("3: View Current Account Balance");
System.out.println("4: View Saving Account Balance");
System.out.println("5: Cancel"); //When the User Quits the system prints out GoodBye
System.out.println("Please choose");
option= choice.nextInt();
}while (option < 6);
}
}
AccountLoginClass:
package BankingSystem;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SignIn {
public void AccountLogin(){
List<String> AccountList = new ArrayList<String>();
AccountList.add("45678690");
Scanner AccountInput = new Scanner(System.in);
System.out.println("What is your account number?");
AccountInput.next();
boolean isExist = false;
for (String item : AccountList){
if (AccountInput.equals(AccountList.get(0))){
System.out.println("Hi");
isExist = true;
break;
}
}
if (isExist){
//Found In the ArrayList
}
}
}
我想創建一個相當複雜的銀行系統。在這裏,我希望用戶輸入他們的賬號,希望與陣列列表匹配,並且當它與ArrayList中的號碼匹配時,它們與菜單一起顯示,例如退出,存款等。
這裏的問題是我我不知道我怎麼能做到這一點,我創建一個對象之前,它與AccountLoginClass鏈接它的菜單,但這並不真正的工作。
你覺得呢'AccountInput.next();'呢?文檔的哪一部分讓你這麼想? – Pshemo
我在類似的答案中看到了它,所以我決定只是把它放進去。 – Ahmed
但是你認爲它有什麼作用(我在問,因爲它可能不正確)? – Pshemo