ObjectiveYou work for a company called Lock Up Tite. They want you to write a front end program to grant authentication access to programs using a user name and password. Requirements Write a program that creates a loop and has three options for the user to select.
Option 1 allows the user to add a user name and password, which is then stored into a file.
Option 2 allows the user to enter a user name and password up to three times. For a given attempt, the user will be notified if the attempt is successful or unsuccessful.
Option 3 will exit the loop and end the program Main Menu Requirements: When the program starts, present the user with a menu offering the three options described above. After the user chooses either option 1 or 2, the program should go back to the main menu. The final option will end the program.
Option 1 Requirements:This option prompts the user for their user name and password and stores them in a file named passwords.txt. The program should not overwrite what's already in the file; it should append the new user name and password to the end of the file.
Option 2 Requirements:This option uses the passwords.txt file to verify the user is entering a valid user name and password. It begins by asking the user for a user name and password within a loop that runs up to three times. If the password is correct, an appropriate message will be printed, the loop will end, and the program will go back to the main menu. If the user is unable to provide a user name and password that matches any of the combinations in the file, an appropriate message will be printed and the user will be allowed to try again. If the user fails after three attempts, the loop should end and the program should go back to the main menu.
1. Create a Java program named LockUpTite.java.
2. Create a procedure for each major task in the program. Call the procedures based on the option selected by the user.
3. After completing the tasks of Option 1 or 2, re-display the menu and allow the user to pick another option. Option 3 will exit the program.
4. Make sure your program is adequately commented, uses consistent naming conventions for variable and module names, and uses appropriate indentation and line spacing to enhance the readability of the code.
Instructions Follow these instructions as you build your program:
1. Create the LockUpTite.java class and create a main() method.
2. In the main() method, create a try-catch block. Within the try block, get the path to theplayers.txt file. While you can do this many different ways, the easiest approach is to put all your files in the same folder and use Path filePath = Paths.get("players.txt"); If you use an IDE that keeps .java and .class files in a separate folder, then use the following approach: Path filePath = Paths.get("players.txt").toAbsolutePath();
3. You may want to declare this variable outside of the main() method but within the class so that the other functions you build can use it.
4. For the function that responds to Option 2, you should do the following:
(a) Ask the user for a username and password.
(b) Create a Boolean variable to indicate a successful login, and set it to false.
(c) Open the players.txt file by creating a BufferedReader object. Call theFiles.newBufferedReader() method and pass it the BufferedReader reader = Files.newBufferedReader(filePath); NOTE: If you are using Java 7, this technique will not work. Instead, you must send two arguments, aPath and a Charset. So if you are using
Java 7, you will need to do the following:
import java.nio.charset.Charset; Create your Path object as outlined above. Then when you create the BufferedReader: BufferedReader reader = Files.newBufferedReader(filePath, Charset.forName("UTF-8"));
1. Create a String named line, and assign it to reader.readLine(), where reader is the name of theBufferedReader object you created in step 4.
2. Create a while loop that will continue as long as line is not NULL and a match has not been found.
(a) Within the loop, use the line object’s split() method to break the String into two pieces, both of which should be stored in a String array.
(b) Check the name and password for a match. The user name taken from the file will be stored in the first element of the array; the password will be in the second. If both match, set Boolean to true.
(c) Assign line to the next line of text in the file by calling reader.readLine().
3. Below the while loop, check the Boolean variable. If it is true, then a match was found. If not, bump a counter to give the user a second chance unless the value of the counter has exceeded three increments.
4. Within the catch block, print out the Exception object’s error message.
Order Now and get your work!