银行项目,如何在阵列中存储帐户的阵列问题

时间:2018-12-22 19:05:31

标签: java arrays multidimensional-array

这是我的代码的示例 我的问题是如何创建一个帐户而不一次输入50个帐户,例如,如果我只想保存10个帐户并确保这些帐户没有写在上面,那么谢谢

public static void main(String[] args) {
                   Scanner keyboard = new Scanner (System.in);
                   String Administrator = "Amro" ;
                   String Password = "1234567";
    System.out.println("login the bank system ");
    System.out.println("1- login as Administrator ");
    System.out.println("2- login as a user ");
    System.out.println("3- Exit ");
    int x = keyboard.nextInt() ;
    switch(x){
        case 1 :               
            System.out.println("Enter username :");
            String username = keyboard.next();
            System.out.println("Enter Password :");
            String password = keyboard.next();
            if(username.equals(Administrator) && password.equals(Password)){
             System.out.println("Enter type of operation :");
                }else{ System.out.println("ERORR!!!!");
                   System.exit(0);}               
            boolean isRunning = true;
            while(isRunning){
             System.out.println("1- Create a new account");
              System.out.println("2- Deposit an amount in the account");
               System.out.println("3- Withdraw an amount in the account");
                System.out.println("4- Modify the customer data");
                 System.out.println("5- Delete the bank account");
                  System.out.println("6- Search for a bank account");
                   System.out.println("7- View all bank account");
                    System.out.println("8- Go back");
                    int y = keyboard.nextInt();
                    switch(y){
                        case 1:
                        String Info [][] = new String [50][5];
                           System.out.println("*Create a new account*");
                           for(int i=0;i<+Info.length;i++ ){
                                for(int j=0;j<1;j++){
                            System.out.println("Customer ID number :");
                           Info [i][j] = keyboard.next();
                           System.out.println("Customer Name :");
                           Info [i][j+1] = keyboard.next();
                           System.out.println("Customer password :");
                           Info [i][j+2] = keyboard.next();
                           System.out.println("Customer's phone number :");
                           Info [i][j+3] = keyboard.next();
                                }
                           }
  //                   for(int i=0;i<Info.length;i++ ){
  //                   for(int j=0;j<1;j++){
  //                  System.out.println(Info [i][j]);  
  //                   System.out.println(Info [i][j+1]);
  //                   System.out.println(Info [i][j+2]);
  //                   System.out.println(Info [i][j+3]);
  //                                      }
                   //                }
                   }

                  }
                  }
              }
          }

1 个答案:

答案 0 :(得分:0)

要在此处更改帐户条目的数量,您将更新以下现有行:

String Info [][] = new String [50][5];

例如,如果您想输入10个帐户,则可以将其更改为:

String Info [][] = new String [10][5];

如果您希望用户输入计划输入的帐户数量,则可以使用:

int z = keyboard.nextInt();
String Info [][] = new String [z][5];