在ArrayList中存储名称并使用它登录

我有一个任务要做,其中包括要求用户输入他们的姓,并给用户一个账号登录到程序。 我列出了下面可能更有意义的步骤。

1)用户创建一个帐户

2)用户输入他们的姓氏(存储到数组列表中)

3)给用户一个帐号(存入数组列表)

4)然后用户可以使用他们的姓氏和帐号登录(检查姓氏和帐号的arraylist,如果匹配,则登录消息,如果没有错误消息)

用户输入他们的姓氏,并给他们一个帐号,然后他们使用它登录以存款,取款和查看余额。

我如何创建一个程序来做到这一点,而不使用数据库?

帐户类

private static int number = 500;

    Account(){
        accountNumber = number++;
    }

创建帐号

public void createAccount(){

String firstName;

System.out.print("Please Enter Last Name: ");
lastName = scanner.nextLine();
System.out.println("This is your Account Number to log into: " + _______ );
}

public void logIn(){

    System.out.println("Please enter your last name: ");

    System.out.println("Please enter your account number: ");

}

我想建议使用xml来存储凭据的另一种方法遵循以下步骤

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
      {
            string username;
            string pwd;
            string CurrentUser = "";
            string CurrentPwd = "";
            bool LoginStatus = false;
            username = Login1.UserName;
            pwd = Login1.Password;
            XmlDocument xmxdoc = new XmlDocument();
            xmxdoc.Load(Server.MapPath("Register.xml"));
            XmlNodeList xmlnodelist = xmxdoc.GetElementsByTagName("user");
            foreach (XmlNode xn in xmlnodelist)
            {
                  XmlNodeList xmlnl = xn.ChildNodes;
                  foreach (XmlNode xmln in xmlnl)
                  {
                        if (xmln.Name == "Name")
                        {
                              if (xmln.InnerText == username)
                              {
                                    CurrentUser = username;
                              }
                        }
                        if (xmln.Name == "Password")
                        {
                              if (xmln.InnerText == pwd)
                              {
                                    CurrentPwd = pwd;
                              }
                        }
                  }
                  if ((CurrentUser != "") & (CurrentPwd != ""))
                  {
                        LoginStatus = true;
                  }
            }
            if (LoginStatus == true)
            {
                  Session["UserAuthentication"] = username;
                  Session.Timeout = 1;
                  Response.Redirect("welcome.aspx");
            }
            else
            {
                  Session["UserAuthentication"] = "";
            }
      }

在你的xml文件中

<user>
  <Name>smashcode</Name>
  <Password>smashcode</Password>
</user>

我想这比采用数组列表的方法更好

如果你想尝试使用数组列表的步骤

第1步: username_list{uesr1,user2,user3}

  password_List{pass1,pass2,pass3}

步骤:按照以下步骤检查在循环中输入用户标识和密码的所有条目

     int flag = 0;
     while(username_list.get(i)!=null)
       {

           if((username_list.get(i).equals(enteredusername))&&((password_list.get(i).equals(enteredpassword)))
             {
                flag = 1;
             }
       }

if(flag==1)
 {
    System.out.println("login successful ");
    Response.Redirect("welcome.aspx");
 }
   I had written second code implementation in cut short 

希望我的工作会有所帮助。保持编码


这里没有一个完整的答案,但一些建议....

你可以创建一个“银行”类......它可能拥有帐户的数组列表,也可以持有
创建帐号()

delAccount()

findAccount()...

等等等等

张贴这个我现在看到它是一个答案,我的坏人


我假设你需要在执行完成后能够保存这些信息,这意味着除了正在运行的程序之外,还需要存储信息。

在我的头顶,你可以使用一个文件来存储这个信息存储,其中每一行文件将等于姓氏 - 帐号的匹配。 在打开程序时,你阅读文件。 尝试阅读:

  • http://www.tutorialspoint.com/java/java_files_io.htm或
  • https://docs.oracle.com/javase/tutorial/essential/io/file.html
  • 该解决方案与使用数据库类似,所以我不知道它是否会执行。 希望它。

    链接地址: http://www.djcxy.com/p/40791.html

    上一篇: Storing Names in ArrayList and Using it to Login

    下一篇: Having trouble deep cloning an object in a linked list