Please write program in JAVA ONLY When a user signs in for t
Please write program in JAVA ONLY!
When a user signs in for the first time to a website, the user has to submit personal information, such as user_id, 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 the concept of processing a form with the following elements:
User_id
Password
Reenter password
Email address
Name
Street Address
City
State
Zip
Telephone
You will store these values as strings in an array.
Write the following methods in your class:
1. A constructor with one parameter, an array of 10 strings (representing one element for each of the fields above), the only instance variable.
2. Accessor, mutator, toString methods
3. A method checking that no Strings are empty. If at least one is empty, return false; otherwise return true.
4. A method returning the number of characters in the user_id
5. A method checking if the two Strings representing the password fields are the same, if they are return true, otherwise false.
6. A method checking if the email address contains one and only one @ character and contains at least one \".\" after the @ character. If these conditions are met, return true; otherwise return false.
Write a test client to test all your methods in your class.
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
################ UserForm.java ###########
public class UserForm {
private String[] information;
// constructor
public UserForm(String[] information){
this.information = information;
}
// accessors and mutators
public String getUserId() {
return information[0];
}
public void setUserId(String userId) {
information[0] = userId;
}
public String getPassword() {
return information[1];
}
public void setPassword(String password) {
information[1] = password;
}
public String getReenteredPasswerd() {
return information[2];
}
public void setReenteredPasswerd(String reenteredPasswerd) {
this.information[2] = reenteredPasswerd;
}
public String getEmail() {
return information[3];
}
public void setEmail(String email) {
this.information[3] = email;
}
public String getName() {
return information[4];
}
public void setName(String name) {
this.information[4] = name;
}
public String getStreetAddress() {
return information[5];
}
public void setStreetAddress(String streetAddress) {
this.information[5] = streetAddress;
}
public String getCity() {
return information[6];
}
public void setCity(String city) {
this.information[6] = city;
}
public String getState() {
return information[7];
}
public void setState(String state) {
this.information[7] = state;
}
public String getZip() {
return information[8];
}
public void setZip(String zip) {
this.information[8] = zip;
}
public String getTelephone() {
return information[9];
}
public void setTelephone(String telephone) {
this.information[9] = telephone;
}
@Override
public String toString() {
return \"User ID: \"+information[0]+\"\ \"+
\"Name: \"+information[3]+\"\ \"+
\"Email: \"+information[4]+\"\ \"+
\"Street Address: \"+information[5]+\"\ \"+
\"City: \"+information[6]+\"\ \"+
\"State: \"+information[7]+\"\ \"+
\"Zip: \"+information[8]+\"\ \"+
\"Telephone: \"+information[9];
}
public boolean isNotEmpty(){
for(int i=0; i<information.length; i++){
if(information[i] == null && information[i].isEmpty())
return false;
}
return true;
}
public int numCharacters(){
return information[0].length();
}
public boolean isPAsswordMatch(){
if(information[1].equals(information[2]))
return true;
return false;
}
public boolean isValidEmail(){
String email = information[3];
int index1 = email.indexOf(\'@\');
// we do not have any \'\'@
if(index1 == -1)
return false;
// getting substring after first \'@\'
String temp = email.substring(index1+1);
int index2 = temp.indexOf(\'@\');
// more than one \'@\'
if(index1 != -1)
return false;
return true;
}
}
################ UserFormTest.java ###################
public class UserFormTest {
public static void main(String[] args) {
// creating information array
String[] information = {
\"awe123\",
\"@1345\",
\"@1345\",
\"pk@gmai.com\",
\"Pravesh Kumar\",
\"196, Goldmohar Enclave\",
\"Bangalore\",
\"Karnatka\",
\"560067\",
\"1234567\"
};
// creating UserFOrm object and passing information array
UserForm form = new UserForm(information);
System.out.println(form.toString());
System.out.println();
System.out.println(\"EMail length: \"+form.numCharacters());
System.out.println(\"Is Not Empty: \"+form.isNotEmpty());
System.out.println(\"Password Matches: \"+form.isPAsswordMatch());
System.out.println(\"Is email valid: \"+form.isValidEmail());
}
}
/*
Sample Output:
User ID: awe123
Name: pk@gmai.com
Email: Pravesh Kumar
Street Address: 196, Goldmohar Enclave
City: Bangalore
State: Karnatka
Zip: 560067
Telephone: 1234567
EMail length: 6
Is Not Empty: true
Password Matches: true
Is email valid: false
*/






