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

This is an assignment for my java class which I am very confused about... I have

ID: 3628727 • Letter: T

Question

This is an assignment for my java class which I am very confused about... I have the framework completed, but don't know where to go from here. Any help would be appreciated! I apologize for the length of the directions in advance...

Program Name: UserID.java

Requirements: You have been requested to create a program that allows a user to enter their first name and last name and generate a random user id and default password (a 6-digit random number). The user id must contain the first 3 letters of the user's last name, the first three letters of the user's first name, and a random number. The random number must have the following characteristics:
o The number must be from 000 to 199
o The second digit must be from 3-9
o The third digit must be from 0-9

Example:
First name: Bob
Last name: Smith
Example user name: smibob143
Example random password: 386425


• Design: Your UserID class must contain a constructor that accepts 2 strings as parameters representing the user's first name and last name. A user id and password must also be generated.

Example:
UserID myInfo = new UserID("Bob", "Smith");

The UserID class must also contain the following methods:

- getId: accepts no parameters and returns the user name that has been generated for
the user as a String. The same user name must be returned every time the method is
called once the object has been created (HINT: you will want the user name to be
generated for each object when it is created rather than when the getId method is
invoked). If the user's first or last name is less than 3 characters long, then
concatenate the existing characters with the random number (Example: Jane Ki might
be janki037.)

- getPassword: accepts no parameters and returns a String representing the curent
password. The current password must be randomly generated when the object is
created and only changed when generateNewPassword is invoked or when the
password is set using the setPassword method.

- setPassword: takes a String parameter and returns a boolean. If the string
paramter (the new password) is less than 6 characters, then the method returns false
and the password is not set. Otherwise, the password is set to the parameter value and
the method returns true.

- generateNewPassword: Takes no parameters and does not return a value. The
method should generate a new password for the user. The password must be a 6-digit
number.

- toString: Returns a String containing the user's first name and last name on the
first line, their user name on the second line, and their current password on the third
line.

Example:
Bob Smith
smibob143
386425


- Code: Note that the user ID must contain a number from 000 to 199, but the second digit must not be below 3. You can therefore genererate integers in the 3-digit number separately and then concatenate them together. Use constant fields instead of including literal values in your code. Also, keep variables local where possible.


- Test: Make sure that once an object is created, the user ID always stays the same. The password should also be generated when the object is created, and only changed if setPassword is invoked with a valid input or if generateNewPassword is invoked.


HERE IS THE CODING FRAMEWORK I HAVE DONE SO FAR (NOT SURE WHERE TO GO BEYOND HERE THOUGH...)

public class UserID {

public UserID(String firstName, String lastName)
{

}

public String getId()
{
return null;
}

public String getPassword()
{
return null;
}

public boolean setPassword(String passwordIn)
{
return false;
}

public void generateNewPassword()
{

}

public String toString()
{
return null;
}

}


* I apologize for the length of the question again, this is a complex assignment and I wanted to be sure that anyone attempting to help me knew exactly what was expected. Thanks! *

Explanation / Answer

//import of java classes
import java.util.Random;
import java.io.*;
public class UserID
{
//variable declarations
String fName;
String lName;
int password[]=new password[6];
//create a random object to generate a random numbers
Random r=new Random();
//constructor
public void UserID(String firstName,String lastName)
{
  fName=firstName;
  lName=lastName;
  
}
//To get id of the first name and last name
public String getId()
{
  char fname=new char[10];
  char lname=new char[10];
int fLen=fName.length();
  int lLen=lName.length();
  if(fLen>3&&lLen>3)
  {
   for(int i=0;i<3;i++)
   {
    fname[i]=firstName.charAt(i);
    lName[i]=lastName.charAt(i);
   }
  }
return fname+lname;
  
}
//get random password of length
public String getPassword()
{
for(int i=0;i<6;i++)
password[i]=(int)Math.random()*6;
}

public boolean setPassword(String passwordIn)
{
  for(int i=0;i<6;i++)
  {
  password[i]=(int)(Math.random()*6);
  System.out.println(password[i]);
  }
}
//To generate a new password
public void generateNewPassword()
{
for(int i=0;i<6;i++)
  {
  password[i]=(int)(Math.random()*6);
  System.out.println(password[i]);
  }
}

public String toString()
{
System.out.println(fName+" "+lName+password);
}

public static void main(String[] args)
{
UserID myinfo=new UserID("Bob","smith");
System.out.println(getId());
}
}

Hope this would help you

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