In JAVA, When a user signs in for the first time to a website, the user has to s
ID: 3752763 • Letter: I
Question
In JAVA,
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 Zip You will store these values as strings. Write the following methods in your class: 1. A constructor which will initialize the 9 attributes listed above. 2. Accessor, mutator, toString methods 3. A method returning the number of characters in the userid 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.
Explanation / Answer
Explanation::
Code in JAVA::
User.java code::
public class User {
private String userID;
private String name;
private String emailAddress;
private String password;
private String reenteredPassword;
private String street;
private String address;
private String city;
private String state;
private String zip;
public User(String userID, String name, String emailAddress, String password, String reenteredPassword,
String street, String address, String city, String state, String zip) {
this.userID = userID;
this.name = name;
this.emailAddress = emailAddress;
this.password = password;
this.reenteredPassword = reenteredPassword;
this.street = street;
this.address = address;
this.city = city;
this.state = state;
this.zip = zip;
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getReenteredPassword() {
return reenteredPassword;
}
public void setReenteredPassword(String reenteredPassword) {
this.reenteredPassword = reenteredPassword;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
@Override
public String toString() {
return "User UserID : " + userID + " Name : " + name + " EmailAddress : " + emailAddress + " Password : " + password
+ " ReenteredPassword : " + reenteredPassword + " Street : " + street + " Address : " + address + " City : "
+ city + " State : " + state + " Zip : " + zip;
}
public int characterNumber(String userId) {
return userId.length();
}
public boolean isEqual(String password,String repassword) {
return password.equals(repassword);
}
}
========================================================================
TestUser.java code::
public class TestUser {
public static void main(String[] args) {
User user1=new User("145409","Elon Musk","elon.musk@tesla.com","elon@123","elon@123","JumpStreet","Route 66","New York","United States","100101");
User user2=new User("145007","James Bond","james.007@bond.com","james007@","james007#","Hacker Street","Opposite Broadway","Chicago","United States","241322");
/**
* Calling functions for user1 object first
**/
System.out.println("________________________________________________________________________________");
System.out.println("User 1 :: "+user1); /*toString() is called here*/
System.out.println(" Password Match for USER 1 ? -> "+user1.isEqual(user1.getPassword(), user1.getReenteredPassword()));
System.out.println(" Number of characters in UserID of user 1 :: "+user1.characterNumber(user1.getUserID()));
System.out.println(" ________________________________________________________________________________");
/**
* Calling functions for user2 object first
**/
System.out.println("User 2 :: "+user2); /*toString() is called here*/
System.out.println(" Password Match for USER 2 ? -> "+user2.isEqual(user2.getPassword(), user2.getReenteredPassword()));
System.out.println(" Number of characters in UserID of user 2 :: "+user2.characterNumber(user2.getUserID()));
}
}
OUTPUT::
________________________________________________________________________________
User 1 ::
User
UserID : 145409
Name : Elon Musk
EmailAddress : elon.musk@tesla.com
Password : elon@123
ReenteredPassword : elon@123
Street : JumpStreet
Address : Route 66
City : New York
State : United States
Zip : 100101
Password Match for USER 1 ? -> true
Number of characters in UserID of user 1 :: 6
________________________________________________________________________________
User 2 ::
User
UserID : 145007
Name : James Bond
EmailAddress : james.007@bond.com
Password : james007@
ReenteredPassword : james007#
Street : Hacker Street
Address : Opposite Broadway
City : Chicago
State : United States
Zip : 241322
Password Match for USER 2 ? -> false
Number of characters in UserID of user 2 :: 6
Please provide the feedback!!
Thank You!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.