Question

I) will create a rudimentary (and highly insecure) database for the storage of only the user...

I)

will create a rudimentary (and highly insecure) database for the storage of only the user generated identities. This

program will have the following behaviors:

(line break, 11 pt)

) - Prior to prompting for a new username, the existing list of usernames should be read and loaded

to an array.

1 ) Read the list from "users.txt", a prompt is not necessary. Do not change this data file name "users.txt".

2 ) The existing list of usernames should be displayed to the console (screen).

(line break, 11 pt)

username.

) - Upon prompting, the following checks must be made against an attempt to create a new

1 ) Duplicate usernames should be disallowed, and the usernames are case sensitive.

2 ) Usernames must be between 4 and 7 characters in length.

3 ) Username must have lower-case AND upper case.

4) a letter like [a-z A-Z]
5) have at least one number like [0-9]
6) have at least one of these special characters [!, #, ?]

C) (6 / 30 pts.

D) (8 / 30 pts.

-10 pts.

Usernames must start with

Usernames must Usernames must

7) If the rules from 1-6 are violated, an appropriate error message informing the user should be displayed.

i ) The error message should display *all* the reasons why the username is not correct.

ii ) Do not display merely the first problem the program identifies (unless, of course, the first problem is

the only problem).

(line break, 11 pt)

) - When a valid username is provided, this username should be written to an array and displayed

back to console.

(line break, 11 pt)

) - Finally, the "users.txt" database should be updated such that the new username appears should

the program be run again.

(line break, 11 pt)

E) (

) - Include appropriate program documentation and formatting including:

1) Your first and last name

2) Your contact information

3) Your student ID number

4) The date

5) A short description of the program’s function

6) Comments necessary to explain the operation of your program

7) Proper indentation

*Note that your student list may vary from the one below.

List of Usernames

Create a new user: bellevuecollege

(line break, 11 pt)

F) Save your file as “UserNames

.java” and upload to Canvas.(line break, 11 pt)

II ) A Sample log of execution is as follow (user inputs are in bold and underlined):

(line break, 11 pt)

Usernames must have at least one number

Usernames must have at least one number.
Usernames must have at least one special character. Usernames must have lower-case and upper-case.

a letter.

April4!

March3#

June!6

Create a new user: December!

Invalid Name.
Name too long.

  

Invalid Name.
Name too long.

Create a new user: April4!

Invalid Name. Name already in use.

Create a new user: 4!July

Invalid Name. Name must start with

Create a new user: July4!

User "July4!" added successfully!
List of Usernames

April4!

March3#

June!6

July4!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The java code is attached here

UserNames.java

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Pattern;

public class UserNames {
  
   public static void main(String[] args) throws IOException {
      
       File f = new File("users.txt");
      
       //To determine if the string is invalid or valid
       boolean flag = false;
      
       Scanner s = new Scanner(new FileReader(f));
      
       //To store the list of users from text files
       String[] users = new String[100];
      
      
       String user = null;
      
       //Used for indexing through the array
       int i = 0;
       System.out.println("List of Usernames");
      
       while(s.hasNext())
       {
           user = s.nextLine();
           System.out.println(user);
           users[i] = user;
           i++;
       }
      
       Scanner s1 = new Scanner(System.in);

//To open the file in append mode
       BufferedWriter bw = new BufferedWriter(new FileWriter(f,true));
      
       System.out.println("Create a new user: ");
       String userName = s1.nextLine();
      
       for(String us:users)
       {
           if(us!= null && us.equals(userName))
           {
               System.out.println("Invalid Name. Name already in use.");
               flag = true;
           }
       }
      
       //To see that the userName is of valid length
       if(userName.length() < 4 || userName.length() > 7)
       {
           System.out.println("Invalid Name.Name too long");
           flag = true;
       }
      
       //To see if the username has one or more uppercase or lowercase letter
       if(!Pattern.matches(".*[a-zA-Z].*", userName))
       {
           System.out.println("Username doesn't have a lower case or upper case letter");
           flag = true;
       }
      
       //To see if username contains numbers
       if(!Pattern.matches(".*[0-9].*", userName))
       {
           System.out.println("Username doesn't have a number");
           flag = true;
       }
      
       //To see if the userName starts with alphabets
       if(!Pattern.matches(".*^[a-zA-Z].*", userName))
       {
           System.out.println("Invalid Name. Name must start with alphabets");
           flag = true;
       }
      
       //To see if the username has the following special characters
       if(!Pattern.matches(".*[!,#,?].*", userName))
       {
           System.out.println("Username doesn't have special characters");
           flag = true;
       }  
      
       //If the userNames passes all test,store it in the database
       if(!flag)
       {
           bw.append("\n" + userName);
           System.out.println("User " + userName + " added successfully!");
       }
      
       s.close();
       s1.close();
       bw.close();
   }
  
}

The screenshot of the code:-

The sampleoutput of the code :-

Add a comment
Know the answer?
Add Answer to:
I) will create a rudimentary (and highly insecure) database for the storage of only the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python 5.23 Login Create a program that prompts the user for a username and password....

    in python 5.23 Login Create a program that prompts the user for a username and password. The correct username should be python and the correct password should be csci 135. See below for example output. (Different messages depending on if user name or password are correct.) Only allow the user to make 3 attempts. Welcome to my secret program! Please enter your username: Trish Please enter your password: Duce Invalid username and password Please enter your username: Trish Please enter...

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • 1. Create a program to verify a user name and password given by a user 2....

    1. Create a program to verify a user name and password given by a user 2. Create a text file named "correctData.txt" (You will NOT upload this file during submission). Place a username on line 1 in the txt file and a password on line 2 in the file. This will be used for testing. 3. Create the following functions and call them starting from main: • void login () - This function is responsible for displaying the prompts asking...

  • Write a Python program to create userids: You work for a small company that keeps the...

    Write a Python program to create userids: You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000 Your job is to create a program assign usernames for a...

  • Lab: User login system (python) Create a user login system. Your code should do the following:...

    Lab: User login system (python) Create a user login system. Your code should do the following: 1.Load your user database from “UD.txt” (USE THE EXACT FILE NAME, file is given in the folder) 2.Display “Login or create a new user? Select L to login, select C to create new user.” 3. If wrong selection is entered, take the user back to step 2. 4. If the user entered “L”, display “Please enter your user name and hit enter” 5. Check...

  • I need to create a code based off of what the users first name and last...

    I need to create a code based off of what the users first name and last name are along with a random set of numbers no longer than 10 characters as the picture below demonstrate (Java language) Scenario: You have been appointed by the CS department to create a username generator to create CS email accounts automatically. The CS email will have the following format: Username@cs.utep.du. Your username must have a limit of 10 characters. Your program, will provide three...

  • I need atleast 1000 words in this assignment, thank you. Create Activity diagram Use-case diagram CRC...

    I need atleast 1000 words in this assignment, thank you. Create Activity diagram Use-case diagram CRC cards Class diagrams for developing a new online attendance system to be developed for a university. The steps of the activity diagram are as follows: (You have to follow every step to create the complete activity diagram) a) The faculty is asked to first enter valid username and password in the system. b) If an invalid username or password is entered, a message is...

  • need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user...

    need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user objects. The Facebook class should have methods to list all of the users (i.e. print out their usernames), add a user,delete a user, and get the password hint for a user You will also need to create a driver program. The driver should create an instance of the Facebook class and display a menu containing five options: list users...

  • In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...

    In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user's GPA. The program should first ask the user to type either Yes or No in response to the question, "Do you want to enter a grade?" If the answer is Yes, the user should be asked to enter the name of the...

  • Use PYTHON3 to create a program that asks the user for their name, and then prints...

    Use PYTHON3 to create a program that asks the user for their name, and then prints their initials. You must create a function called getInitials() that takes the name string and prints out the initials. It must be case insensitive and the initials must be printed in upper case. The program must contain a main() and a function called getInitials(), implemented as described in the function header comment given below. (You should include this function header comment in your own...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT