Question: Examine the provided User class and run the code. Your goal for this problem is to add validation by testing the values of arguments being
Examine the provided User class and run the code.
Your goal for this problem is to add validation by testing the values of arguments
being passed to the setter methods and throwing IllegalArgumentExceptions if the
values do not meet certain criteria. You have been provided argument validation for
the password setter that tests if the password contains both an upper and lowercase
letter. Add the following addtional validations. You may find the java String
documentation helpful.
Make sure you include try and catch blocks in the main method to catch the
Exceptions. Every attempt value should be able to be retried if an invalid value is
entered.
import java.util.;
public class Main
public static void mainString args
Scanner scnr new ScannerSystemin;
User newUser new User;
System.out.printlnPlease enter the user's first name:";
String fname scnrnextLine;
newUser.setFirstNamefname;
System.out.printlnPlease enter the user's last name:";
String lname scnrnextLine;
newUser.setLastNamelname;
System.out.printlnPlease enter the user's birthday in the format mmddyyyy:;
String bday scnrnextLine;
newUser.setBirthdaybday;
System.out.printlnPlease enter the user's password:";
String psw scnrnextLine;
newUser.setPasswordpsw;
System.out.printlnPlease enter the user's zipcode:";
int zip scnrnextInt;
newUser.setZipcodezip;
public class User
private String firstName;
private String lastName;
private String password;
private String birthday;
private int zipcode;
public User
public void setFirstNameString firstName
this.firstName firstName;
public void setLastNameString lastName
this.lastName lastName;
public void setPasswordString password
if password.matchesAZpassword.matchesaz
throw new IllegalArgumentException;
this.password password;
public void setBirthdayString birthday
this.birthday birthday;
public void setZipcodeint zipcode
this.zipcode zipcode;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
