Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Program Companies with lots of employees need to manage user information an

ID: 3777964 • Letter: J

Question

Java Program

Companies with lots of employees need to manage user information and passwords. It would be helpful to have the facility to generate a userid and password when a new employee is entered.

Create a class, User that manages user info.

The class must store first name, last name, phone number, userid, and password.

The class must generate the id based on first initial, lastname.

The class must generate a random based 6 position password.

The private information should all be strings.

The class must allow for changes to these fields.

The class must allow for display of all the fields but password

The class must allow for display of the fields including password

The class must allow for the comparison of userid and password, returning true or false.

Write a driver that instantiates several instances of the class User, modifies several field, displays the contents, performs a comparison of userid and password against keyboard input. The purpose of the driver is to demonstrate that the class features are working.

You’ll need to write a constructor that creates the object with information passed to it. The constructor will have to generate the userid and generate a random password.   You should use private methods for generating the userid and password that the constructor calls.

Constructor methods must include:

            Default constructor

Requires no parameters

                        Sets variables to default values – empty strings

            Overloaded constructor

                        Passed strings for first name, last name, and phone

                        Invokes private methods to create userid and password

Mutator methods must include:

updateName

Allow updating of first & last names. Accepts 2 strings as input

Returns void

updatePhone

Allow updating of phone number. Accepts 1 string as input

Returns void

updatePassword,

Allow updating of password.   Will allow setting to a specific password

Accepts 1 string as input

Returns void

updateUserID.

Allow updating of Userid

                        Will call private function to generate

Returns void

Accessor methods must include:

displayInfo

Doesn’t display the password and displays a formatted line using System.out.print

Returns void

            displayInfoAll

Displays all info including the password on a formatted line using System.out.print

Returns void

            isPasswordEqual

                        Compares a password passed to the method with the one stored.

Returns true or false

            isUseridEqual

                        Compares a userid passed to the method with the one stored.

Returns true or false

Private methods must include:

createUserid

Generates id based on first initial, last name

Returns void

            createPassword

Generates random password

Returns void

Complete all the requirements above. Generate a 6 position mixed upper/lower case alpha password with alternating consonants & vowels

Documentation is required in the program.  

Explanation / Answer

import java.util.Random;

public class User {

   private String firstName;
   private String lastName;
   private String phoneNum;
   private String userID;
   private String password;

   /**
   * @param firstName
   * @param lastName
   * @param phoneNum
   * @param userID
   * @param password
   */
   public User() {
       this.firstName = "";
       this.lastName = "";
       this.phoneNum = "";
       this.userID = "";
       this.password = "";
   }

   /**
   * @param firstName
   * @param lastName
   * @param phoneNum
   * @param userID
   * @param password
   */
   public User(String firstName, String lastName, String phoneNum) {
       this.firstName = firstName;
       this.lastName = lastName;
       this.phoneNum = phoneNum;
       createUserID();
       createPassword();
   }

   /**
   *
   */
   private void createPassword() {

       String alphabet = new String(
               "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
       int n = alphabet.length();

       String result = new String();
       Random r = new Random();

       for (int i = 0; i < 6; i++)
           result = result + alphabet.charAt(r.nextInt(n)); // 13
       this.password = result;
   }

   private void createUserID() {

       this.userID = firstName + lastName;
   }

   /**
   * @param firstName
   * @param lastName
   */
   public void updateName(String firstName, String lastName) {

       this.firstName = firstName;
       this.lastName = lastName;
       createUserID();
   }

   /**
   * @param phoneNum
   */
   public void updatePhone(String phoneNum) {
       this.phoneNum = phoneNum;
   }

   public void updatePassword() {
       createPassword();
   }

   /**
   * Allow updating of Userid Will call private function to generate Returns
   * void
   */
   public void updateUserID() {
       createUserID();
   }

   /**
   * Doesn’t display the password and displays a formatted
   */
   public void displayInfo() {
       System.out.println("firstName=" + firstName + ", lastName=" + lastName
               + ", phoneNum=" + phoneNum + ", userID=" + userID);
   }

   /**
   * Displays all info including the password on a formatted line
   */
   public void displayInfoAll() {
       System.out.println("firstName=" + firstName + ", lastName=" + lastName
               + ", phoneNum=" + phoneNum + ", userID=" + userID
               + ", password=" + password);
   }

   /**
   * Compares a password passed to the method with the one stored.
   *
   * @param password
   * @return
   */
   public boolean isPasswordEqual(String password) {
       if (this.password == password) {
           return true;
       } else
           return false;

   }

   /**
   * Compares a userid passed to the method with the one stored.
   *
   * @param userid
   * @return
   */
   public boolean isUseridEqual(String userid) {
       if (this.userID == userID) {
           return true;
       } else
           return false;

   }

}

import java.util.Scanner;

public class UserDriver {

   public static void main(String[] args) {

       Scanner scanner = null;
       try {
           scanner = new Scanner(System.in);

           User user1 = new User("Srinivas", "Palli", "9887654557");
           User user2 = new User();

           System.out.println("user1 :");
           user1.displayInfo();

           System.out.println("user2 :");
           user2.displayInfo();

           System.out.println("user1 include password:");
           user1.displayInfoAll();

           System.out.println("user2 include password:");
           user2.displayInfoAll();

           System.out.println("password equlity of user1 and user2:"
                   + user1.isPasswordEqual("rediif"));
           System.out.println("password equlity of user1 and user2:"
                   + user1.isUseridEqual("rajeshpalli"));

           user2.updateName("Pavan", "kishore");

       } catch (Exception e) {
           // TODO: handle exception
       }
   }
}

OUTPUT:

user1 :
firstName=Srinivas, lastName=Palli, phoneNum=9887654557, userID=SrinivasPalli
user2 :
firstName=, lastName=, phoneNum=, userID=
user1 include password:
firstName=Srinivas, lastName=Palli, phoneNum=9887654557, userID=SrinivasPalli, password=jCXtrH
user2 include password:
firstName=, lastName=, phoneNum=, userID=, password=
password equlity of user1 and user2:false
password equlity of user1 and user2:true

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote