@@ -53,34 +53,39 @@ public static void main(String[] args) {
53
53
54
54
System .out .println ("Welcome to Account Creation!" );
55
55
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
+ }
79
79
}
80
80
}
81
81
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 {
84
89
if (username .length () < 4 || username .length () > 10 ) {
85
90
throw new InvalidUsernameException ();
86
91
}
@@ -96,7 +101,7 @@ public static void createAccount(String username, int age, String password, Stri
96
101
if (!password .equals (confirmPassword )) {
97
102
throw new PasswordMismatchException ();
98
103
}
99
- }
104
+ }
100
105
}
101
106
102
107
class InvalidUsernameException extends Exception {}
0 commit comments