@@ -53,34 +53,39 @@ public static void main(String[] args) {
5353
5454 System .out .println ("Welcome to Account Creation!" );
5555 while (true ) {
56- System .out .print ("Enter username (4 to 10 characters): " );
57- String username = sc .next ();
58- System .out .print ("Enter age: " );
59- int age = sc .nextInt ();
60- System .out .print ("Enter password (4 to 10 characters): " );
61- String password = sc .next ();
62- System .out .print ("Confirm password (4 to 10 characters): " );
63- String confirmPassword = sc .next ();
64-
65- try {
66- createAccount (username , age , password , confirmPassword );
67- System .out .println ("Account created successfully!" );
68- sc .close ();
69- break ;
70- } catch (InvalidUsernameException e ) {
71- System .out .println ("Invalid username." );
72- } catch (InvalidPasswordException e ) {
73- System .out .println ("Invalid password." );
74- } catch (InvalidAgeException e ) {
75- System .out .println ("Must be 18 or older to create an account." );
76- } catch (PasswordMismatchException e ) {
77- System .out .println ("Passwords don't match!" );
78- }
56+ System .out .print ("Enter username (4 to 10 characters): " );
57+ String username = sc .next ();
58+ System .out .print ("Enter age: " );
59+ int age = sc .nextInt ();
60+ System .out .print ("Enter password (4 to 10 characters): " );
61+ String password = sc .next ();
62+ System .out .print ("Confirm password (4 to 10 characters): " );
63+ String confirmPassword = sc .next ();
64+
65+ try {
66+ createAccount (username , age , password , confirmPassword );
67+ System .out .println ("Account created successfully!" );
68+ sc .close ();
69+ break ;
70+ } catch (InvalidUsernameException e ) {
71+ System .out .println ("Invalid username." );
72+ } catch (InvalidPasswordException e ) {
73+ System .out .println ("Invalid password." );
74+ } catch (InvalidAgeException e ) {
75+ System .out .println ("Must be 18 or older to create an account." );
76+ } catch (PasswordMismatchException e ) {
77+ System .out .println ("Passwords don't match!" );
78+ }
7979 }
8080 }
8181
82- public static void createAccount (String username , int age , String password , String confirmPassword )
83- throws InvalidAgeException , InvalidPasswordException , InvalidUsernameException , PasswordMismatchException {
82+ public static void createAccount (
83+ String username ,
84+ int age ,
85+ String password ,
86+ String confirmPassword
87+ )
88+ throws InvalidAgeException , InvalidPasswordException , InvalidUsernameException , PasswordMismatchException {
8489 if (username .length () < 4 || username .length () > 10 ) {
8590 throw new InvalidUsernameException ();
8691 }
@@ -96,7 +101,7 @@ public static void createAccount(String username, int age, String password, Stri
96101 if (!password .equals (confirmPassword )) {
97102 throw new PasswordMismatchException ();
98103 }
99- }
104+ }
100105}
101106
102107class InvalidUsernameException extends Exception {}
0 commit comments