Skip to content

Commit cef8163

Browse files
committed
Update Account.java
Identation fix again
1 parent f80f9d3 commit cef8163

File tree

1 file changed

+26
-31
lines changed
  • src/com/codefortomorrow/advanced/chapter14/solutions

1 file changed

+26
-31
lines changed

src/com/codefortomorrow/advanced/chapter14/solutions/Account.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,34 @@ 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(
83-
String username,
84-
int age,
85-
String password,
86-
String confirmPassword
87-
)
88-
throws InvalidAgeException, InvalidPasswordException, InvalidUsernameException, PasswordMismatchException {
82+
public static void createAccount(String username, int age, String password, String confirmPassword)
83+
throws InvalidAgeException, InvalidPasswordException, InvalidUsernameException, PasswordMismatchException {
8984
if (username.length() < 4 || username.length() > 10) {
9085
throw new InvalidUsernameException();
9186
}
@@ -101,7 +96,7 @@ public static void createAccount(
10196
if (!password.equals(confirmPassword)) {
10297
throw new PasswordMismatchException();
10398
}
104-
}
99+
}
105100
}
106101

107102
class InvalidUsernameException extends Exception {}

0 commit comments

Comments
 (0)