0

Still need a little help on this program I'm making

Here's the link: https://code.sololearn.com/c9KwbA5EqgOk/#java Alright, still need a little help on this program. I've decided to try to add in passwords. That's working fine but I don't know if that's how I should implement passwords, especially in a program like this. Not only that, there is still some improvements that still need to be made here. 1. I need this program to support more than one account at one time. Like, if the user says he wants to access an existing account, he exits out, and then he says he wants to add in a new account while keeping data from the old account simultaneously. How can I make it so the user can add as many accounts as he wants? Obviously, the user isn't going to have like 100 accounts with a bunch of data each. So, maybe it's reasonable to have a cap on there, but I don't know. I don't know what I'm doing. 2. I don't know how to use files in Java. I learned about it but it's a bit confusing on how to use it and call it and store data in them. 3. The password and password validation thing I decided to add in still needs some refinement. I don't know if I should just make the passwords include any character or restrict it to a 4-pin number kinda how real banks ask you. But, I don't know how to make the program check to see if the password is only numbers and doesn't include letters and see if it's the size of 4 numbers. I don't know. I want to hear from those who actually know what they're doing and help me complete my first real "project".

19th Jul 2017, 12:45 AM
Dishoungh White
Dishoungh White - avatar
1 ответ
+ 1
So, I'm not looking through your code but hopefully me giving you some info on ways to accomplish those improvements can help. 1) Adding many accounts can be done with OOP. Here's an example of how it can be done. Lets say I have a class called Client. That class has the following instance variables: String userName, String password, String surName. I can use a constructor to initialize these fields when the Client Object is created. Once the client object is created. That's an object that stores all that clients info. Now, if I create another object and do the same thing with different passwords. Voila, still different than the first client. If the user wants to check in an account, one method I could do is use a list, storing all Client objects. Then I search through the list to see if the username is equal to any of those (as an example). If it is, I ask and conpare the passwords of that account. 2) To write to a text file you can use a printWriter. Creating a PrintWriter: PrintWriter example = new PrintWriter(new FileWriter(File)); (All in Java.io) Then you can use things like print() or println() to write to the file. Encrypting the file or whatev is another story, but that's a way to practically save the information even when the program is not running. (This means when you load the program you'll need to read the file) Basically all info in the list will be read/printed from. To print all info of a Client you can make a toString() method. That would just return a string containing all the information needed of the object. 3) You can check to see if a String is only numbers by trying to convert it to a number! try{ int test = Integer.parseInt(pass); //ALL numbers } catch(ArithmeticException){ //NOT ALL Numbers } Depending how many characters the pass is, you may want to use a long. Or check character by character instead of casting. Checking a strings size can be done by the length() method. if (myString.length() == 4){ // size of 4 characters } Hopefully s
19th Jul 2017, 2:52 AM
Rrestoring faith
Rrestoring faith - avatar