Skip to content

Commit 5c30377

Browse files
authored
Merge branch 'master' into fix-pr-22
2 parents 38cfe25 + 8f6745c commit 5c30377

21 files changed

+250
-158
lines changed
File renamed without changes.

src/com/codefortomorrow/advanced/chapter13/solutions/NegativeSum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.codefortomorrow.advanced.chapter13.practice;
1+
package com.codefortomorrow.advanced.chapter13.solutions;
22

33
/*
44
Implement the iterative code as a recursive
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.codefortomorrow.advanced.chapter14.practice;
2+
3+
/*
4+
Create the following classes that simply extend the `Exception` class:
5+
6+
- `InvalidUsernameException`
7+
- `InvalidPasswordException`
8+
- `InvalidAgeException`
9+
- `PasswordMismatchException`
10+
11+
In the `Account` class, code a method called `createAccount` that takes a `username`, `age`,
12+
`password`, and `confirmPassword` as parameters.
13+
14+
In `createAccount`, throw an:
15+
16+
- `InvalidUsernameException` - if the given username is <4 or >10 characters.
17+
- `InvalidPasswordException` - if the given password is <4 or >10 characters.
18+
- `InvalidAgeException` - if the given age is <18.
19+
- `PasswordMismatchException` - if the given password does not match the given confirm password.
20+
21+
In your `main` method (within the `Account` class):
22+
23+
- To simulate the creation of an account online, prompt the user to enter their username, age,
24+
password, and their password again (to confirm).
25+
- Call the `createAccount` method continuously with the user's input and use `try`/`catch` to
26+
handle the possible exceptions and print the appropriate error message. (You can assume that
27+
the user input will only throw at most 1 exception.)
28+
- Keep asking the user for input until the account is created successfully.
29+
30+
Example output:
31+
32+
```
33+
Welcome to Account Creation!
34+
Enter username (4 to 10 characters): hi
35+
Enter age: 18
36+
Enter password (4 to 10 characters): thisislong
37+
Confirm password (4 to 10 characters): thisislong
38+
Invalid username.
39+
Enter username (4 to 10 characters): four
40+
Enter age: 18
41+
Enter password (4 to 10 characters): thisislong
42+
Confirm password (4 to 10 characters): thisislong
43+
Account created successfully!
44+
```
45+
*/
46+
47+
public class Account {
48+
49+
public static void main(String[] args) {
50+
// Write your code here
51+
}
52+
53+
public static void createAccount(
54+
String username,
55+
int age,
56+
String password,
57+
String confirmPassword
58+
) {
59+
// Write your code here
60+
}
61+
}
62+
// Write exception classes here

src/com/codefortomorrow/advanced/chapter14/practice/Average.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.codefortomorrow.advanced.chapter14.practice;
22

3-
import java.io.*;
4-
53
/*
64
The file “numbers.txt” has 100 random numbers
75
(one on each line). Use file i/o to find the

src/com/codefortomorrow/advanced/chapter14/practice/Lexico.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.codefortomorrow.advanced.chapter14.practice;
22

3-
import java.io.*;
4-
53
/*
64
Practice: Use File I/O to compare two files lexicographically.
75
Lexicographical order is very similar to alphabetical order,

src/com/codefortomorrow/advanced/chapter14/practice/account/InvalidAgeException.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/com/codefortomorrow/advanced/chapter14/practice/account/InvalidPasswordException.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/com/codefortomorrow/advanced/chapter14/practice/account/InvalidUsernameException.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/com/codefortomorrow/advanced/chapter14/practice/account/Main.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/com/codefortomorrow/advanced/chapter14/practice/account/PasswordMismatchException.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)