Question

In: Computer Science

When a user signs in for the first time to a website, the user must submit...

When a user signs in for the first time to a website, the user must submit personal information, such as last name, first name, email address, and so on. Typically, there are two fields for passwords, requiring the user to enter the password twice, to ensure that the user did not make a typo in the first password field.

Write a class encapsulating user with the following attributes:

UserID

Password

Reentered password

Email address

Last Name

First Name

Zip

You will store these values as strings.

Write the following methods in your class:

1. A constructor which will initialize the 7 attributes listed above.

2. Accessor, mutator, toString methods

3. A method returning the user id consisting of the first letter of the first name, last two letters of the last name and the first three nambers of the zip code and a random number (between 0 and 999)

4.. A method checking if the two Strings representing the password fields are the same, if they are return true, otherwise false.

Write a test class to create 2 user objects (using your constructor) and test all the methods in your class.

Remember to submit all your .java files, .class files and screenshots of your code and output and psuedocode

Solutions

Expert Solution

Program

import java.util.*;

//User class
class User
{
   //private data members
   private String userID;
   private String password;
   private String reenteredPassword;
   private String emailAddress;
   private String lastName;
   private String firstName;
   private String zip;
  
   //constructor
   public User(String userID, String password, String reenteredPassword,
       String emailAddress, String lastName, String firstName, String zip)
   {
      
       this.userID = userID;
       this.password = password;
       this.reenteredPassword = reenteredPassword;
       this.emailAddress = emailAddress;
       this.lastName = lastName;
       this.firstName = firstName;
       this.zip = zip;
   }
   //method to set userID
   public void setUserId(String userID)
   {
       this.userID = userID;
   }
   //method to set password
   public void setPassword(String password)
   {
       this.password = password;
   }
   //method to set reenteredPassword
   public void setReenteredPassword(String reenteredPassword)
   {
       this.reenteredPassword = reenteredPassword;
   }
   //method to set emailAddress
   public void setEmailAddress(String emailAddress)
   {
       this.emailAddress = emailAddress;
   }  
   //method to set lastName
   public void setLastName(String lastName)
   {
       this.lastName = lastName;
   }
   //method to set firstName
   public void setFirstName(String firstName)
   {
       this.firstName = firstName;
   }
   //method to set zip
   public void setZip(String zip)
   {
       this.zip = zip;
   }
   //method to return userID
   public String getUserID()
   {
       return userID;
   }
   //method to return password
   public String getPassword()
   {
       return password;
   }
   //method to return reenteredPassword
   public String getReenteredPassword()
   {
       return reenteredPassword;
   }
   //method to return emailAddress
   public String getEmailAddress()
   {
       return emailAddress;
   }
   //method to return lastName
   public String getLastName()
   {
       return lastName;
   }
   //method to return firstName
   public String getFirstName()
   {
       return firstName;
   }
   //method to return zip
   public String getZip()
   {
       return zip;
   }
   //method to convert to String
   public String toString()
   {
       return "User id: " + userID +
           " Password: " + password +
           " EmailAddress: " + emailAddress+
           " Name: " + lastName + " " + firstName +
           " Zop: " + zip;
   }
   //method to check the password fields are the same or not
   public boolean passwordChecking()
   {
       return password.equals(reenteredPassword);
   }
   //method to generate and return id
   public String getID()
   {
       String id = firstName.charAt(0) + lastName.substring(lastName.length()-2);
       id = id + zip.substring(0, 3);
       id = id + (new Random()).nextInt(1000);
      
       return id;
   }

}

//Driver class
class Driver
{
   //main method
   public static void main (String[] args)
   {
       //create objects of User class
       User user1 = new User("user1", "password1", "password1", "[email protected]", "Ali", "Joe", "12345");
       User user2 = new User("user2", "password2", "password2", "[email protected]", "Ali", "John", "23456");
      

//display details of user1
       System.out.println("Password fields are the same: " + user1.passwordChecking());
       System.out.println("UserID: " + user1.getUserID());
       System.out.println("Password: " + user1.getPassword());
       System.out.println("Reentered Password: " + user1.getReenteredPassword());
       System.out.println("Email: " + user1.getEmailAddress());
       System.out.println("Name: " + user1.getFirstName() + " " + user1.getLastName());
       System.out.println("Zip: " + user1.getZip());
       System.out.println("ID: " + user1.getID());
       System.out.println(user1);
      

  //display details of user2
       System.out.println("Password fields are the same: " + user2.passwordChecking());
       System.out.println("UserID: " + user2.getUserID());
       System.out.println("Password: " + user2.getPassword());
       System.out.println("Reentered Password: " + user2.getReenteredPassword());
       System.out.println("Email: " + user2.getEmailAddress());
       System.out.println("Name: " + user2.getFirstName() + " " + user2.getLastName());
       System.out.println("Zip: " + user2.getZip());
       System.out.println("ID: " + user2.getID());
       System.out.println(user2);
   }
}

Output:

Password fields are the same: true
UserID: user1
Password: password1
Reentered Password: password1
Email: [email protected]
Name: Joe Ali
Zip: 12345
ID: Jli12363
User id: user1 Password: password1 EmailAddress: [email protected] Name: Ali Joe Zop: 12345
Password fields are the same: true
UserID: user2
Password: password2
Reentered Password: password2
Email: [email protected]
Name: John Ali
Zip: 23456
ID: Jli234190
User id: user2 Password: password2 EmailAddress: [email protected] Name: Ali John Zop: 23456


Related Solutions

When a user signs in for the first time to a website, the user has to...
When a user signs in for the first time to a website, the user has to submit personal information, such as userid, name, email address, telephone number and so on. Typically, there are two fields for passwords, requiring the user to enter the password twice, to ensure that the user did not make a typo in the first password field. Write a class encapsulating user with the following elements: UserID Password Reentered password Email address Name Street Address City State...
Based on a study, the average elapsed time between when a user navigates to a website...
Based on a study, the average elapsed time between when a user navigates to a website on a mobile device until its main content is available was 14.6 seconds. This is more than a 20% increase from the previous year. Responsiveness is certainly an important feature of any website and is perhaps even more important on a mobile device. What other web design factors need to be considered for a mobile device to make it more user friendly? Among other...
A website is trying to increase registration for first-time visitors, exposing 1% of these visitors to...
A website is trying to increase registration for first-time visitors, exposing 1% of these visitors to a new site design. Of 752 randomly sampled visitors over a month who saw the new design, 64 registered. (a) Check any conditions required for constructing a confidence interval. (b) Compute the standard error. (c) Construct and interpret a 90% confidence interval for the fraction of first-time visitors of the site who would register under the new design (assuming stable behaviors by new visitors...
OU MUST FIRST GO TO THE SIMULATION WEBSITE IN ORDER TO COMPLETE QUESTIONS https://phet.colorado.e...
OU MUST FIRST GO TO THE SIMULATION WEBSITE IN ORDER TO COMPLETE QUESTIONS https://phet.colorado.edu/en/simulation/build-an-atom (COPY & PASTE LINK INTO WEB BROWSER) Click to Run Play with the simulation to discover which particles affect the charge of an atom or ion. Neutral atoms have the same number of protons and electrons. 5.Positive ions have __________ protons than electrons. 6.Negative ions have _______ protons than electron 7.Develop a relationship (in the form of a single sentence) that can predict the charge based...
.Code for a game of Tetris in C# .Short explanation for a first time user, showing...
.Code for a game of Tetris in C# .Short explanation for a first time user, showing them how to use it and pointing out all of the pertinent features. (1 paragraph) .Provide a few screen shots if possible
You will be expected to complete a website of your choice. This website must incorporate a...
You will be expected to complete a website of your choice. This website must incorporate a PHP component, in this case, a form that we will be working on in class. When in doubt, carry out research to see what you could add. There are videos in the required resources section to assist anyone who is not familiar with building a website. Be sure to consult your instructor if additional support is needed. The first task is to have your...
You will be expected to complete a website of your choice. This website must incorporate a...
You will be expected to complete a website of your choice. This website must incorporate a PHP component, in this case, a form that we will be working on in class. When in doubt, carry out research to see what you could add. There are videos in the required resources section to assist anyone who is not familiar with building a website. Be sure to consult your instructor if additional support is needed. The first task is to have your...
. . The first aid boxes must be ready by the time college resumes for academic...
. . The first aid boxes must be ready by the time college resumes for academic work
create a website that describes a city of your choice. The website must include the following...
create a website that describes a city of your choice. The website must include the following pages:  Home Page  Arts & Culture  News & Events  Recreation Requirements Write from scratch the HTML and CSS files and show your creativity, aesthetics and imagination. Begin by creating a wireframe diagram that indicates the structure of the web page . Use grammatically correct sentences that provide reasonable flow through each web page. Include the following:  Structural elements (header,...
Identify one website that is exceptionally user- friendly and another that is not. What are the...
Identify one website that is exceptionally user- friendly and another that is not. What are the factors that make for a satisfying user experience in the first instance and a frustrating one in the second? Specify recommendations for improvements in the second website.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT