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

When a new user logs in for the first time on a website, the user has to submit

ID: 3657650 • Letter: W

Question

When a new user logs in for the first time on a website, the user has to submit personal information, such as user_id, password, name, email address, telephone number, and so forth. Typically, there arc 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 In your class, write the following methods: A constructor with one parameter, a sequence of 10 words in an array of Strings, your only instance variable. Accessor, mutator, toString, and equals methods. A method checking that no Strings in the array arc empty. (All fields are mandatory.) If at least one is empty, it returns false, otherwise, it returns true. A method returning the number of characters in the user_id. A method checking if the two Strings representing the passwords (representing the password typed in twice) are identical; if they are, it returns true', if not, it returns false. A method checking if the String representing the email address actually "looks like" an email address; to simplify, we can assume that an email address contains one and only one @ character and contains one or more periods after the @ character. If it does "look like" an email address, then the method returns true; otherwise, it returns false. A method checking if the String representing the state has exactly two characters. If it does, it returns true; otherwise, it returns false. Write a client class to test all the methods in your class.

Explanation / Answer

package Cramster; public class UserProfile { private String[] array = new String[10]; public UserProfile(String[] array) { this.array = array; } public void setUserID(String userID) { array[0] = userID; } public String getUserID() { return array[0]; } public void setPassword(String password) { array[1] = password; array[2] = array[1]; } public String getPassword() { return array[1]; } public void setEmail(String email) { array[3] = email; } public String getEmail() { return array[3]; } public void setName(String name) { array[4] = name; } public String getName() { return array[4]; } public void setStreetAddress(String street) { array[5] = street; } public String getStreetAddress() { return array[5]; } public void setCity(String city) { array[6] = city; } public String getCity() { return array[6]; } public void setState(String state) { array[7] = state; } public String getState() { return array[7]; } public void setZip(String Zip) { array[8] = Zip; } public String getZip() { return array[8]; } public void setPhone(String Phone) { array[9] = Phone; } public String getPhone() { return array[9]; } public boolean checkEmail() { String[] tokens = array[3].split("@"); if(tokens.length == 2 && tokens[1].contains(".")) return true; else return false; } public int userIDCharacter() { return array[0].length(); } public boolean checkState() { return array[7].length() == 2; } public boolean checkInput() { for(String element : array) if(element == null) return false; return true; } public boolean checkPassword() { return array[1].equals(array[2]); } public String toString() { return String.format("%s : %s %s : %s %s : %s %s : %s %s : %s %s : %s " + "%s : %s %s : %s %s : %s %s : %s ","User ID",getUserID(),"PassWord", getPassword(),"Re entered Password",getPassword(),"Email Id",getEmail(), "Name", getName(),"Street",getStreetAddress(),"City",getCity(),"State",getState(), "Zip",getZip(),"Phone Number",getPhone()); } } package Cramster; import java.util.Scanner; public class UserProfileTest { public static void main(String[] args) { Scanner console = new Scanner(System.in); String[] array = new String[10]; int count = 0; System.out.print("User ID : "); array[count++] = console.nextLine(); System.out.print("Password : "); array[count++] = console.nextLine(); System.out.print("Re-enter Password : "); array[count++] = console.nextLine(); System.out.print("Email ID : "); array[count++] = console.nextLine(); System.out.print("Name : "); array[count++] = console.nextLine(); System.out.print("Street Address : "); array[count++] = console.nextLine(); System.out.print("City : "); array[count++] = console.nextLine(); System.out.print("State : "); array[count++] = console.nextLine(); System.out.print("Zip : "); array[count++] = console.nextLine(); System.out.print("Phone Number : "); array[count++] = console.nextLine(); UserProfile user = new UserProfile(array); System.out.printf("Validating if all fields are entered : %b ",user.checkInput()); System.out.printf("Password is valid : %b ",user.checkPassword()); System.out.printf("Email ID is valid : %b ",user.checkEmail()); System.out.printf("State is valid : %b ",user.checkState()); System.out.printf("%s", user.toString()); } }

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