├── 01. Getting Started └── 01. Workbook 1.1.md ├── 02. Getting Started (Challenge) └── 01. Your Initials.md ├── 03. Variables ├── 01. Workbook 2.1.md ├── 02. Workbook 2.2.md ├── 03. Workbook 2.3.md ├── 04. Workbook 2.4.md └── 05. Workbook 2.5.md ├── 04. Variables (Challenge) └── ChatBot.md ├── 05. Booleans and Conditionals ├── 01. Workbook 3.1.md ├── 02. Workbook 3.2.md ├── 03. Workbook 3.3.md ├── 04. Workbook 3.4.md ├── 05. Workbook 3.5.md ├── 06. Workbook 3.6.md └── 07. Workbook 3.7.md ├── 06. Booleans and Conditionals (Challenge) └── Trivia Quiz.md ├── 07. Functions ├── 01. Workbook 4.1.md ├── 02. Workbook 4.2.md ├── 03. Workbook 4.3.md ├── 04. Workbook 4.4.md └── 05. Workbook 4.5.md ├── 08. Functions (Challenge) ├── Part 1.md └── Part 2.md ├── 09. Loops ├── 01. Workbook 5.1.md ├── 02. Workbook 5.2.md ├── 03. Workbook 5.3.md ├── 04. Workbook 5.4.md ├── 05. Workbook 5.5.md ├── 06. Workbook 5.6.md ├── 07. Workbook 5.7.md ├── 08. Workbook 5.8.md ├── 09. Workbook 5.9.md ├── 10. Workbook 5.10.md ├── 11. Workbook 5.11.md └── 12. Pokerito.md ├── 10. Loops (Challenge) ├── Part 1.md └── Part 2.md ├── 11. Arrays ├── 01. Workbook 6.1.md ├── 02. Workbook 6.2.md ├── 03. Workbook 6.3.md ├── 04. Workbook 6.4.md ├── 05. Workbook 6.5.md ├── 06. Workbook 6.6.md ├── 07. Workbook 6.7.md ├── 08. Workbook 6.8.md ├── 09. Workbook 6.9.md ├── 10. Workbook 6.10.md ├── 11. Workbook 6.11.md ├── 12. Workbook 6.12.md ├── 13. Workbook 6.13.md ├── 13a. Workbook 6.13Revisit.md ├── 14. Workbook 6.14.md └── 15. Javapedia.md ├── 12. Arrays (Challenge) ├── Part 1.md ├── Part 2.md └── Part 3.md ├── 13. Capstone └── Hangman.md ├── 14. The World of Objects ├── 01. Workbook 7.1.md ├── 02. Workbook 7.2.md ├── 03. Workbook 7.3.md ├── 04. Workbook 7.4.md ├── 05. Workbook 7.5.md ├── 06. Workbook 7.6.md ├── 07. Workbook 7.7.md ├── 08. Workbook 7.8.md └── 09. Workbook 7.9.md ├── 15. The World of Objects (Challenge) ├── Part 1.md ├── Part 2.md └── Part 3.md ├── 16. Extra Practice ├── Part 1.md ├── Part 2.md ├── Part 3.md └── Part 4.md ├── 17. List └── Workbook 8.1.md ├── 18. Extra Practice ├── Part 1.md └── Part 2.md ├── 19. Exception Handling ├── Part 1.md └── Part 2.md ├── 20. Extra Practice ├── Part 1.md ├── Part 2.md └── Part 3.md ├── 21. Map └── Workbook 9.1.md ├── 22. Map (Extra Practice) ├── Part 1.md ├── Part 2.md └── Part 3.md ├── 23. Static and Final └── Workbook 10.1.md ├── 24. Enums └── Workbook 11.1.md ├── 25. Extra Practice ├── Part 1.md ├── Part 2.md └── Part 3.md ├── 26. Inheritance ├── Workbook 12.1.md ├── Workbook 12.2.md └── Workbook 12.3.md ├── 27. Extra Practice ├── Part 1.md └── Part 2.md ├── 28. Higher Order Functions ├── Workbook 13.1.md ├── Workbook 13.2.md ├── Workbook 13.3.md ├── Workbook 13.4.md ├── Workbook 13.5.md ├── Workbook 13.6.md └── Workbook 13.7.md ├── 29. Extra Practice └── Part 1.md ├── 30. Capstone Project ├── Part 1.md ├── Part 2.md ├── Part 3.md └── Part 4.md ├── README.md └── docs ├── 003 Quiz 10.1.html ├── 008 Quiz 12.1.html ├── 013 Quiz 1.1.html ├── Quiz 1.1.html ├── Quiz 10.1.html ├── Quiz 11.1.html ├── Quiz 11.2.html ├── Quiz 11.3.html ├── Quiz 12.1.html ├── Quiz 2.1.html ├── Quiz 2.2.html ├── Quiz 2.3.html ├── Quiz 2.4.html ├── Quiz 2.5.html ├── Quiz 3.1.html ├── Quiz 3.2.html ├── Quiz 3.3.html ├── Quiz 3.4.html ├── Quiz 3.5.html ├── Quiz 4.1.html ├── Quiz 4.2.html ├── Quiz 4.3.html ├── Quiz 4.4.html ├── Quiz 4.5.html ├── Quiz 4.6.html ├── Quiz 5.1.html ├── Quiz 5.2.html ├── Quiz 5.3.html ├── Quiz 5.4.html ├── Quiz 5.5.html ├── Quiz 5.6.html ├── Quiz 6.1.html ├── Quiz 6.2.html ├── Quiz 6.3.html ├── Quiz 6.4.html ├── Quiz 6.5.html ├── Quiz 7.1.html ├── Quiz 7.2.html ├── Quiz 7.3.html ├── Quiz 7.4.html ├── Quiz 7.5.html ├── Quiz 7.6.html ├── Quiz 8.1.html ├── Quiz 8.2.html ├── Quiz 8.3.html ├── Quiz 9.1.html ├── Quiz 9.2.html ├── Quiz 9.3.html ├── Quiz 9.4.html ├── index.html └── quiz-styles.css /01. Getting Started/01. Workbook 1.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 1.1 2 | 3 | Each workbook is an exercise that challenges you to write code and run it. 4 | 5 | ## Did you download the resources? 6 | 7 | If you did not download the resources yet, return to the lesson: **Workbooks and Challenges**. 8 | 9 | ![Screen Shot 2022-10-13 at 5.48.30 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-17bbffaa2a32f64d8ceef2ec47ab1d9e.png) 10 | 11 | 12 | 13 | ## Launch Workbook 1.1 14 | ----------------- 15 | 16 | 17 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 1.1`** folder. 18 | 19 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-488a68f5fcfcf484bf0794ecef3a1be1.png) 20 | 21 | Your file explorer should appear as follows: 22 | 23 | ![Screen Shot 2022-10-07 at 3.57.13 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-af125b0a80ef23169bbc3d1d5c452e68.png) 24 | 25 | If your file explorer looks like this, please go back and launch the correct folder. 26 | 27 | ![Screen Shot 2022-10-07 at 3.54.59 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-b0bad6016ac130f3bb67f65bc26b62ae.png) 28 | 29 | ## Comments 30 | Inside `FirstProgram.java`, you will notice **comments**. 31 | 32 | ![Screen Shot 2022-10-30 at 8.31.25 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-4a38812825c78b578e4df66d765d2c85.png) 33 | 34 | A comment follows two forward slashes `//`. It has no impact on your code. 35 | 36 | ## Task 1 37 | ---------------------- 38 | 39 | Make a class. 40 | 41 | ## Task 2 42 | --------------------------------- 43 | 44 | Write the `main()` method. 45 | 46 | ## Task 3 47 | ---------------------- 48 | 49 | Inside `main()`, print these messages to the console. 50 | 51 | ``` 52 | >> Printing is fun! 53 | >> Java > Python. 54 | >> I spilled Java all over my paper. 55 | >> My dog ate my Java. 56 | ``` 57 | 58 | ## Execute your code 59 | --- 60 | `>>: javac FirstProgram.java` 61 | 62 | `>>: java FirstProgram` 63 | 64 | #### Expected Result 65 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-10cea94aaadbf646e6e2030f5dfae0f8.png) 66 | 67 | ## Reminder 68 | ------------ 69 | 70 | - You can use the up key (`↑`) to run previous terminal commands. 71 | - You can use the `tab` key to autocomplete: 72 | 73 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-e427817bed0a13c294278d14fe95bbb7.gif) 74 | 75 | 76 | ## Solution 77 | 78 | The **code solution** is beside your starter project. 79 | 80 | ![Screen Shot 2022-10-10 at 11.51.25 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-19-11-1562c195ac8a944ba940b05cfb2fcaeb.png) 81 | 82 | ## Good Luck! 83 | ---- 84 | 85 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /02. Getting Started (Challenge)/01. Your Initials.md: -------------------------------------------------------------------------------- 1 | # Your Initials 2 | 3 | In this challenge, you will print your initials in a similar fashion. 4 | 5 | ![Screen Shot 2022-10-30 at 10.00.21 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-963de16a61f8e081a0ff7866de691928.png) 6 | 7 | ## Did you download the resources? 8 | 9 | If you did not download the resources yet, return to the lesson: **Workbooks and Challenges**. 10 | 11 | ![Screen Shot 2022-10-13 at 5.48.30 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-685acd745768515227ff596bdda22a0e.png) 12 | 13 | ## Launch the Challenge 14 | 15 | From the `Java-Bootcamp-Resources`, launch the **`Challenge 1`** folder. 16 | 17 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-08c7da0de8d98a4705d2036a703c44d0.png) 18 | 19 | The folder has a `YourInitials.java` file. 20 | 21 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-73f7a1404372376670928a8c4c6d3a03.png) 22 | 23 | ## Print your Initials 24 | 25 | In this challenge, you need to print your initials. 26 | 27 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-3d4970c16e63efddbf5cc3d90e97e772.png) 28 | 29 | Each letter must span **7 lines** and **5 spaces**. 30 | 31 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-11aca4d14a71149b77ff5e5684fc958b.png) 32 | 33 | Between each letter, add **2 spaces**. 34 | 35 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-0786cd2dabbd7e1d944185bd0446f3e2.png) 36 | 37 | Use this guide to draw your letters. 38 | 39 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-4c08c4bff917989fe4b63847c35dda54.png) 40 | 41 | ## Execute your code 42 | Try to achieve a similar output: 43 | ``` 44 | >>: SSS A 45 | >>: S S A A 46 | >>: S A A 47 | >>: SSS AAAAA 48 | >>: S A A 49 | >>: S S A A 50 | >>: SSS A A 51 | ``` 52 | 53 | ## Solution 54 | 55 | The **solution code** is beside your starter project. 56 | 57 | ![Screen Shot 2022-10-10 at 11.49.40 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-14-51-71ea1b27c1adda478d79798677ecb922.png) 58 | 59 | ------- 60 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /03. Variables/01. Workbook 2.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 2.1 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 2.1`** folder. 4 | 5 | ![Screen Shot 2022-10-10 at 7.03.55 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-46-98071d2cf268817e1282f5eaf3a38cf9.png) 6 | 7 | ## Did you download the resources? 8 | 9 | If you did not download the resources yet, return to the lesson: **Workbooks and Challenges**. 10 | 11 | ![Screen Shot 2022-10-13 at 5.48.30 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-46-59c007166cbd40db7895dc1b39b4e7ce.png) 12 | 13 | 14 | ## Reminder 15 | 16 | **Never** launch all of the resources at once. You will not be able to run your code. 17 | 18 | ![0daba7df-3d7a-447e-9910-724f27b8fdbc.jpeg](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-46-3343d16556b0ce6779b3cfbb745b7684.png) 19 | 20 | **Only** launch the exact folder that contains your Java file. 21 | 22 | ![Screen Shot 2022-10-10 at 7.03.55 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-47-6c6e2f8d819961140c9321e3f2876a58.png) 23 | 24 | This ensures that your terminal points to the correct folder. 25 | 26 | ![Screen Shot 2022-10-17 at 2.38.27 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-47-ec2069375ed6272a9e581c277ded2fb0.png) 27 | 28 | 29 | ## Task 1 30 | 31 | A `points` variable starts at 0. 32 | 33 | ```java 34 | int points = 0; 35 | ``` 36 | 37 | Update the variable whenever Gryffindor wins or loses points. 38 | 39 | ![Screen Shot 2022-10-30 at 9.47.55 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-47-27ee179beca2e9053aa7a7b6de87c0e4.png) 40 | 41 | ## Task 2 42 | 43 | Print your final result. It should be be 137. 44 | 45 | ![Screen Shot 2022-10-09 at 5.00.51 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-47-b404cf6503f3710a60fc833c6024b130.png) 46 | 47 | ## Solution 48 | 49 | The **code solution** is beside your starter project. 50 | 51 | ![Screen Shot 2022-10-10 at 11.48.41 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-11-47-d5531a0cc414d1a6513d7665e0d01014.png) 52 | 53 | ## Good Luck! 54 | ------- 55 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /03. Variables/02. Workbook 2.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 2.2 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 2.2`** folder. 4 | 5 | ![Screen Shot 2022-10-10 at 7.24.09 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-09-25-592a6a9d7abbd8f5bca56c2ccda33add.png) 6 | 7 | ## Did you download the resources? 8 | ---------------------- 9 | 10 | If you did not download the resources yet, return to the lesson: **Workbooks and Challenges**. 11 | 12 | ![Screen Shot 2022-10-13 at 5.48.30 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-09-25-f8b1cafbf453d5a0459ae261d8b2e4c9.png) 13 | 14 | 15 | ## My Biography 16 | 17 | In this workbook, you will fill in a biography of yourself. 18 | 19 | `>> My name is `**``**`. I'm `**``**` years old, and I'm from `**``**`.` 20 | 21 | `>> My favorite sport is `**``**`. I play for `**``**` hour(s) a day` 22 | 23 | `>> When I'm tired, I like to play `**``**`.` 24 | 25 | `>> In school, my favourite subject was `**``**`. I scored a `**``**`.` 26 | 27 | ## **Task 1** 28 | 29 | Inside `main()`, replace each comment with a variable. 30 | 31 | ![Screen Shot 2022-10-30 at 9.35.44 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-09-25-91e70072f1ef1b0b956fcb8752a2244b.png) 32 | 33 | ## Task 2 34 | 35 | Replace every placeholder with a variable. 36 | 37 | ![Screen Shot 2022-10-30 at 9.36.38 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-09-25-cef37534fa8a4ee7359ac7b93ab2dccb.png) 38 | 39 | ## Result 40 | 41 | ``` 42 | >>: My name is Sam. I'm 35 years old, and I'm from England. 43 | >>: My favourite sport is Basketball. I play for 2 hour(s) a day 44 | >>: When I'm tired, I like to play Checkers. 45 | >>: In school, my favourite subject was Chemistry, I scored a B. 46 | ``` 47 | ## Solution 48 | 49 | The **code solution** is beside your starter project. 50 | 51 | ![Screen Shot 2022-10-10 at 11.48.05 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-09-25-dfbc15d8eebf01a0f886facbff910035.png) 52 | 53 | ## Good Luck! 54 | ------- 55 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /03. Variables/03. Workbook 2.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 2.3 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 2.3`** folder. 4 | 5 | ![Screen Shot 2022-10-10 at 11.38.36 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-2d30adee79d3da9ba136fc8d613e0f23.png) 6 | 7 | ## The Apple Store 8 | The workbook starts with three variables. 9 | 10 | ```java 11 | int numOfApples = 0; 12 | int numOfCustomers = 0; 13 | double profit = 0; 14 | ``` 15 | 16 | ## **Task 1** 17 | 18 | **Decrease** your number of apples based on the printed messages. 19 | 20 | ![Screen Shot 2022-10-30 at 10.16.31 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-7933b4530391e30d444efddf4e0c585b.png) 21 | 22 | ## **Task 2** 23 | 24 | **Increase** your number of customers based on the printed messages. 25 | 26 | ![Screen Shot 2022-10-30 at 10.21.15 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-2340a86c4d38da08f843919568c3f018.png) 27 | 28 | ## Task 3 29 | 30 | Make a `price` variable and set it equal to **`0.40`**. 31 | 32 | ![Screen Shot 2022-10-30 at 10.25.44 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-63eae12ca4f28332d2b24907459a434b.png) 33 | 34 | **Increase** your profits based on the **number of apples** sold, and the **price** of each apple. 35 | 36 | ![Screen Shot 2022-10-30 at 10.29.03 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-2bb3424deab325a72f1521e937c421f1.png) 37 | 38 | ## **Task 4** 39 | 40 | Replace each placeholder with a variable. 41 | 42 | ![Screen Shot 2022-10-30 at 10.30.54 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-cd2740625cc3d11ed770119c117b6e9b.png) 43 | 44 | ## Result 45 | ``` 46 | >> Wow! So far, you made: $89.6 47 | >> 3 customers love your apples. 48 | >> You have 276 apples left. We'll sell more tomorrow! 49 | ``` 50 | ## Solution 51 | 52 | The **code solution** is beside the starter project. 53 | 54 | ![Screen Shot 2022-10-10 at 11.45.19 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-07-47-5a960bf81685e09fb624d2d630a0299b.png) 55 | 56 | ------- 57 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /03. Variables/04. Workbook 2.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 2.4 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 2.4`** folder. 4 | 5 | ![Screen Shot 2022-10-11 at 1.47.52 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-05-29-82e5ae837706a900eced6c587c7457bf.png) 6 | 7 | ## The Meeting 8 | The workbook contains four variables that store financial data. 9 | 10 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-05-29-287c6c7577cd272d01e1b2b31b5cf815.png) 11 | 12 | ## Task 1 13 | 14 | We don't care about cents. Print each value as a whole number (`24309`). 15 | 16 | ![Screen Shot 2022-10-31 at 12.55.26 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-05-29-8e6f6646f08f5c68ecdfa149233f945e.png) 17 | 18 | ## Result 19 | ``` 20 | >>: This month, we made $24309 in sales 21 | >>: Factoring in costs, we made $18562 in profit 22 | >>: The refunds are at a low $688. This is a good sign! 23 | >>: Shipping costs were high. We paid $1233 in shipping 24 | ``` 25 | 26 | ## Solution 27 | 28 | The solution code is inside the same folder as the starter project. 29 | 30 | ![Screen Shot 2022-10-11 at 1.49.35 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-05-29-0aef9cb1d9475ba33a23a2661dd83e88.png) 31 | 32 | ## Good Luck! 33 | ------- 34 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /03. Variables/05. Workbook 2.5.md: -------------------------------------------------------------------------------- 1 | # Workbook 2.5 2 | 3 | From the `Java-Bootcamp-Resources`, open the **`Workbook 2.5`** folder. 4 | 5 | ![Screen Shot 2022-10-11 at 1.53.18 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-53-a8f2d0c327e5687a09ee8b13dc492299.png) 6 | 7 | JavaGram 8 | --------- 9 | 10 | In this workbook, you will create a `sign-up` page for JavaGram! 11 | 12 | ![Screen Shot 2022-10-11 at 2.03.09 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-53-be8a056fcdcbada2649db7e0cfb3f702.png) 13 | 14 | ## Careful from the Incoming **Trap**! 15 | 16 | You will encounter the `nextLine()` trap when picking up the username. 17 | 18 | ![Screen Shot 2022-10-31 at 2.14.29 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-54-1dc79378835243dcb13141bf43a2f82a.png) 19 | 20 | 21 | ## **Task 1** 22 | Use Scanner to pick up each response. 23 | 24 | ![Screen Shot 2022-10-31 at 2.14.29 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-54-1d46d39f3ee74a2bf5ec37ae2a9ba7e0.png) 25 | 26 | ## **Task 2** 27 | 28 | Print the data that you picked up. 29 | 30 | ![Screen Shot 2022-10-31 at 2.19.53 AM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-54-81fda77b7c9758388c501212523fc615.png) 31 | 32 | Notice how it prints in a nice format. **`\n`** inserts a new line. 33 | 34 | ![t.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-54-5a173516d094a10a297bac2f173cae9e.png) 35 | 36 | **`\t`** inserts a tab of space. 37 | 38 | ![n.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-54-aee32d7e98e6a39862edcdda33bc45b8.png) 39 | 40 | 41 | ## Result 42 | 43 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_04-03-54-f94edf9ebb70e20deb5debf279dc85ae.gif) 44 | 45 | ## Good Luck! 46 | ------- 47 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 48 | -------------------------------------------------------------------------------- /04. Variables (Challenge)/ChatBot.md: -------------------------------------------------------------------------------- 1 | # Chatbot 2 | 3 | You're going to build an app that carries a simple conversation. 4 | 5 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-d7d0f9b74d03a84115baf24b385e26c2.gif) 6 | 7 | ## Open the challenge 8 | ------------------ 9 | 10 | From the `Java-Bootcamp-Resources`, open `Challenge 2`. 11 | 12 | ![Screen Shot 2022-10-11 at 11.40.48 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-0e1b643f884a684d131bd360a746d2f2.png) 13 | 14 | ## 1\. Store each answer. 15 | ---------------------- 16 | 17 | After each question, add code that picks up the user's answer and stores it. 18 | 19 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-0e26e29534ef295ba048e065bfed8541.png) 20 | 21 | ## **Careful from the** `nextLine()` **trap** 22 | ---------------------------------------------- 23 | 24 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-aec6a097fe5a9329647243cb6627f58b.png) 25 | 26 | 27 | ## 2\. Update each reply. 28 | ---------------------- 29 | 30 | Update each reply with the user's answer. 31 | 32 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-5b55dc9b8ff25bb4ba86969615ffa359.png) 33 | 34 | ## 3\. Run your code. 35 | ------------------ 36 | 37 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-7cb514bd1206ab9abf7715c9e8363f19.png) 38 | 39 | Why is the cat scared? 40 | 41 | The screaming cat appears when something's wrong or looks bad. In this case, the output is very messy. There should be a line of spacing between each answer and reply (see arrows). 42 | 43 | ## 4\. Add a new line 44 | ------------------ 45 | 46 | Before every reply, add a **new line**. 47 | 48 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-d493dafd7604d7b78380f6cb9da337e3.png) 49 | 50 | Follow the comments to guide your code. 51 | 52 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-78ed06d3bd2955cb7ae69f64571edd30.png) 53 | 54 | ## **Final output:** 55 | 56 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-56-05-a08c25022ce2a355b5bc7fbd0f2a673b.gif) 57 | 58 | ## Good luck! 59 | ---------- 60 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /05. Booleans and Conditionals/01. Workbook 3.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.1 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 3.1`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 3.42.57 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-50-40-380551d6b6478513230debdd2416dcb1.png) 6 | 7 | Ask Java! 8 | --------- 9 | 10 | The application will ask questions, and each reply must compare to `true` or `false`. 11 | 12 | ![Screen Shot 2022-10-16 at 3.44.57 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-50-40-eea3163b8013cadbc1f3e6e47aab8d6a.png) 13 | 14 | ## Question 1 15 | > Hi Java, do I have enough change to buy chips? 16 | 17 | Replace the placeholder by comparing the provided variables. 18 | 19 | ```java 20 | double change = 3.50; 21 | double price = 2.50; 22 | 23 | System.out.println("Java: " + (placeholder) + "\n"); 24 | ``` 25 | 26 | ## Questions 2 to 5 27 | Repeat this process for the remaining questions. 28 | 29 | ## Run your code. 30 | -------------- 31 | 32 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-50-40-8f6799faa1c2f69eabc2b90b14cd7e38.png) 33 | 34 | 35 | ## Solution Code 36 | 37 | The solution code is inside the same folder as the starter project. 38 | 39 | ![Screen Shot 2022-10-16 at 4.03.59 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-50-41-20fa674ab331464383e8142b9ef4a40c.png) 40 | 41 | ------- 42 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 43 | -------------------------------------------------------------------------------- /05. Booleans and Conditionals/02. Workbook 3.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.2 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 3.2`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 4.40.05 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-49-14-6d96da78b3dce18ed5fa9bfb5145443f.png) 6 | 7 | ## The Java Mart 8 | 9 | You start with **$100**, and your kids will ask you to buy them stuff. 10 | 11 | ![Screen Shot 2022-10-16 at 5.13.39 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-49-14-0b263341bc2c7a75b8231b555be2834a.png) 12 | 13 | **Scenario 1:** If you have enough money, display `Sure!` and update the wallet value. 14 | 15 | ![Screen Shot 2022-10-16 at 5.06.50 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-49-15-51c08c400977a65be62b16bda56ea93e.png) 16 | 17 | **Scenario 2:** If you don't have enough money, display `Sorry I only have left`. 18 | 19 | ![Screen Shot 2022-10-16 at 5.08.56 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-49-15-8f274ce476a01871feaceb3ee6851016.png) 20 | 21 | ## Run your code 22 | -------------- 23 | 24 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-49-15-52b593a1f0bd1dac2ceeaae1a60744df.png) 25 | 26 | ## Solution Code 27 | 28 | The solution code is inside the same folder as the starter project. 29 | 30 | ![Screen Shot 2022-10-16 at 5.23.27 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-49-15-72f393026ee33f7553387e7e6571b2d2.png) 31 | 32 | ------- 33 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 34 | -------------------------------------------------------------------------------- /05. Booleans and Conditionals/03. Workbook 3.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.3 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 3.3`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 5.44.01 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-47-33-ec1f42d5451126776a52b6260fda1dec.png) 6 | 7 | ## The Quidditch Championship 8 | 9 | This is a modified passage from the book: **Harry Potter and the Half-Blood Prince.** 10 | 11 | ![Screen Shot 2022-10-16 at 8.27.45 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-47-33-0468bd937fb6da40c670dd62c9f0dbcd.png) 12 | 13 | We're going to convert this passage into code. The code starts with the number of points scored by `gryffindor` and `ravenclaw`. 14 | 15 | ```java 16 | public class Championship { 17 | 18 | public static void main(String[] args) { 19 | 20 | int gryffindor = 400; //gryffindor points   21 | int ravenclaw = 200; //ravenclaw points 22 | } 23 | 24 | ``` 25 | 26 | ## 1\. Calculate the difference in points. 27 | --------------------------------------- 28 | 29 | Make an `int` variable called `margin`. It will calculate the margin of points `gryffindor` scored over `ravenclaw`. 30 | 31 | ```java 32 | public class Championship { 33 | 34 | public static void main(String[] args) { 35 | 36 | int gryffindor = 400; //gryffindor points 37 | int ravenclaw = 200; //ravenclaw points 38 | 39 | // margin: amount of points by which gryffindor scored over ravenclaw ; 40 | } 41 | 42 | } 43 | ``` 44 | 45 | ## 2\. if - else if - else. 46 | ------------------------------ 47 | 48 | If `gryffindor` wins by a margin of 300 points or more, `print`: 49 | 50 | > Gryffindor takes the house cup! 51 | 52 | If `gryffindor` wins by a margin of any points or ties, `print`: 53 | 54 | > In second place, Gryffindor! 55 | 56 | If `gryffindor` loses within 100 points, `print`: 57 | 58 | > In third place, Gryffindor! 59 | 60 | `else`, `print`: 61 | 62 | > In fourth place, Gryffindor! 63 | 64 | 65 | ## Run your Code 66 | ### Test Case 1 67 | ```java 68 | int gryffindor = 400; 69 | int ravenclaw = 200; 70 | ``` 71 | `>>In second place, Gryffindor!` 72 | 73 | ### Test Case 2: 74 | 75 | ```java 76 | int gryffindor = 850; 77 | int ravenclaw = 500; 78 | ``` 79 | 80 | `>>Gryffindor takes the house cup!` 81 | 82 | ### Test Case 3: 83 | 84 | ```java 85 | int gryffindor = 620; 86 | int ravenclaw = 500; 87 | ``` 88 | 89 | `>>In second place, Gryffindor!` 90 | 91 | ### Test Case 4: 92 | 93 | 94 | ```java 95 | int gryffindor = 450; 96 | int ravenclaw = 500; 97 | ``` 98 | 99 | `>>In third place, Gryffindor!` 100 | 101 | ### Test Case 5: 102 | 103 | ```java 104 | int gryffindor = 100; 105 | int ravenclaw = 500; 106 | ``` 107 | 108 | `>>In fourth place, Gryffindor!` 109 | 110 | ## Solution Code 111 | 112 | The solution code is inside the same folder as the starter project. 113 | 114 | ![Screen Shot 2022-10-16 at 5.57.24 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-47-33-9e0ab410b279310531c43c67ec2fbef7.png) 115 | 116 | ## Good Luck! 117 | ------- 118 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 119 | -------------------------------------------------------------------------------- /05. Booleans and Conditionals/04. Workbook 3.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.4 2 | 3 | From the `Java-Bootcamp-Resources`, launch the **`Workbook 3.4`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 6.04.12 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-46-13-361bb4ccb52e0fb38450f44a11b5a4d1.png) 6 | 7 | ## The Weather Network 8 | ------------------- 9 | 10 | The workbook starts with a temperature (Celsius). There's also a `String` variable `forecast` that doesn't start with a value. 11 | 12 | ```java 13 | public class WeatherNetwork { 14 | 15 | 16 | public static void main(String[] args) { 17 | int temp = 25; 18 | String forecast; 19 | 20 | 21 | System.out.println(forecast); 22 | } 23 | } 24 | ``` 25 | 26 | ## Task 1 - Update the forecast. 27 | ----------------------------- 28 | 29 | Update the `forecast` variable based on the temperature. 30 | 31 | - Less than or equal to **-1** 32 | 33 | > The forecast is FREEZING! Stay home! 34 | 35 | - Less than or equal to **10** 36 | 37 | > The forecast is Chilly. Wear a coat! 38 | 39 | - Otherwise 40 | 41 | > It's warm. Go outside! 42 | 43 | ## Run your code. 44 | 45 | ### Test Case 1: 46 | ```java 47 | int temp = 25; 48 | ``` 49 | `>>: It's warm. Go outside!` 50 | 51 | ### Test Case 2: 52 | ```java 53 | int temp = -1; 54 | ``` 55 | `>>: The forecast is FREEZING! Stay home!` 56 | 57 | ### Test Case 3: 58 | ```java 59 | int temp = 0; 60 | ``` 61 | `>>: The forecast is Chilly. Wear a coat!` 62 | 63 | ### Test Case 4: 64 | ```java 65 | int temp = 10; 66 | ``` 67 | `>>: The forecast is Chilly. Wear a coat!` 68 | 69 | 70 | ### Test Case 5: 71 | ```java 72 | int temp = 11; 73 | ``` 74 | `>>: It's warm. Go outside!` 75 | 76 | 77 | ### Test Case 6: 78 | ```java 79 | int temp = -12; 80 | ``` 81 | `>>: The forecast is FREEZING! Stay home!` 82 | 83 | ---------- 84 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 85 | -------------------------------------------------------------------------------- /05. Booleans and Conditionals/05. Workbook 3.5.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.5 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 3.5`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 6.44.39 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-44-48-3b3bfdd9b9a24174821e1acdb364df2e.png) 6 | 7 | 8 | 9 | ## Your Work Schedule 10 | ------------------ 11 | 12 | Assume that `day` can be any value between 1 (Monday) and 7 (Sunday). There's also a `boolean` variable: `holiday`. 13 | 14 | ```java 15 | public class WorkSchedule { 16 | 17 | public static void main(String[] args) { 18 | int day = 3; 19 | boolean holiday = true; 20 | } 21 | } 22 | 23 | ``` 24 | 25 | ## Task 1 - Do I have work that day? 26 | --------------------------------- 27 | 28 | In the event of a holiday, `print`: 29 | 30 | > Woohoo, no work 31 | 32 | During the weekend (Saturday or Sunday), `print`: 33 | 34 | > It's the weekend, no work! 35 | 36 | Otherwise, `print`: 37 | 38 | > Wake up at 7:00 :( 39 | 40 | ## Run your code. 41 | -------------- 42 | 43 | ### Test Case 1: 44 | ```java 45 | int day = 3; 46 | boolean holiday = true; 47 | ``` 48 | 49 | `>>woohoo, no work!` 50 | 51 | ### Test Case 2: 52 | 53 | ```java 54 | int day = 3; 55 | boolean holiday = false; 56 | ``` 57 | 58 | `>>Wake up at 7:00 :(` 59 | 60 | ### Test Case 3: 61 | 62 | ```java 63 | int day = 6; 64 | boolean holiday = false; 65 | ``` 66 | `>>It's the weekend, no work!` 67 | 68 | ---------- 69 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /05. Booleans and Conditionals/06. Workbook 3.6.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.6 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 3.6`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 7.03.08 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-42-56-7ec6d9395771792a57f7a495f1247af0.png) 6 | 7 | 8 | ## Your Calendar 9 | ------------- 10 | 11 | The code starts with a `day` variable. Your friend wants to hang out on that day. 12 | 13 | ```java 14 | public class Calendar { 15 | 16 | 17 | public static void main(String[] args) { 18 | String day = "Friday"; 19 | System.out.println("Hey, are you free on " + day + "? \n"); 20 | 21 | 22 | System.out.println("Hmm, let me check my calendar."); 23 | 24 | 25 | } 26 | } 27 | ``` 28 | 29 | `>>Hey, are you free on friday?` 30 | 31 | `>>` 32 | 33 | `>>Hmm, let me check my calendar.` 34 | 35 | ## Task 1 - Check your calendar 36 | 37 | Check that day against 7 days from your calendar. 38 | 39 | 40 | - `case Monday`, `print`: 41 | 42 | > Sorry, I have to stay at work late. 43 | 44 | - `case Tuesday`, `print`: 45 | 46 | > It looks like I have meetings all day. 47 | 48 | - `case Wednesday`, `print`: 49 | 50 | > I have a dentist appointment. Some other time! 51 | 52 | - `case Thursday`, `print`: 53 | 54 | > Sorry, thursday is date night! 55 | 56 | - `case Friday`, `print`: 57 | 58 | > I'm free!! 59 | 60 | - `case Saturday`, `print`: 61 | 62 | > I'm free!! 63 | 64 | - `case Sunday`, `print`: 65 | 66 | > I'm free!! 67 | 68 | - `default`: 69 | 70 | > That's not a day. 71 | 72 | ## Run your code. 73 | ### Test Case 1 74 | ```java 75 | String day = "Friday"; 76 | ``` 77 | `>>: I'm free!!` 78 | 79 | ### Test Case 2 80 | ```java 81 | String day = "Saturday"; 82 | ``` 83 | `>>: I'm free!!` 84 | 85 | ### Test Case 3 86 | 87 | ```java 88 | String day = "Monday"; 89 | ``` 90 | `>>: Sorry, I have to stay at work late.` 91 | 92 | ---------- 93 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /05. Booleans and Conditionals/07. Workbook 3.7.md: -------------------------------------------------------------------------------- 1 | # Workbook 3.7 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 3.7`** folder. 4 | 5 | ![Screen Shot 2022-10-16 at 7.13.08 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-16-29c17dd6c0fc49e7a290baf69e09e6ca.png) 6 | 7 | ## The Royal Bank of Java 8 | ---------------------- 9 | 10 | In this workbook, you work for the Royal Bank of Java. Your job is to approve customers for a loan if they: 11 | 12 | - Have **at least** $10,000 in their savings account. 13 | 14 | - Have **less than** $5,000 in credit card debt. 15 | 16 | - Have worked for **more than** 2 years. 17 | 18 | The user will also need to provide their name. 19 | 20 | Your task is to scan for values and use `if-else` to control how these statements print. 21 | 22 | ```java 23 | public class Bank { 24 | public static void main(String[] args) { 25 | Scanner scan = new Scanner(System.in); 26 | System.out.println("\n****ROYAL BANK OF JAVA****"); 27 | System.out.println("Are you here to get a mortgage? (yes or no)"); 28 | System.out.println("\nGreat! In one line" + 29 | "\nHow much money do you have in your savings?" + 30 | "\nAnd, how much do you owe in credit card debt?"); 31 | System.out.println("\nHow many years have you worked for?"); 32 | System.out.println("What is your name?"); 33 | System.out.println("Congratulations , you have been approved!"); 34 | System.out.println("Sorry, you are not eligible for a mortgage"); 35 | System.out.println("\nOK. Have a nice day!"); 36 | scan.close(); 37 | } 38 | } 39 | ``` 40 | 41 | ## Task 1 - Pick up the user's decision 42 | 43 | The code starts by asking the user if they're here to get a mortgage. Use `Scanner` to pick up their decision. 44 | 45 | ```java 46 | System.out.println("\n****ROYAL BANK OF JAVA****"); 47 | System.out.println("Are you here to get a mortgage? (yes or no)"); 48 | //Task 1 - Pick up the user's decision. 49 | 50 | ``` 51 | 52 | ## Task 2 - `if - else` 53 | 54 | If the decision is `'yes'`, ask the user about their savings and debt. If the decision is anything other than 'yes', print: `'OK. Have a nice day!'`. 55 | 56 | ``` 57 | // -- Print this if the decision is "yes" 58 | System.out.println("\nGreat! In one line" + 59 | "\nHow much money do you have in your savings?" + 60 | "\nAnd, how much do you owe in credit card debt?"); 61 | 62 | 63 | // -- Print this if the decision is not "yes" 64 | System.out.println("\nOK. Have a nice day!"); 65 | 66 | ``` 67 | 68 | Output for `yes`: 69 | 70 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-16-8e6c8a8aeb4e3615b583a1b61bf6c0f6.png) 71 | 72 | Output for `else`: 73 | 74 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-16-d77639567f2a8b708dce950f4a369cc8.png) 75 | 76 | ## Task 3 - Pick up the savings and debt values 77 | -------------------------------------------- 78 | 79 | Pick up and store the savings and debt values. 80 | 81 | ```java 82 | System.out.println("\nGreat! In one line" + 83 | "\nHow much money do you have in your savings?" + 84 | "\nAnd, how much do you owe in credit card debt?"); 85 | // Task 3 - Pick up each value 86 | ``` 87 | 88 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-16-ad9ac7a9f75420e5f9f613171227e56e.gif) 89 | 90 | ## Task 4 - Pick up the number of years 91 | 92 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-17-c95a70fc417225d57db56e5b746886be.png) 93 | 94 | ## Task 5 - Pick up the user's name 95 | Careful not to fall into the `nextLine()` trap. 96 | 97 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-17-2e0b81cda66ff72683b472102beba7c9.png) 98 | 99 | 100 | ## Task 6 - Logical Operator 101 | ------------------------- 102 | 103 | Use a logical operator to check if the user has 104 | 105 | - **at least** $10,000 in their savings account. 106 | 107 | - **less than** $5,000 in credit card debt. 108 | 109 | - **more than** 2 years of work experience. 110 | 111 | If they meet the requirements, print: 112 | 113 | > `Congratulations , you have been approved!` 114 | 115 | Otherwise, print: 116 | 117 | > `Sorry, you are not eligible for a mortgage.` 118 | 119 | Finally, use these values: 120 | 121 | - `savings: 20000` 122 | 123 | - `debt: 1500` 124 | 125 | - `years: 7` 126 | 127 | **Final Ouput:** 128 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-41-17-3910bb831397dc46d23f3e46443001da.gif) 129 | 130 | ---------- 131 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /06. Booleans and Conditionals (Challenge)/Trivia Quiz.md: -------------------------------------------------------------------------------- 1 | # Trivia Quiz 2 | 3 | The quiz will ask multiple-choice questions about common trivia. It tracks the user's answers and prints their final score. 4 | 5 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-26-32-2385e223461c2c1b226c98dd0577e560.gif) 6 | 7 | ## Open the challenge 8 | 9 | From `Java Bootcamp Resources`, launch `Challenge 3`. 10 | 11 | ![Screen Shot 2022-10-16 at 7.18.41 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-26-32-aa312d19f7b1508d332ec2e375df32c9.png) 12 | 13 | ## 1\. Store each answer. 14 | ---------------------- 15 | 16 | Add code that picks up the user's answer. Use the comments to guide your code. 17 | 18 | ``` 19 | System.out.println("1. Which country held the 2016 Summer Olympics?"); 20 | System.out.println("\ta) China\n\tb) Ireland\n\tc) Brazil\n\td) Italy\n"); 21 | //store answer 1 22 | ``` 23 | 24 | 25 | ## 2\. Check each answer. 26 | ---------------------- 27 | 28 | The correct answers are: 29 | 30 | - Question 1: **c** 31 | 32 | - Question 2: **a** 33 | 34 | - Question 3: **d** 35 | 36 | - Question 4: **a** OR **b** is correct 37 | 38 | Update the user's score by 5 points for each correct answer. 39 | 40 | ## 3\. Print a final message. 41 | -------------------------- 42 | 43 | If `score` is 15 or higher, `print`: 44 | 45 | > Wow, you know your stuff! 46 | 47 | If `score` is < than 15 but greater than or equal to 5: 48 | 49 | > Not bad! 50 | 51 | otherwise: 52 | 53 | > better luck next time. 54 | 55 | ## Run your code. 56 | -------------- 57 | 58 | Enter the correct answer to each question. 59 | 60 | - Question 1: **c** 61 | 62 | - Question 2: **a** 63 | 64 | - Question 3: **d** 65 | 66 | - Question 4: **a** OR **b**. 67 | 68 | 69 | ``` 70 | 1. Which country held the 2016 Summer Olympics? 71 |     a) China 72 |     b) Ireland 73 |     c) Brazil 74 |     d) Italy 75 | c 76 | 77 | 2. Which planet is the hottest? 78 |     a) Venus 79 |     b) Saturn 80 |     c) Mercury 81 |     d) Mars 82 | a 83 | 84 | 3. What is the rarest blood type? 85 |     a) O 86 |     b) A 87 |     c) B 88 |     d) AB-Negative 89 | 90 | d 91 | 92 | 4. Which one of these characters is friends with Harry Potter? 93 |     a) Ron Weasley 94 |     b) Hermione Granger 95 |     c) Draco Malfoy 96 | 97 | a 98 | 99 | Your final score is: 20/20 100 | Wow, you know your stuff! 101 | ``` 102 | 103 | ## Running test cases 104 | ------------------ 105 | 106 | **Test case 1** 107 | 108 | Enter the following answers: 109 | 110 | - Question 1: **b** 111 | 112 | - Question 2: **c** 113 | 114 | - Question 3: **d** 115 | 116 | - Question 4: **c** 117 | 118 | Your output should reflect a score of 5/20. It should also print: 119 | 120 | > Not bad! 121 | 122 | **Test case 2** 123 | 124 | Enter the wrong answers to each question: 125 | 126 | - Question 1: **b** 127 | 128 | - Question 2: **c** 129 | 130 | - Question 3: **a** 131 | 132 | - Question 4: **c** 133 | 134 | Your output should reflect a score of 0/20. It should also print: 135 | 136 | > Better luck next time! 137 | 138 | ## Good luck! 139 | ---------- 140 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /07. Functions/01. Workbook 4.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 4.1 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 4.1`** folder. 4 | 5 | ![4.1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-18-29-187ceb5f719366870bd143d0a7c9726c.png) 6 | 7 | ## Bart's detention. 8 | ----------------- 9 | 10 | Bart's teacher wants him to write lines on the chalkboard. 11 | 12 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-18-29-d85cb3b78ff6eea811c5c03359275ed1.png) 13 | 14 | He needs to write this paragraph 6 times: 15 | 16 | `I will not copy and paste code.` 17 | 18 | `I will use Camel Case when writing class names.` 19 | 20 | `I will use lower Camel Case when writing function names.` 21 | 22 | `I will use lower Camel Case when writing variables names.` 23 | 24 | Bart wrote the paragraph once, but it took him a long time! 25 | 26 | ``` 27 | public class Detention { 28 | 29 | 30 | public static void main(String[] args) { 31 | //what Bart did so far 32 | System.out.println("I will not copy and paste code."); 33 | System.out.println("I will use Camel Case when writing class names."); 34 | System.out.println("I will use lower Camel Case when writing function names."); 35 | System.out.println("I will use lower Camel Case when writing variables names."); 36 | } 37 | 38 | 39 | } 40 | ``` 41 | 42 | `>> I will not copy and paste code.` 43 | 44 | `>> I will use Camel Case when writing class names. ` 45 | 46 | `>> I will use lower Camel Case when writing function names. ` 47 | 48 | `>> I will use lower Camel Case when writing variables names.` 49 | 50 | ## Task 1 - Write a function 51 | ------------------------- 52 | 53 | Help Bart write a function that does the task for him. The doc comment will guide you. 54 | 55 | ``` 56 | /** 57 | * Function name: printLines 58 | * 59 | * Inside the function: 60 | * 1. prints the four lines 61 | */ 62 | ``` 63 | 64 | A doc comment is embedded inside `/** ... */`. They're best at describing the function name, parameters, and return value. 65 | 66 | - The name of the function is `printLines`. 67 | 68 | ``` 69 | /** 70 | * Function name: printLines <-- 71 | * 72 | * Inside the function: 73 | * 1. prints the four lines 74 | */ 75 | ``` 76 | 77 | - The comment says nothing about parameters, so you can assume it doesn't take any. 78 | 79 | - The comment says nothing about a return value. So, you can assume the function is `void`. 80 | 81 | - Inside the function, it prints the four lines. 82 | 83 | ``` 84 | /** 85 | * Function name: printLines 86 | * 87 | * Inside the function: 88 | * 1. prints the four lines <-- 89 | */ 90 | ``` 91 | 92 | The doc comment outlines everything you need to make your function. 93 | 94 | ## Task 2 - Call the function 95 | -------------------------- 96 | 97 | Once you finish writing it, call the function six times from `main()`. 98 | 99 | ## Run your code. 100 | -------------- 101 | 102 | 103 | ``` 104 | >>I will not copy and paste code. 105 | >>I will use Camel Case when writing class names. 106 | >>I will use lower Camel Case when writing function names. 107 | >>I will use lower Camel Case when writing variables names. 108 | 109 | >>I will not copy and paste code. 110 | >>I will use Camel Case when writing class names. 111 | >>I will use lower Camel Case when writing function names. 112 | >>I will use lower Camel Case when writing variables names. 113 | 114 | >>I will not copy and paste code. 115 | >>I will use Camel Case when writing class names. 116 | >>I will use lower Camel Case when writing function names. 117 | >>I will use lower Camel Case when writing variables names. 118 | 119 | ... 120 | ``` 121 | ---------- 122 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /07. Functions/02. Workbook 4.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 4.2 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 4.2`** folder. 4 | 5 | ![4.2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-16-57-dec0bb2a80b2435b306a55d3c5e0a6bc.png) 6 | 7 | ## Tip the waiter. 8 | Your bill was $53.50. It's polite to tip the waiter 15% of your bill. 9 | 10 | ## Task 1 - Write a function 11 | ------------------------- 12 | 13 | You will write a function that does this task. 14 | 15 | - Function name: `tipTheWaiter`. It calculates a tip and prints it. 16 | 17 | ```java 18 | /** 19 | * Function name: tipTheWaiter - calculates a tip and prints it. <----- 20 | * @param bill (double). 21 | * 22 | * Inside the function: 23 | * 1. Calculates a tip that's 15 percent of the bill you paid. 24 | * 2. Prints: your service was wonderful! Please, accept this tip: $ 25 | * 26 | */ 27 | ``` 28 | 29 | - Parameters: The function takes one parameter named `bill` of type `double`. 30 | 31 | ```java 32 | /** 33 | * Function name: tipTheWaiter - calculates a tip and prints it. 34 | * @param bill (double). <----- 35 | * 36 | * Inside the function: 37 | * 1. Calculates a tip that's 15 percent of the bill you paid. 38 | * 2. Prints: your service was wonderful! Please, accept this tip: $ 39 | * 40 | */ 41 | ``` 42 | 43 | - Return value: the comment says nothing about a return value. So, you can assume the function is `void`. 44 | 45 | - Inside the function, implement the following logic: 46 | 47 | ```java 48 | /** 49 | * Function name: tipTheWaiter - calculates a tip and prints it. 50 | * @param bill (double). 51 | * 52 | * Inside the function: <----- 53 | * 1. Calculates a tip that's 15 percent of the bill you paid. 54 | * 2. Prints: your service was wonderful! Please, accept this tip: $ 55 | * 56 | */ 57 | ``` 58 | 59 | Task 2 - Call the function 60 | -------------------------- 61 | 62 | Call the function from `main()`. 63 | 64 | Run your code. 65 | -------------- 66 | ``` 67 | Waiter: I hope you enjoyed your meal! 68 | ``` 69 | 70 | ``` 71 | Thank you! 72 | Your service was wonderful! Please, accept this tip: $8.025 73 | ``` 74 | 75 | ---------- 76 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /07. Functions/03. Workbook 4.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 4.3 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 4.3`** folder. 4 | 5 | ![4.3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-15-07-5961986664819407684149de9ba8eb43.png) 6 | 7 | ## Weather 8 | ------- 9 | These are the temperatures for noon, evening, and midnight in Fahrenheit. We need to convert them to Celsius. 10 | 11 | ```java 12 | public static void main(String[] args) { 13 | 14 | 15 | double noon = 77; //temperature in fahrenheit. 16 | double evening = 61; //temperature in fahrenheit 17 | double midnight = 55; //temperature in fahrenheit 18 | 19 | 20 | } 21 | ``` 22 | 23 | ## Task 1 - Write a function 24 | 25 | You will write a function that converts Fahrenheit to Celcius. 26 | 27 | - Function name. 28 | 29 | ```java 30 | /** 31 | * Function name: fahrenheitToCelsius. <----- 32 | * @param fahrenheit (double) 33 | * @return celsius (double) 34 | * 35 | * Inside the function: 36 | * 1. return the celsius temperature. C = (F - 32) * 5/9 37 | */ 38 | ``` 39 | 40 | - Parameter. 41 | 42 | ```java 43 | /** 44 | * Function name: fahrenheitToCelsius. 45 | * @param fahrenheit (double) <------ 46 | * @return celsius (double) 47 | * 48 | * Inside the function: 49 | * 1. return the celsius temperature. C = (F - 32) * 5/9 50 | */ 51 | ``` 52 | 53 | - Return value. 54 | 55 | ```java 56 | /** 57 | * Function name: fahrenheitToCelsius. 58 | * @param fahrenheit (double) 59 | * @return celsius (double) <------ 60 | * 61 | * Inside the function: 62 | * 1. return the celsius temperature. C = (F - 32) * 5/9 63 | */ 64 | ``` 65 | 66 | Inside the function, use the equation to go from Fahrenheit to Celsius. Then, return the result. 67 | 68 | ```java 69 | /** 70 | * Function name: fahrenheitToCelsius. 71 | * @param fahrenheit (double) 72 | * @return celsius (double) 73 | * 74 | * Inside the function: 75 | * 1. return the celsius temperature. C = (F - 32) * 5/9 <---- 76 | */ 77 | ``` 78 | 79 | ## Task 2 - Write another function 80 | 81 | - Function name. 82 | 83 | ```java 84 | /** 85 | * Name: printTemperatures <----- 86 | * @param fahrenheit (double) 87 | * 88 | * Inside the function: 89 | * 1. prints the fahrenheit value: "F: ". 90 | * 2. calls fahrenheitToCelsius, and 91 | * prints the celcius value: "C: \n". 92 | */ 93 | ``` 94 | 95 | - Parameter. 96 | 97 | ```java 98 | /** 99 | * Name: printTemperatures 100 | * @param fahrenheit (double) <----- 101 | * 102 | * Inside the function: 103 | * 1. prints the fahrenheit value: "F: ". 104 | * 2. calls fahrenheitToCelsius, and 105 | * prints the celcius value: "C: \n".. 106 | */ 107 | ``` 108 | 109 | - Return value: The function is `void`. 110 | 111 | - Code the logic inside the function 112 | 113 | ```java 114 | /** 115 | * Name: printTemperatures 116 | * @param fahrenheit (double) 117 | * 118 | * Inside the function: <----- 119 | * 1. prints the fahrenheit value: "F: ". 120 | * 2. calls fahrenheitToCelsius, and prints the celcius value: "C: \n".. 121 | */ 122 | ``` 123 | 124 | ## Task 3 - Call the function 125 | 126 | From `main()`, call the `printTemperatures` function for each value. 127 | 128 | ## Run your code 129 | 130 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-15-07-b57761b438225f30c407af151551f7ca.png) 131 | 132 | ---------- 133 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /07. Functions/04. Workbook 4.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 4.4 2 | 3 | From the `Java Bootcamp Resources`, launch the **`Workbook 4.4`** folder. 4 | 5 | ![4.4.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_03-13-23-4ae5d2e84bdda2fad85477c25e5f3eb4.png) 6 | 7 | ## Drawing with Java 8 | ----------------- 9 | 10 | The user can choose to draw a butterfly, elephant, bear, or snake. 11 | 12 | ``` 13 | System.out.print("\nWhich animal would you like to draw?\n"); 14 | System.out.println("Write 1 for butterfly "); 15 | System.out.println("Write 2 for elephant "); 16 | System.out.println("Write 3 for bear "); 17 | System.out.println("Write 4 for snake "); 18 | ``` 19 | 20 | ## **Task 1: Pick up the user's choice.** 21 | -------------------------------------- 22 | 23 | Using `Scanner`, pick up the user's choice. 24 | 25 | ## **Task 2: Write a function** 26 | ---------------------------- 27 | 28 | - Function name. 29 | 30 | ```java 31 | /** 32 | * Function name: draw <----- 33 | * @param choice: (int) 34 | * 35 | * Inside the function: 36 | * - Based on the choice, draw: 37 | * 1. a butterfly 38 | * 2. elephant 39 | * 3. bear 40 | * 4. snake 41 | */ 42 | ``` 43 | 44 | - Parameters. 45 | 46 | ```java 47 | /** 48 | * Function name: draw 49 | * @param choice: (int) <----- 50 | * 51 | * Inside the function: 52 | * - Based on the choice, draw: 53 | * 1. a butterfly 54 | * 2. elephant 55 | * 3. bear 56 | * 4. snake 57 | */ 58 | ``` 59 | 60 | - Return value: `void`. 61 | 62 | - Inside the function, draw one of the animals based on the user's choice. 63 | 64 | ```java 65 | /** 66 | * Function name: draw 67 | * @param choice: (int) 68 | * 69 | * Inside the function: <--------- 70 | * - Based on the choice, draw: 71 | * 1. a butterfly 72 | * 2. elephant 73 | * 3. bear 74 | * 4. snake 75 | */ 76 | ``` 77 | 78 | The drawing of each animal is inside your workbook. 79 | 80 | ## **Task 3: Call the function** 81 | ----------------------------- 82 | 83 | Call the function from `main()`. 84 | 85 | ## Run your code 86 | ------------- 87 | 88 | Based on the user's choice, the output should draw an animal. 89 | 90 | ---------- 91 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/01. Workbook 5.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-57-42-6995614c95f6d86cf116174e598d9f9f.png) 6 | ## Megaphone. 7 | ---------- 8 | 9 | In this workbook, you will use your Java Megaphone and print this 10 times: 10 | 11 | > If Java was easy, they would call it Python! 12 | 13 | ## Task 1 - Make a `for` loop. 14 | --------------------------- 15 | 16 | Make a `for` loop that prints this message 10 times. 17 | 18 | ```java 19 | >>: If Java was easy, they would call it Python! 20 | >>: If Java was easy, they would call it Python! 21 | >>: If Java was easy, they would call it Python! 22 | >>: If Java was easy, they would call it Python! 23 | >>: If Java was easy, they would call it Python! 24 | >>: If Java was easy, they would call it Python! 25 | >>: If Java was easy, they would call it Python! 26 | >>: If Java was easy, they would call it Python! 27 | >>: If Java was easy, they would call it Python! 28 | >>: If Java was easy, they would call it Python! 29 | ``` 30 | 31 | ## Task 2 - Number each line. 32 | -------------------------- 33 | 34 | Number each line starting from 1. 35 | 36 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-57-42-11000e3fe49bbe705510978d4bf30557.png) 37 | 38 | ---------- 39 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/02. Workbook 5.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-56-34-980d5d50e7538409aa94ec5e39f2ca69.png) 6 | 7 | Bart's detention. 8 | ----------------- 9 | 10 | Bart's teacher wants him to write this line ninety-nine times 11 | 12 | > I will not forget semi-colons. 13 | 14 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-56-34-55e5d8ff6be038afbe029a7283154740.png) 15 | 16 | ## Task 1: Ask Bart to enter the line. 17 | ----------------------------------- 18 | 19 | Ask Bart to enter the line he wants to write. 20 | 21 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-56-34-0947bcdcd895706295e6c27435ddf9b8.gif) 22 | 23 | ## Task 2: Print the line 99 times 24 | -------------------------------- 25 | 26 | Using a loop, print the line 99 times. Number each line starting from **one**. 27 | 28 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-56-34-92dd5033fe6746de9fc8e26c0257ba24.gif) 29 | 30 | ---------- 31 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/03. Workbook 5.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.3`**. 4 | 5 | ![3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-52-56-bea1b51f02bee503d51c3360778be3a0.png) 6 | 7 | ## `println()` vs. `print()` 8 | 9 | This workbook will need to employ the `print` function. In summary: 10 | 11 | - `println()` prints text and moves to a new line. 12 | 13 | ```java 14 | System.out.println(" a "); 15 | System.out.println(" b "); 16 | System.out.println(" c "); 17 | ``` 18 | 19 | `>> a` 20 | 21 | `>> b` 22 | 23 | `>> c` 24 | 25 | - `print` prints text but it does not move to a new line. So, ensuing print calls print on the same line. 26 | 27 | ```java 28 | System.out.print(" a "); 29 | System.out.print(" b "); 30 | System.out.print(" c "); 31 | ``` 32 | 33 | `>> a b c` 34 | 35 | Counting Tool 36 | ------------- 37 | 38 | Timmy's having trouble counting. Let's build a Java app that will help him out. 39 | 40 | ## Task 1 41 | ------ 42 | 43 | Ask Timmy what number he'd like to count up to. 44 | 45 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-52-56-78b983142471113b8a2b68aa6942e39a.png) 46 | 47 | Make sure Timmy can enter the value **BESIDE** the question. 48 | 49 | ## Task 2 50 | ------ 51 | 52 | Count from 0 to that number. If Timmy enters 7, your app should should output: `0 1 2 3 4 5 6 7` 53 | 54 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-52-56-7574d53475c33cb9bce963163689e323.gif) 55 | 56 | ---------- 57 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 58 | -------------------------------------------------------------------------------- /09. Loops/04. Workbook 5.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.4 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.4`**. 4 | 5 | ![4.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-51-38-e5be7d4e8800c5b09991769dd7de2d4d.png) 6 | 7 | ## 99 bottles of beer on the wall. 8 | ------------------------------- 9 | 10 | A song as old as time itself. 11 | 12 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-51-39-3ae34bc503d93eab07cb1c911d6514e9.png) 13 | 14 | ## Task 1 - Write a function 15 | ------------------------- 16 | 17 | 1\. Function name: 18 | 19 | ```java 20 | /** 21 | * Function name -- sing. <------ 22 | * @param i (int) 23 | * 24 | * 25 | * Inside the function: 26 | * 1. print: 27 | * bottles of beer on the wall, bottles of beer! 28 | * take one down, pass it around , bottles of beer on the wall! 29 | */ 30 | ``` 31 | 32 | 2\. Parameters: 33 | 34 | ```java 35 | /** 36 | * Function name -- sing. 37 | * @param i (int) <------- 38 | * 39 | * 40 | * Inside the function: 41 | * 1. print: 42 | * bottles of beer on the wall, bottles of beer! 43 | * take one down, pass it around , bottles of beer on the wall! 44 | */ 45 | ``` 46 | 47 | **3**. Return value: `void`. 48 | 49 | **4**. Inside the function, add the following logic: 50 | 51 | ```java 52 | /** 53 | * Function name -- sing. 54 | * @param i (int) 55 | * 56 | * 57 | * Inside the function: <-------- 58 | * 1. print: 59 | * bottles of beer on the wall, bottles of beer! 60 | * take one down, pass it around , bottles of beer on the wall! 61 | */ 62 | ``` 63 | The first line is some number. The second line is one less the number. 64 | 65 | > **58** bottles of beer on the wall, **58** bottles of beer. 66 | 67 | > take one down, pass it around, **57** bottles of beer on the wall!. 68 | 69 | ## Task 2 - Write a loop 70 | --------------------- 71 | 72 | Make a `for` loop that: 73 | 74 | - starts from `i` = 99. 75 | 76 | - finishes at `i` = 1. 77 | 78 | - loops down in steps of 1. 79 | 80 | Call the function during each run. Your final output should start from 99 bottles of beer on the wall. 81 | 82 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-51-39-f0f6266a835210ac16aed9f1957f3e62.png) 83 | 84 | And end at 0 bottles of beers. 85 | 86 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-51-39-097a4e8601fc710a0283aaea2da3a0e2.png) 87 | 88 | If you get this output, fix your condition. 89 | 90 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-51-39-7ce97db8fed91243057c25e17c5f0916.png) 91 | 92 | ---------- 93 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 94 | -------------------------------------------------------------------------------- /09. Loops/05. Workbook 5.5.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.5 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.5`**. 4 | 5 | ![5.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-50-12-9a3f9bb2e9c23335f7413e663c8b45c2.png) 6 | 7 | Counter Tool revisited. 8 | ----------------------- 9 | 10 | Your app should let the user choose: 11 | 12 | - the steps to count by. 13 | 14 | - a number to count from. 15 | 16 | - a number to count until. 17 | 18 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-50-12-b539c0b600055c820b9c7e5b34e906eb.gif) 19 | 20 | Your program will count from the second number to the third number, in steps of the first. 21 | 22 | ## Task 1 - Get integers from the user. 23 | ------------------------------------ 24 | 25 | You'll ask the user three questions: 26 | 27 | 1\. Pick a number to count by: `` 28 | 29 | 2\. Pick a number to start counting from: `` 30 | 31 | 3\. Pick a number to count to: `` 32 | 33 | The user will submit his answer **BESIDE** each question: 34 | 35 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-50-12-c9e15c40cf2af3b58616e2e70d27b131.png) 36 | 37 | ## Task 2 - Write a loop 38 | --------------------- 39 | 40 | Make a `for` loop that: 41 | 42 | - starts from the second number. 43 | 44 | - stops at the third number. 45 | 46 | - counts in steps of the first. 47 | 48 | Then, print your count in **ONE** line. 49 | 50 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-50-12-ac5ef7332b9f2d31c7be375531d9491b.gif) 51 | 52 | ---------- 53 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/06. Workbook 5.6.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.6 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.6`**. 4 | 5 | ![6.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-48-48-2005d22e8958c7b9d64ec9ac3ce4c372.png) 6 | 7 | ## Even or odd 8 | ----------- 9 | 10 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-48-48-a1d07d37b5ff02fc51206b3f2ada6095.gif) 11 | 12 | ## Task 1 13 | ------ 14 | 15 | Make a `for` loop that counts from 0 to 19. 16 | 17 | ```java 18 | >>: 0 19 | >>: 1 20 | >>: 2 21 | >>: 3 22 | >>: 4 23 | >>: 5 24 | >>:... 25 | >>: 19 26 | ``` 27 | 28 | ## Task 2 29 | ------ 30 | 31 | Using an `if - else` statement, mark each number as even or odd. 32 | 33 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-48-48-a5c39793cce825d20beabda31de097ea.gif) 34 | 35 | Hint: Use the modulus operator `%`. 36 | 37 | ---------- 38 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/07. Workbook 5.7.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.7 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.7`**. 4 | 5 | ![7.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-47-28-c07d828d8f3c2ec3f14f47828add052d.png) 6 | 7 | Fizz Buzz 8 | --------- 9 | 10 | Your program has to print numbers from 0 to 18. 11 | 12 | - If a number is a multiple of three, mark it: Fizz. 13 | 14 | - If a number is a multiple of five, mark it: Buzz. 15 | 16 | - If a number is a multiple of three and five, mark it: FizzBuzz. 17 | 18 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-47-28-a6383f74a637106e4599b0c8b3bbd8f8.png) 19 | 20 | ## Task 1 21 | ------ 22 | 23 | Make a `for` loop that counts from 0 to 18 and print each number. 24 | 25 | ``` 26 | >>: 0 27 | >>: 1 28 | >>: ... 29 | >>: 18 30 | ``` 31 | 32 | ## Task 2 33 | ------ 34 | 35 | Set up an `if - else if - else` statement. 36 | 37 | - if the number is a multiple of three, mark it: `Fizz`. 38 | 39 | - if the number is a multiple of five, mark it: `Buzz`. 40 | 41 | - if the number is a multiple of three and five, mark it: `FizzBuzz`. 42 | 43 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-47-28-99653c2c469d9a61e2129a19503c62f2.png) 44 | 45 | **Hints:** 46 | ---------- 47 | 48 | - A number is a multiple of X if `number` ÷ `X` results in a remainder of zero. 49 | 50 | - There are three conditions for Fizz, Buzz, and FizzBuzz. **Be careful about their order**. If something is FizzBuzz, it also satisfies the conditions for Fizz and Buzz. 51 | 52 | ---------- 53 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/08. Workbook 5.8.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.8 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.8`**. 4 | 5 | ![8.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-46-11-abb1b9613851342e1a6b27d725420e17.png) 6 | 7 | Guess the number 8 | ---------------- 9 | 10 | In this workbook, the user has to keep guessing a number until they get it right. 11 | 12 | Task 1 13 | ------ 14 | 15 | Store a "secret" number between 1 and 5. Then, prompt the user to enter a guess. 16 | 17 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-46-11-51f0dae96047bd3b86c13f827e9d3b1a.png) 18 | 19 | Task 2 20 | ------ 21 | 22 | Set up a loop that keeps the user guessing until they get it right. 23 | 24 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-46-12-e452d39139884c0ab72d376e851cfe81.png) 25 | 26 | In other words, the loop should keep running **while** the guess is different from the secret. 27 | 28 | Task 3 29 | ------ 30 | 31 | After they guess the number, print: 32 | 33 | > You got it! 34 | 35 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-46-12-e60ede8e42692cad4518df4a9123ad86.gif) 36 | 37 | ---------- 38 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/09. Workbook 5.9.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.9 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.9`**. 4 | 5 | ![9.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-43-33-f60eccd5ea60e3482b227d448fbcfc93.png) 6 | 7 | ## Signing in 8 | ---------- 9 | 10 | In this workbook, Samantha will sign into her favorite social network: Javagram! 11 | 12 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-43-33-668e7dc03028281ec4ea5a3b5dc61a71.gif) 13 | 14 | ## Task 1 15 | ------ 16 | 17 | The program starts with a stored username and password: 18 | 19 | > username: Samantha password: Java<3 20 | 21 | When signing in, prompt the user to enter their username and password. 22 | 23 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-43-34-5e4c53bbe08a1bc9ce696d6e70f17e8d.png) 24 | 25 | ## Task 2 26 | ------ 27 | 28 | Set up a loop that keeps running while the username OR password is incorrect. 29 | 30 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-43-34-c63ff47d2f1260a82e18a9a8171b7b04.gif) 31 | 32 | ## Task 3 33 | ------ 34 | 35 | After they enter the correct information, print: 36 | 37 | > Sign in successful. Welcome! 38 | 39 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-43-34-bad99cd40dfd0cd3f3749c2bd001bc5f.gif) 40 | 41 | ---------- 42 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/10. Workbook 5.10.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.10 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.10`**. 4 | 5 | ![10.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-41-42-878f81e20a3961e9c1e865ea8e95b747.png) 6 | 7 | ## Roll doubles 8 | ------------ 9 | 10 | The user must keep rolling dice until they roll doubles! 11 | 12 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-41-42-0f23a174a5c173a38979618801e88ff6.gif) 13 | 14 | ## Task 1 15 | ------ 16 | 17 | First, make a function that returns a random number between 1 and 6. 18 | 19 | ``` 20 | /** 21 | * Function name: rollDice -- rolls a dice between 1 and 6 22 | * @return randomNumber (int) 23 | * 24 | */ 25 | ``` 26 | 27 | ## Task 2 28 | ------ 29 | 30 | Call the `rollDice()` function twice, and store the values in variables: `dice1` and `dice2`. Then, print each dice value as follows: 31 | 32 | > `System.out.println("Dice 1: " + dice1);` 33 | 34 | > `System.out.println("Dice 2: " + dice2 + "\n");` 35 | 36 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-41-42-13e2d29d3a03ac669ed334623195ea5a.png) 37 | 38 | ## Task 3 39 | ------ 40 | 41 | Set up a loop that keeps running **while** the two dice aren't the same. During each run, re-roll the dice and print both values. 42 | 43 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-41-42-a64149c45c1c801e5b201ae65dc130c0.png) 44 | 45 | ## Task 4 46 | ------ 47 | 48 | After they roll doubles, print: 49 | 50 | > You rolled doubles! 51 | 52 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-41-42-da2b64ce2a1c1b3883f456632de9b432.png) 53 | 54 | ---------- 55 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /09. Loops/11. Workbook 5.11.md: -------------------------------------------------------------------------------- 1 | # Workbook 5.11 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 5.11`**. 4 | 5 | ![11.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-40-16-8db157abdcd442d98720718c29aa347b.png) 6 | 7 | Task 1 8 | ------ 9 | 10 | Print the rules to the user: 11 | 12 | `>> Let's play Rolling Java. Type anything to start.` 13 | 14 | **`scan.nextLine`** 15 | 16 | `>> Great, here are the rules:\n` 17 | 18 | `>> - If you roll a 6, the game stops.` 19 | 20 | `>> - If you roll a 4, nothing happens.` 21 | 22 | `>> - Otherwise, you get 1 point.\n` 23 | 24 | `>> You must collect at least 3 points to win. Enter anything to roll:` 25 | 26 | **`scan.nextLine`** 27 | 28 | 29 | Task 2 30 | ------ 31 | 32 | Make a `while` loop that runs forever. 33 | 34 | Place your second `scan.nextLine()` from **Task 1** as the first line in your loop. Print `hey` in your loop's second line. 35 | 36 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-40-16-1a63c4308e4ec4761374e3375960102d.gif) 37 | 38 | After testing your code, remove the `hey` print. 39 | 40 | Task 3 41 | ------ 42 | 43 | Define the `rollDice` function. 44 | 45 | ```java 46 | /** 47 | * Function name: rollDice 48 | * @return randomNumber (int) 49 | * 50 | * Inside the function: 51 | * - return a random number between one and six. 52 | */ 53 | ``` 54 | 55 | Task 4 56 | ------ 57 | 58 | During each run, call `rollDice()` and store the value in `diceRoll`. Print each dice roll: `You rolled a .`. 59 | 60 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-40-17-6250559619e75e5c61054180d3e61dda.gif) 61 | 62 | Task 5 63 | ------ 64 | 65 | Whenever the user rolls a **6**: 66 | - print: `End of game.` 67 | - stop the game. 68 | 69 | Whenever the user rolls a 4: 70 | - print: `Zero points. Keep rolling.` 71 | 72 | When the user rolls anything else: 73 | - update the `score` variable by 1 74 | 75 | - print: `One point. Keep rolling`. 76 | 77 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-40-17-521750e7dc17e00c3e8ef7ccc8e377fa.gif) 78 | 79 | Task 6 80 | ------ 81 | 82 | After the game ends, check the user's points. If the score is greater than or equal to 3, print: 83 | 84 | - `Wow, that's lucky. You win!` 85 | 86 | Otherwise, print: 87 | 88 | - `Tough luck, you lose :(` 89 | 90 | **Winning scenario:** 91 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-40-17-75c6a194697ee1a389d3e698bd19aefa.gif) 92 | 93 | **Losing scenario:** 94 | 95 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-40-17-7a635e34f81aa6aa4c7ee0a3fa4bdf1d.gif) 96 | 97 | ---------- 98 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /10. Loops (Challenge)/Part 1.md: -------------------------------------------------------------------------------- 1 | # Blackjack 2 | 3 | Blackjack is the most popular table game at casinos. You're going to build a simple version of Blackjack. 4 | 5 | **Part 1: Starting the game** 6 | 7 | - In Blackjack, the player plays against the dealer. 8 | 9 | - The dealer gives the player two cards faceup. 10 | 11 | - The dealer also starts with two cards. But, only one of the dealer's cards is faceup. The other is facedown. 12 | 13 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-14-07-e2cd2da094cfeb1f9b86aec53075080d.gif) 14 | 15 | **Part 2: During the game** 16 | 17 | - First, it's the player's turn. The player can decide to **hit** or **stay**. 18 | 19 | - **hit**: draw another card. 20 | 21 | - **stay**: do nothing. 22 | 23 | - If the player decides to hit, and their hand value exceeds 21, they go **bust** (lose). 24 | 25 | - Once the player decides to stay, the dealer reveals the hidden card. 26 | 27 | - Then, the dealer must **hit** until their cards total up to 17. At 17 points or higher, the dealer must stay. 28 | 29 | - You win if your hand value is higher than the dealer's hand. 30 | 31 | - You win if the dealer goes bust (exceeds 21) 32 | 33 | - You lose if the dealer's hand value is higher than yours. 34 | 35 | **Full output:** 36 | 37 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-14-07-146f4d5526e2d7b928888087b8f64cdc.gif) 38 | 39 | ## Launch the challenge 40 | -------------------- 41 | 42 | From `Java Bootcamp Resources` -> `Module 1` -> `5. Loops`, open `Challenge 5`. 43 | 44 | ## Task 1 45 | ------ 46 | Define the `drawRandomCard` function. 47 | 48 | ```java 49 | /** 50 | * Function name -- drawRandomCard 51 | * @return (int) 52 | * 53 | * Inside the function: 54 | * 1. Gets a random number between 1 and 13. 55 | * 2. Returns a card. 56 | */ 57 | ``` 58 | 59 | ## Task 2 60 | ------ 61 | 62 | Make a function that receives a card number and returns the `String` drawing. You can grab the cards from `cards.txt`. Use the doc comment inside the workbook as a guide. 63 | 64 | ## Task 3 65 | ------ 66 | 67 | Write code that waits for the user to press enter. 68 | 69 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-14-07-e98ebd84f5280a9070109f0a48b2a327.gif) 70 | 71 | ## Task 4 72 | ------ 73 | 74 | When the game starts, the dealer will give you two cards faceup. Get the code to deal you two random cards and print them: 75 | 76 | ``` 77 | -- Get two random cards. 78 | -- Print them: (new line) You get a (new line) and a 79 | ``` 80 | 81 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-14-08-4c04de312b2df64b72dce3d83cac1f89.gif) 82 | 83 | ## Task 5 84 | ------ 85 | 86 | After you print your cards, print the hand value. The hand value is the sum of your card values. 87 | 88 | ```java 89 | your total is: 90 | ``` 91 | 92 | In blackjack, the face cards (Jack, Queen, and King) have values of 10. 93 | 94 | **Hint**: look into `Math.min`. 95 | 96 | **Example output:** 97 | 98 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-14-08-6f1f435b4c2efd59b0bc0290b882b652.gif) 99 | 100 | ## Task 6 101 | ------ 102 | 103 | The dealer gets two cards as well. Print the dealer's first card, and print the next one facedown. You can find the `String` for a facedown card being returned from a function called: `faceDown()`. 104 | 105 | ``` 106 | 1. print: 107 | 108 | (new line) The dealer shows (new line) and 109 | has a card facing down (new line) ; 110 | 111 | 2. print: 112 | (new line) The dealer's total is hidden 113 | ``` 114 | 115 | That's all for part 1. Your final output should appear as follows: 116 | 117 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-14-08-d8db3808d87937f2272208633a0b385e.gif) 118 | 119 | ## Good luck! 120 | ---------- 121 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /10. Loops (Challenge)/Part 2.md: -------------------------------------------------------------------------------- 1 | # Blackjack (part 2) 2 | 3 | In part 1, you wrote the logic for starting the game. 4 | 5 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-56-f64571187f7dcded6c963119737241f3.gif) 6 | 7 | In part 2, you will write the logic for playing the game. Recall: 8 | 9 | - First, it's the player's turn. The player can decide to **hit** or **stay**. 10 | 11 | - **hit**: draw another card. 12 | 13 | - **stay**: do nothing. 14 | 15 | - If the player decides to hit, and their hand value exceeds 21, they go **bust** (lose). 16 | 17 | - Once the player decides to stay, the dealer reveals the hidden card. 18 | 19 | - Then, the dealer must **hit** until their total gets to 17. At 17 points or higher, the dealer's turn ends. 20 | 21 | - You win if your hand value is higher than the dealer's hand. 22 | 23 | - You win if the dealer goes bust (exceeds 21) 24 | 25 | - You lose if the dealer's hand value is higher than yours. 26 | 27 | **Final output:** 28 | 29 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-57-68a1f51207930ee744ecd8267f6661ee.gif) 30 | 31 | ## Task 7 32 | ------ 33 | 34 | Make a function that asks the user to hit or stay. 35 | 36 | ```java 37 | /** 38 | * Function name -- hitOrStay 39 | * @return (String) 40 | * 41 | * Inside the function: 42 | * 1. Asks the user to hit or stay. 43 | * 44 | * 2. If the user doesn't enter "hit" or "stay" 45 | * Run a while loop 46 | * During each run, println: Please write 'hit' or 'stay' 47 | * 48 | * 3. Returns the user's option 49 | */ 50 | ``` 51 | 52 | If the user doesn't enter "hit" or "stay", keep asking them to try again by printing: 53 | 54 | `"Please write 'hit' or 'stay'"` 55 | 56 | The condition for this while loop is kind of tricky. I recommend using a while loop that runs forever and breaking it when it's appropriate. Test your function by calling it from `main()`. 57 | 58 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-57-fa090f9aa33b03d5c7accfb57352cd50.gif) 59 | 60 | ## Task 8 61 | ------ 62 | 63 | In Task 8, you will keep asking the player to hit or stay. In other words, make a `while` loop that runs forever. Then, call your function inside the `while` loop. Every time the player hits, draw a new card and calculate their new total. Then, print: 64 | 65 | - `(new line) You get a (new line) ` 66 | 67 | - ` your new total is ` 68 | 69 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-57-a4b897c0dc377d305de09269f901826d.gif) 70 | 71 | - Once the player 'stays', break the loop. 72 | 73 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-57-03e2d36dcf6cd6dad26729dcbac48c12.gif) 74 | 75 | ## Task 9 76 | ------ 77 | 78 | While the player is hitting, if they go bust (total exceeds 21) print: `"Bust! Player loses"`. Then, shut down the game with `System.exit(0)` (`System.exit(0)` terminates execution). 79 | 80 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-58-b11cc3d38b602519a05ef527974897cb.gif) 81 | 82 | ## Task 10 83 | ------- 84 | 85 | After the player chooses to stay, it becomes the dealer's turn. First, reveal the dealer's hidden card. 86 | 87 | Print: 88 | 89 | - `(new line) Dealer's turn` 90 | 91 | - `(new line) The dealer's cards are (new line) (new line) and a (new line) ` 92 | 93 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-58-ea836c69c95c61d095ec92a1301e7001.gif) 94 | 95 | ## Task 11 96 | ------- 97 | 98 | The dealer must keep "hitting" until their total gets to 17. 99 | Every time the dealer hits, print: 100 | 101 | - `(new line) Dealer gets a (new line) ` 102 | 103 | - `(new line) Dealer's total is ` 104 | 105 | At 17 points or higher, end the dealer's turn. 106 | 107 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-58-bc1020afffe1565237aa3799458b7d38.gif) 108 | 109 | ## Task 12 110 | ------- 111 | 112 | If the dealer's total is higher than 21, print: `"Bust! Dealer loses"` and end the game with `System.exit(0)`. 113 | 114 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-58-cd1534b9e77c31c0bc391c2a5a68b589.gif) 115 | 116 | ## Task 13 117 | ------- 118 | 119 | If at this point, the program didn't terminate, compare the dealer and player's hand values. 120 | 121 | - If the player's hand value is higher, print: `Player wins!` 122 | 123 | - Otherwise, print: `Dealer wins!`. 124 | 125 | **Final output:** 126 | 127 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-17-58-eae6a245eba0e4c3f440167680b9b718.gif) 128 | 129 | ## Good luck! 130 | ---------- 131 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/01. Workbook 6.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.1`**. 4 | 5 | ![6.1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-54-29-79364443b4ec0f3858f714ebae2b5b8d.png) 6 | 7 | ## Task 1 8 | 9 | Create an array called `seats` that stores five students. 10 | ```java 11 | "Harry", "Neville", "Ron", "Hermione", "Seamus" 12 | ``` 13 | 14 | ## Task 2 15 | 16 | Replace each placeholder by indexing values from the array. 17 | 18 | ![Screen Shot 2022-10-31 at 7.55.05 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-54-29-adf01f091f269bd1ddbf9814cd16fb38.png) 19 | 20 | ## Result 21 | 22 | ``` 23 | >>: It's time to take your 5th year exams. Please, take your seats. 24 | >>: 25 | >>: Harry, you will take seat 0 26 | >>: Neville, you will take seat 1 27 | >>: Ron, you will take seat 2 28 | >>: Hermione, you will take seat 3 29 | >>: Seamus, you will take seat 4 30 | ``` 31 | 32 | ---------- 33 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/02. Workbook 6.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.2`**. 4 | 5 | ![Untitled3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-57-20-cad6ed397a919620fc7f088ab21fef10.png) 6 | 7 | Exams (Revisited) 8 | ---------------- 9 | 10 | Another wave of students needs to write their exams. 11 | 12 | ## Task 1 13 | 14 | Create a new array of five students. 15 | 16 | ```java 17 | "Malfoy", "Crabbe", "Goyle", "Pansy", "Dean" 18 | ``` 19 | ## Task 2 20 | ------ 21 | 22 | Create a `for` loop that runs through the array, and prints a message for each element. 23 | 24 | ### Result 25 | ``` 26 | >>: It's time to take your 5th year exams. Please, take your seats. 27 | >>: 28 | >>: Malfoy, you will take seat 0 29 | >>: Crabbe, you will take seat 1 30 | >>: Goyle, you will take seat 2 31 | >>: Pansy, you will take seat 3 32 | >>: Dean, you will take seat 4 33 | ``` 34 | 35 | ---------- 36 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/03. Workbook 6.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.3`**. 4 | 5 | ![Untitled123.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-59-11-2a353fd207a915f4e7ae15d1a0e347b9.png) 6 | 7 | ## Java Grocer 8 | 9 | In this workbook, your job is to help customers find what they're looking for. 10 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-59-11-82eea8d6834b926d226fed8c18824bfb.png) 11 | 12 | ## Task 1 13 | 14 | Create an array that stores aisles. 15 | ```java 16 | "apples", "bananas", "candy", "chocolate", "coffee", "tea" 17 | ``` 18 | 19 | ## Task 2 20 | 21 | A customer is looking for coffee. 22 | ```java 23 | System.out.println("\nDo you sell coffee?"); 24 | ``` 25 | 26 | Create a `for` loop that searches the array for the `coffee` aisle. 27 | 28 | ```java 29 | 0 1 2 3 4 5 30 | "apples", "bananas", "candy", "chocolate", "coffee", "tea" 31 | ``` 32 | Once you find the aisle (when your condition is `true`), display the following message: 33 | 34 | ```java 35 | System.out.println("\nWe have that in aisle: "); 36 | ``` 37 | ## Result 38 | 39 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-59-11-2e5ddc78f25951755878fba6efe6a1a5.png) 40 | 41 | ---------- 42 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/04. Workbook 6.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.4 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.4`**. 4 | 5 | ![Untitled4.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-04-54-c92101d09bb667c4df42507f388aa5b0.png) 6 | 7 | ## Task 1 8 | 9 | Use `Scanner` to pick up the user's response. Store the response in a `String` variable. 10 | ``` 11 | >>: Welcome to Java Grocers. 12 | >>: What can I help you find? 13 | ``` 14 | 15 | ## Task 2 16 | ------ 17 | 18 | Using the `for` loop, check every element in the array. 19 | 20 | ```java 21 | 0 1 2 3 4 5 22 | "apples", "bananas", "candy", "chocolate", "coffee", "tea" 23 | ``` 24 | 25 | 26 | If there is a match, break the loop and print the aisle (index) that they're looking for. 27 | 28 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-04-54-3b28f729d9545d80702bf2ca4f7e525b.gif) 29 | 30 | Aside from adding interactivity, the code should be identical to Workbook 6.3. 31 | 32 | ---------- 33 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/05. Workbook 6.5.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.5 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.5`**. 4 | 5 | ![Untitled5.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-06-43-b4047a3d1ad57346ced85cfdc82bf5d5.png) 6 | 7 | ## Task 1 8 | 9 | Make a function that returns a random number between 0 to 49999. 10 | 11 | ```java 12 | /** 13 | * Function name - randomNumber 14 | * @return (int) 15 | * 16 | * Inside the function 17 | * - returns a random number between 0 to 49999 18 | * 19 | */ 20 | ``` 21 | 22 | ## Task 2 23 | 24 | Create an array that stores 10 random numbers. 25 | 26 | ## Task 3 27 | 28 | Use a `for` loop to print every element on the same line. Leave one space between each element. 29 | 30 | ``` 31 | Here are the scores: 14775 48328 7928 27102 21787 21063 38096 42711 32863 23707 32 | ``` 33 | 34 | ## Task 4 35 | 36 | Your code contains a `highScore` variable. 37 | 38 | ```java 39 | int highScore = 0; 40 | ``` 41 | Use a `for` loop to update the variable with the highest score in the array, and print it. 42 | 43 | **Hint**: your loop needs a condition that updates the variable whenever an element is higher. 44 | 45 | ## Result 46 | 47 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-06-43-0af2ea258bcbfeea4eca04c0ad5475df.png) 48 | 49 | ---------- 50 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/06. Workbook 6.6.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.6 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.6`**. 4 | 5 | ![Untitled6.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-07-55-717b3897ce4bea09cd2be60b2f835696.png) 6 | 7 | ## Attention 8 | 9 | This workbook continues from workbook 6.5. 10 | 11 | ## Task 1 12 | 13 | Create a variable `seat` that starts at 0. 14 | 15 | ```java 16 | int seat = 0; 17 | ``` 18 | Using a `for` loop, find the seat number (**index**) that matches the highest score and print it. 19 | 20 | ![35dfe411-603f-4756-b840-ca18703ceed7.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-07-56-4e1a24de13e852e4801272b4ad0e3209.png) 21 | 22 | ---------- 23 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/07. Workbook 6.7.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.7 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.7`**. 4 | 5 | ![7.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-08-50-306661d0be43c2f4f878417fc1941c7e.png) 6 | 7 | ## Task 1 8 | ------ 9 | 10 | Inside the workbook, an array stores Java's fight record. 11 | 12 | ```java 13 | String[] record = {"WIN", "WIN", "WIN", "LOSS", "WIN", "WIN", "LOSS"}; 14 | ``` 15 | 16 | Use a `for` loop to count the number of wins, and update the following variable. 17 | ```java 18 | int wins = 0; 19 | ``` 20 | Use a `for` loop to count the number of losses, and update the following variable. 21 | 22 | ```java 23 | int losses = 0; 24 | ``` 25 | 26 | ## Result 27 | 28 | Print your results. 29 | 30 | ![a36dcd41-c71f-4317-aca6-87c10732c0b3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-08-51-5397709a8c022ffc9794a5ae7dc8a97e.png) 31 | 32 | ---------- 33 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/08. Workbook 6.8.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.8 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.8`**. 4 | 5 | ![8.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-09-52-aeb2a9d0c50f0292b441a99a02c89147.png) 6 | 7 | ## Task 1 8 | Create an array that stores three apples you purchased: 9 | 10 | ```java 11 | "Gala", "Granny Smith", "Macintosh" 12 | ``` 13 | 14 | Create another array that stores the price of each apple: 15 | 16 | ```java 17 | 1.99, 1.49, 1.29 18 | ``` 19 | 20 | ## Task 2 21 | 22 | Use a `for` loop to print each apple and its price. 23 | 24 | 25 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_02-09-52-b509f761bfd4fe8b40a01f687edeeb80.png) 26 | 27 | ---------- 28 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/09. Workbook 6.9.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.9 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.9`**. 4 | 5 | ![Tax.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-50-09-612d5def34a2fa9b5a77947cf626aae1.png) 6 | 7 | 8 | ## Task 1 9 | 10 | The workbook contains an array that stores four prices. 11 | 12 | ```java 13 | double[] price = {1.99, 2.99, 3.99, 4.99}; 14 | ``` 15 | 16 | Create another array `afterTax` with the same length. 17 | 18 | ## Task 2 19 | 20 | **Tax is 13%**. Use a loop to update each element in `afterTax` to equal the original price + tax. 21 | 22 | ## Task 3 23 | 24 | Use `Arrays.toString` to print the arrays. 25 | 26 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-50-09-81155a8bb84cb507ae6f438e3d9e4937.png) 27 | 28 | ---------- 29 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/10. Workbook 6.10.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.10 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.10`**. 4 | 5 | ![Untitled10.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-51-35-2ba72054f118ad956e6133e9d04f4f11.png) 6 | 7 | 8 | ## Task 1 9 | 10 | Create a `for` loop that runs through the length of the `toppings` array. Inside the `for` loop: 11 | 12 | 1. Print each index number followed by a dot. 13 | 14 | ![Screen Shot 2022-11-01 at 6.12.34 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-51-35-070fd08db7005dbe11a6cbf71c708e9c.png) 15 | 16 | 2. **Beside** the number, pick up the user's topping. 17 | 18 | ![animation.gif](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-51-36-c65493a118ddb0626ec5e5a91bd6906a.gif) 19 | 20 | Store every topping the user inputs in the `toppings` array. 21 | 22 | ## Task 2 23 | ------ 24 | 25 | Create a `for` loop that runs through the length of the array and prints each topping. 26 | 27 | ![Screen Shot 2022-11-01 at 6.13.36 PM.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-51-36-6e1efa37274a953a8d21471b6921180d.png) 28 | 29 | ---------- 30 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/12. Workbook 6.12.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.12 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.12`**. 4 | 5 | ![6.12.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-46-09-7e52ba253e43e179b991334d6faf4f75.png) 6 | 7 | ## Task 1 8 | 9 | You're feeling good about these lottery numbers. 10 | ```java 11 | int[] ticket = {34, 43, 45, 65, 21, 54}; 12 | ``` 13 | 14 | Use `Arrays.copyOf()` to copy all the elements of `ticket` into `ticket2`. Change the third value to **54**. 15 | 16 | ```java 17 | int[] ticket = {34, 43, 45, 65, 21, 54}; 18 | int[] ticket2 = // 34 - 43 - 54 - 65 - 21 - 54. 19 | ``` 20 | 21 | ## Task 2 22 | 23 | Create a function that prints the ticket numbers. Follow the steps below: 24 | 25 | ```java 26 | /** 27 | * Function name -- printTicketNumbers 28 | * @param ticket ( int[] ) 29 | * 30 | * Inside the function: 31 | * 1. Use a loop to print the numbers in one line. 32 | * System.out.print(ticket[i] + " "); 33 | * 34 | * 2. After the loop, print two new lines. 35 | * System.out.print("\n\n"); 36 | * 37 | */ 38 | ``` 39 | 40 | Call the function for each ticket: 41 | 42 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-46-09-c06c213160e34d1a068009f8181333a9.png) 43 | 44 | ---------- 45 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/13. Workbook 6.13.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.13 2 | 3 | From the `Java Bootcamp Resources`, open **`Workbook 6.13`**. 4 | 5 | ![6.13.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-37-39-7133ff875f920ea4740ef1b5f012149a.png) 6 | 7 | ## Task 1 8 | 9 | Create a 2D array of `double` values that can hold **3 rows** and **5 elements** per row. 10 | 11 | ## Task 2 12 | Populate your 2D array with values from the following table: 13 | 14 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-37-40-70f8a76f0d75e529e15c9577e4d270fe.png) 15 | 16 | For the sake of exercise, do it the *long* way (indexing elements one by one). 17 | ```java 18 | prices[x][x] = 12.99 19 | prices[x][x] = 8.99 20 | //.... 21 | ``` 22 | 23 | ## Task 3 24 | 25 | Print the prices of each row using this format: 26 | 27 | ```java 28 | System.out.println("Baking: " + prices[0][0] + " " + prices[0][1] + " "...); 29 | ``` 30 | 31 | ### Result 32 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-37-40-a9bbf78659779f156443fbb1afceb2dd.png) 33 | 34 | ## Task 4 35 | 36 | Define the array in a single line. 37 | 38 | ```java 39 | double[][] prices = { 40 | {12.99, 8.99, 9.99, 10.49, 11.99}, 41 | {0.99, 1.99, 2.49, 1.49, 2.99}, 42 | {8.99, 7.99, 9.49, 9.99, 10.99} 43 | }; 44 | ``` 45 | 46 | ---------- 47 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/13a. Workbook 6.13Revisit.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.13 (Revisited) 2 | 3 | Re-write your print logic from Workbook 6.13 to use a nested loop. 4 | 5 | ### **Outer Loop** 6 | ```java 7 | switch (i) { 8 | case 0: System.out.print("Baking: "); break; 9 | case 1: System.out.print("Beverage: "); break; 10 | case 2: System.out.print("Cereals: "); break; 11 | } 12 | ``` 13 | 14 | ### **Inner Loop** 15 | ```java 16 | System.out.print(prices[i][j] + " "); 17 | ``` 18 | After the inner loop runs to completion, print a new line. 19 | ```java 20 | System.out.print("\n"); 21 | ``` 22 | ### Final Result 23 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-34-16-524b4fcd96e62b9af04396c9a0cdb783.png) 24 | 25 | ---------- 26 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/14. Workbook 6.14.md: -------------------------------------------------------------------------------- 1 | # Workbook 6.14 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 6.14`**. 4 | 5 | ![Untitled4.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-35-39-fd330312cb254a1b0b0aff588869c6c4.png) 6 | 7 | ## Task 1 8 | 9 | This function returns a random number between 0 and 99. Copy it into your class. 10 | 11 | ```java 12 | public static int randomNumber() { 13 | double randomNumber = Math.random()*100; 14 | return (int)randomNumber; 15 | } 16 | ``` 17 | 18 | ## Task 2 19 | 20 | Write a function that prints the contents of an `int[][]` array. 21 | 22 | ```java 23 | /** 24 | * Function name: print2DArray 25 | * @param array ( int[][] ) 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | */ 33 | ``` 34 | The function uses a nested loop. The inner loop prints each row in one line. 35 | 36 | ```java 37 | /** 38 | * Function name: print2DArray 39 | * @param array ( int[][] ) 40 | * 41 | * Inside the function: 42 | * 1. Nested loop: 43 | * - Inner Loop: System.out.print(array[i][j] + " "); 44 | * 45 | */ 46 | ``` 47 | 48 | After the inner loop runs to completion, print a new line. 49 | ```java 50 | /** 51 | * Function name: print2DArray 52 | * @param array ( int[][] ) 53 | * 54 | * Inside the function: 55 | * 1. Nested loop: 56 | * - Inner Loop: System.out.print(array[i][j] + " "); 57 | * - After the Inner Loop Completes: System.out.print("\n"); 58 | */ 59 | ``` 60 | 61 | Call `print2DArray` for the following array. 62 | ```java 63 | int[][] array = { 64 | {48, 56, 56, 76, 0, 81, 51, 81, 99, 70}, 65 | {38, 52, 73, 6, 10, 56, 1, 71, 47, 9}, 66 | {85, 35, 47, 98, 91, 25, 69, 52, 2, 93} 67 | }; 68 | ``` 69 | ### Result 70 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-35-39-4eca2efa184ed5509c90162700433358.png) 71 | 72 | Delete the array if you achieve the result. 73 | 74 | ## Task 3 75 | 76 | Create a 2D array with **100 rows** and **10 columns**. Then call `print2DArray`. 77 | 78 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-35-39-ab87deb721255fa2261338f101575bb7.png) 79 | 80 | ## Task 4 81 | 82 | Use a nested loop to populate the array with random numbers before calling: `print2DArray`. 83 | 84 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-35-39-bb25f9c1e3bb01a55385fa702a01f45b.png) 85 | 86 | ---------- 87 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /11. Arrays/15. Javapedia.md: -------------------------------------------------------------------------------- 1 | # Javapedia 2 | 3 | Javapedia is a free encyclopedia that anyone can edit. As a world-renowned editor, your task is to submit information about famous historical figures. 4 | 5 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-53-3aef7cbfce3c2d875fad09db5465eb84.gif) 6 | 7 | Then, Javapedia will print the content from its "database" (in our case, a 2D array) 8 | 9 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-53-b4371cf72ec36daf50327b16a88b1fec.gif) 10 | 11 | Javapedia also lets the user search popular figures by name: 12 | 13 | ``` 14 | **********Javapedia********** 15 | How many historical figures will you register? 16 | 2 17 | 18 | Figure: 1 19 | - Name: Marco Polo 20 | - Date of birth: 08/01/1324 21 | - Occupation: Merchant 22 | 23 | Figure: 2 24 | - Name: Shakespeare 25 | - Date of birth: 26/03/1564 26 | - Occupation: Playwright 27 | 28 | These are the values you stored: 29 | Marco Polo 08/01/1324 Merchant 30 | Shakespeare 26/03/1564 Playwright 31 | 32 | Who do you want information on? Marco Polo 33 | 34 | Name: Marco Polo 35 | Date of birth: 08/01/1324 36 | Occupation: Merchant 37 | ``` 38 | 39 | Launch the workbook 40 | ------------------- 41 | 42 | From `Java Bootcamp Resources` -> `Module 2` -> `6. Array`, open Javapedia. 43 | 44 | Task 1 45 | ------ 46 | 47 | Ask the user: `How many historical figures will you register?`. Store the value in an `int` variable. 48 | 49 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-54-e9ae073a912a9701d32c659ea53486a9.png) 50 | 51 | Task 2 52 | ------ 53 | 54 | Make a 2D array named: `database`. The data we're going to submit will take the form of a table. 55 | 56 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-54-ad3aa6397744c87bb76d543fbf9a1104.png) 57 | 58 | So, our array must have as many rows as there are historical figures. Each row also needs 3 values. 59 | 60 | **Don't populate the array yet. Leave that for task 3.** 61 | 62 | Task 3 63 | ------ 64 | 65 | Create a `for` loop that runs through every row in the database. The user needs to submit three values per row. 66 | 67 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-54-2015f053b4b9ee8c91930c4deb86f753.gif) 68 | 69 | As the user submits each value, you need to store it in the appropriate row. While doing this task, be careful of the `nextLine` pitfall (see cheat sheet). 70 | 71 | Task 4 72 | ------ 73 | 74 | Print the contents of `database`. Create a function called `print2DArray`. 75 | 76 | ```java 77 | /** 78 | * Function name: print2DArray 79 | * @param array (String[][]) 80 | * 81 | * Inside the function 82 | * 1. print the database 83 | * - a tab of space precedes each row. 84 | * - each value in database has one space from the other value. 85 | */ 86 | ``` 87 | 88 | **Inside the function:** 89 | 90 | - add a tab of space before each row. 91 | 92 | - add a space after printing each value. 93 | 94 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-54-0da8ab5c130c03c9250f27e0a2d76c2b.png) 95 | 96 | Once you finish writing the function, use it to print `database`: 97 | 98 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_01-30-54-1f219ef5e50529abd2b28d31d6ac1e45.gif) 99 | 100 | Task 5 101 | ------ 102 | 103 | The final task is to let the user search the database by name. If the search matches a name in `database`, print that row's information. 104 | 105 | **Final Output:** 106 | 107 | ``` 108 | **********Javapedia********** 109 | How many historical figures will you register? 2 110 | 111 | 112 | Figure: 1 113 | - Name: Marco Polo 114 | - Date of birth: 08/01/1324 115 | - Occupation: Merchant 116 | 117 | 118 | Figure: 2 119 | - Name: Shakespeare 120 | - Date of birth: 26/03/1564 121 | - Occupation: Playwright 122 | 123 | 124 | These are the values you stored: 125 | Marco Polo 08/01/1324 Merchant 126 | Shakespeare 26/03/1564 Playwright 127 | 128 | 129 | Who do you want information on? Marco Polo 130 | 131 | 132 | Name: Marco Polo 133 | Date of birth: 08/01/1324 134 | Occupation: Merchant 135 | 136 | ``` 137 | 138 | When printing the information, add a tab of space before each line. 139 | 140 | Good luck! 141 | ---------- 142 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /12. Arrays (Challenge)/Part 1.md: -------------------------------------------------------------------------------- 1 | # Tic Tac Toe 2 | 3 | This is the most exciting challenge in this course. You're going to build a **two-player** game of Tic Tac Toe! 4 | 5 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-58-46-bb2dbff93f21284fde67676dcf5c93c0.gif) 6 | 7 | Open the challenge 8 | ------------------ 9 | 10 | From `Java Bootcamp Resources` -> `Module 1` -> `6. Array`, open `Challenge 6`. 11 | 12 | ## Task 1: Create an array 13 | ----------------------- 14 | 15 | The Tic Tac Toe board is a grid with three rows. 16 | 17 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-58-46-aa7145766e6cfc3a66a0b66f2032a0a5.png) 18 | 19 | Each row has three '`_`' characters. Your first task is to store these characters in an array. 20 | 21 | ## Task 2: Print the array 22 | ----------------------- 23 | 24 | Write a function that prints the board. Call the function after creating the board. 25 | 26 | ```java 27 | //Task 1: Create a board: char[][] board 28 | //Task 2: Call the function: printBoard(board); 29 | ``` 30 | ```java 31 | /** 32 | * Function name - printBoard() 33 | * @param board (char[][]) 34 | * 35 | * Inside the function: 36 | * 1. print a new line. 37 | * 2. print the board. 38 | * - separate each row by two lines. 39 | * - each row precedes a tab of space 40 | * - each character in the grid has one space from the other character 41 | */ 42 | ``` 43 | Inside the function: 44 | 45 | - Print a new line. 46 | 47 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-58-46-a81079dc30fc80e74cf8d139a1138a2b.png) 48 | 49 | 50 | - add a tab of space before each row. 51 | - add a space after printing each character. 52 | 53 | ![](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-58-46-5b2f2b7d34e3f42925ce06dab7802d17.png) 54 | 55 | ## Good Luck! 56 | ---------- 57 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/01. Workbook 7.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.1 2 | 3 | Inside the `Java Bootcamp Resources`, launch **`Workbook 7.1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-01-21-9e7fcb2ba30b7a59b345c0be012f9c3e.png) 6 | 7 | ## **Task 1** 8 | 9 | Create a new file named `Person.java`. Inside the file, create the `Person` `class`. 10 | 11 | ```java 12 | public class Person { 13 | 14 | 15 | } 16 | ``` 17 | 18 | The `Person` `class` will define the following fields: 19 | 20 | ``` 21 | String name; 22 | String nationality; 23 | String dateOfBirth; 24 | String[] passport; 25 | int seatNumber; 26 | ``` 27 | 28 | The `Person` class is a **blueprint** from which you can create `Person` objects. 29 | 30 | ## **Task 2** 31 | 32 | Create one object of the `Person` class. Then print every field in the object. 33 | 34 | ```java 35 | >>: null 36 | >>: null 37 | >>: null 38 | >>: null 39 | >>: 0 40 | ``` 41 | 42 | ## **Task 3** 43 | 44 | Update each field in the object before printing them. 45 | 46 | ```java 47 | person.name = // a String 48 | person.nationality // a String 49 | person.dateOfBirth = // a String 50 | person.passport = // Array that stores: {person.name, person.nationality, person.dateOfBirth} 51 | person.seatNumber = // an Integer 52 | ``` 53 | ### Hint for `passport` 54 | 55 | You can only use shorthand initialization in the same line as the variable declaration. 56 | 57 | ![0.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-01-22-7d211561a50bf79e0c177506ebeed9e1.png) 58 | 59 | That's because the compiler is able to infer the array type. 60 | 61 | ![12.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-01-22-4c3f564e60844944ad38777326f2cbcc.png) 62 | 63 | You cannot use shorthand initialization on another line because the compiler can't infer the type. 64 | 65 | ![13.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-01-22-96595f56389121635e8581c8eab6ab50.png) 66 | 67 | You need to explicitly define a `new` array that can store `String` elements. 68 | 69 | ![14.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-04_00-01-22-af36155a690a0a69839588c06a078433.png) 70 | 71 | ## Task 4 72 | 73 | Print the fields of your updated object. 74 | 75 | ```java 76 | System.out.println(person.name); 77 | System.out.println(person.nationality); 78 | System.out.println(person.dateOfBirth); 79 | System.out.println(Arrays.toString(person.passport)); 80 | System.out.println(person.seatNumber); 81 | ``` 82 | ### Result 83 | ``` 84 | >>: Rayan Slim 85 | >>: Canadian 86 | >>: 01/01/1111 87 | >>: [Rayan Slim, Canadian, 01/01/1111] 88 | >>: 5 89 | ``` 90 | 91 | ---------- 92 | 93 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/02. Workbook 7.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-56-56-2dc0762899de2e23f63328e6138258f3.png) 6 | 7 | 8 | ## **Task 1** 9 | 10 | Create a `Person` constructor that receives four parameters. For now, ignore `passport`. 11 | 12 | ```java 13 | public Person(String name, String nationality, String dateOfBirth, int seatNumber) { 14 | // set fields equal to parameters here. 15 | } 16 | ``` 17 | 18 | 19 | ## **Task 2** 20 | 21 | Remove the field updates from Part 1. 22 | 23 | ![10.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-56-56-e4369dbc65b1f4e4390b32ff2584a914.png) 24 | 25 | While a `new` object is being created, use the constructor to update its fields. 26 | ## Task 3 27 | 28 | Print every field as part of one `String`. 29 | ```java 30 | System.out.println("Name: " + + "\n" + "Nationality: " + + "\n" + "Date of Birth: " + + "\n" + "Seat Number: " + + "\n"); 31 | ``` 32 | 33 | ``` 34 | >>: Name: Rayan Slim 35 | >>: Nationality: Canadian 36 | >>: Date of Birth: 01/01/1111 37 | >>: Seat Number: 5 38 | ``` 39 | 40 | ---------- 41 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/03. Workbook 7.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.3`**. 4 | 5 | ![3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-16-34-5e82cbcd6bf4a8f4a2aed2fb32cbc114.png) 6 | 7 | ## Task 1 8 | 9 | Make each field `private`. 10 | 11 | ```java 12 | private String name; 13 | private String nationality; 14 | private String dateOfBirth; 15 | private String[] passport; 16 | private int seatNumber; 17 | ``` 18 | 19 | ## **Task 2** 20 | 21 | Add getters for `name`, `nationality`, `dateOfBirth`, and `seatNumber`. 22 | 23 | ## **Task 3** 24 | 25 | Call the getters from your `println` function and re-run the code. 26 | 27 | ``` 28 | >>: Name: Rayan Slim 29 | >>: Nationality: Canadian 30 | >>: Date of Birth: 01/01/1111 31 | >>: Seat Number: 5 32 | ``` 33 | 34 | ## **Task 4** 35 | 36 | Add setters for `name`, `nationality`, `dateOfBirth`, and `seatNumber`. 37 | 38 | ## **Task 5** 39 | 40 | The person's current seat number is already taken. Update their seat number to 10 before printing the fields. 41 | 42 | ``` 43 | >>: Name: Rayan Slim 44 | >>: Nationality: Canadian 45 | >>: Date of Birth: 01/01/1111 46 | >>: Seat Number: 10 47 | ``` 48 | 49 | ---------- 50 | 51 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/04. Workbook 7.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.4 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.4`**. 4 | 5 | ![4.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-14-22-3a456f601df2c13c2a1ecfb9bb337eba.png) 6 | 7 | ## **Task 1** 8 | 9 | Inside the `Person` class, add a copy constructor. 10 | 11 | ## **Task 2** 12 | Your code contains a `Person` object. 13 | 14 | ```java 15 | Person person = new Person("Rayan Slim", "Canadian", "01/01/1111", 5); 16 | ``` 17 | That person's twin is also flying with Java airlines. Use this code to test your copy constructor. 18 | 19 | ```java 20 | Person twin = new Person(person); // creates a copy of the first object. 21 | twin.setName("Jad Slim"); // updates name field of the second object. 22 | twin.setSeatNumber(3); // updates the seat number of the second object. 23 | ``` 24 | Print the other person's fields as well. 25 | 26 | ```java 27 | System.out.println("Name: " + twin.getName() + "\n" + "Nationality: " + twin.getNationality() + "\n" + "Date of Birth: " + twin.getDateOfBirth() + "\n" + "Seat Number: " + twin.getSeatNumber() + "\n"); 28 | ``` 29 | 30 | ```java 31 | Name: Rayan Slim 32 | Nationality: Canadian 33 | Date of Birth: 01/01/1111 34 | Seat Number: 10 35 | 36 | Name: Jad Slim 37 | Nationality: Canadian 38 | Date of Birth: 01/01/1111 39 | Seat Number: 3 40 | ``` 41 | 42 | ---------- 43 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/05. Workbook 7.5.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.5 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.5`**. 4 | 5 | ![5.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-13-15-c4c231a4a431889ae3951bb867c0e95e.png) 6 | 7 | ## Task 1 8 | 9 | Inside the `Person` class, define a function called `applyPassport`. 10 | 11 | ```java 12 | /** 13 | * Function name: applyPassport 14 | * 15 | * 16 | * 17 | * 18 | */ 19 | ``` 20 | The function returns a `boolean` and does not expect parameters. 21 | 22 | ```java 23 | /** 24 | * Function name: applyPassport 25 | * @return (boolean) <---- 26 | * 27 | * 28 | * 29 | */ 30 | ``` 31 | 32 | This code randomly returns 0 or 1. 33 | 34 | ```java 35 | int number = (int) (Math.random() * 2); //random int that can be 0 or 1. 36 | ``` 37 | 38 | Use this code to return `true` if the number equals `1`, and `false` otherwise. 39 | 40 | ```java 41 | /** 42 | * Function name: applyPassport 43 | * @return (boolean) 44 | * 45 | * Inside the function: 46 | * 1. Returns a random boolean of true or false. 47 | */ 48 | ``` 49 | 50 | Do not use `if` - `else` to accomplish this task. 51 | 52 | ![24.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-13-15-0c3e1da58e454404ab23583c459059bc.png) 53 | 54 | ## **Task 2** 55 | 56 | Inside the `Person` class, define a function called `chooseSeat`. 57 | 58 | ```java 59 | /** 60 | * Function name: chooseSeat 61 | * 62 | * 63 | * 64 | */ 65 | ``` 66 | This code returns a random number between 1 and 11. 67 | ```java 68 | (int) (Math.random() * 11 + 1); 69 | ``` 70 | `chooseSeat` must use this code to update `this.seat` with a random seat. 71 | 72 | ```java 73 | /** 74 | * Function name: chooseSeat 75 | * 76 | * Inside the function: 77 | * 1. Sets this.seat to a random number between 1 -- 11. 78 | */ 79 | ``` 80 | 81 | ## Task 3 82 | 83 | Your starter project should contain one object. 84 | 85 | ```java 86 | Person person = new Person("Rayan Slim", "Canadian", "01/01/1111", 5); 87 | ``` 88 | 89 | Call `applyPassport` from your object. If the function returns `true`: 90 | 91 | ```java 92 | System.out.println("Congratulations " + person.getName() + ". Your passport was approved!"); 93 | ``` 94 | 95 | Otherwise: 96 | 97 | ```java 98 | System.out.println("We are sorry " + person.getName() + ". We cannot process your application."); 99 | ``` 100 | 101 | **Example Output 1:** 102 | 103 | ``` 104 | >>: Name: Rayan Slim 105 | >>: Nationality: Canadian 106 | >>: Date of Birth: 01/01/1111 107 | >>: Seat Number: 10 108 | 109 | >>: Congratulations Rayan Slim. Your passport was approved! 110 | ``` 111 | 112 | **Example Output 2:** 113 | 114 | ``` 115 | >>: Name: Rayan Slim 116 | >>: Nationality: Canadian 117 | >>: Date of Birth: 01/01/1111 118 | >>: Seat Number: 10 119 | 120 | >>: We are sorry Rayan Slim. We cannot process your application. 121 | ``` 122 | 123 | Run your code multiple times. Each run should output a random result. 124 | 125 | ## Task 4. 126 | 127 | Before printing the result, your object must invoke `chooseSeat` to "choose another seat". 128 | 129 | **Example Output 1** 130 | 131 | ``` 132 | >>: Name: Rayan Slim 133 | >>: Nationality: Canadian 134 | >>: Date of Birth: 01/01/1111 135 | >>: Seat Number: 10 136 | 137 | >>: Congratulations Rayan Slim. Your passport was approved! 138 | ``` 139 | 140 | **Example Output 2** 141 | 142 | ``` 143 | >>: Name: Rayan Slim 144 | >>: Nationality: Canadian 145 | >>: Date of Birth: 01/01/1111 146 | >>: Seat Number: 10 147 | 148 | >>: We are sorry Rayan Slim. We cannot process your application. 149 | ``` 150 | 151 | **Example Output 3** 152 | 153 | ``` 154 | >>: Name: Rayan Slim 155 | >>: Nationality: Canadian 156 | >>: Date of Birth: 01/01/1111 157 | >>: Seat Number: 4 158 | 159 | >>: Congratulations Rayan Slim. Your passport was approved! 160 | ``` 161 | 162 | Keep testing the function. It should keep updating the person's `seatNumber` in the range `1 - 11`. 163 | 164 | ---------- 165 | 166 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 167 | -------------------------------------------------------------------------------- /14. The World of Objects/06. Workbook 7.6.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.6 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.6`**. 4 | 5 | ![6.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-11-00-972b0131a67089748c1c59c02b22f23f.png) 6 | 7 | ## **Task 1** 8 | 9 | Your constructor will **not** receive a passport parameter. 10 | ```java 11 | public Person(String name, String nationality, String dateOfBirth, int seatNumber) { 12 | // ... 13 | } 14 | ``` 15 | But it must set `passport` equal to an array that stores 3 elements. 16 | 17 | ```java 18 | public Person(String name, String nationality, String dateOfBirth, int seatNumber) { 19 | // ... 20 | this.passport = new String[3]; 21 | } 22 | ``` 23 | We do this because we cannot update their passport until they apply for it. 24 | 25 | ## **Task 2** 26 | 27 | Add the getter `getPassport()`. Make sure it returns a **copy** of the array. 28 | 29 | ## Task 3 30 | Add this `println()` function at the end of your `main()` method. Replace the placeholders where appropriate. 31 | ```java 32 | System.out.println("Name: " + + "\n" + 33 | "Nationality: " + + "\n" + 34 | "Date of Birth: " + + "\n" + 35 | "Seat Number: " + + "\n" + "Passport: " + 36 | + "\n"); 37 | ``` 38 | 39 | 40 | **Your output should appear as follows:** 41 | 42 | ``` 43 | >>: Name: Rayan Slim 44 | >>: Nationality: Canadian 45 | >>: Date of Birth: 01/01/1111 46 | >>: Seat Number: 5 47 | >>: Passport: [null, null, null] 48 | ``` 49 | 50 | **Task 4** 51 | ------------------- 52 | Your code contains a setter `setPassport`. Notice that it doesn't have a parameter. 53 | ```java 54 | public void setPassport() { 55 | 56 | } 57 | ``` 58 | Inside `setPassport`, set `passport` equal to `{name, nationality, dateOfBirth}`. 59 | 60 | **Task 5** 61 | ---------------------------- 62 | 63 | Call the setter if the person gets approved for a passport. 64 | 65 | **Test Case:** Passport Approved. 66 | 67 | ``` 68 | >>: Name: Rayan Slim 69 | >>: Nationality: Canadian 70 | >>: Date of Birth: 01/01/1111 71 | >>: Seat Number: 5 72 | >>: Passport: [Rayan Slim, Canadian, 01/01/1111] 73 | ``` 74 | 75 | **Test Case:** Passport Denied. 76 | 77 | ``` 78 | >>: Name: Rayan Slim 79 | >>: Nationality: Canadian 80 | >>: Date of Birth: 01/01/1111 81 | >>: Seat Number: 5 82 | >>: Passport: [null, null, null] 83 | ``` 84 | 85 | Keep running your code and make sure you get alternating outputs. 86 | 87 | ---------- 88 | 89 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/07. Workbook 7.7.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.7 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.7`**. 4 | 5 | ![7.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-09-39-6ce31ded5974cabef2a5b2ef803d432b.png) 6 | 7 | ## Task 1 8 | 9 | Add a `toString` method to the `Person` class. Return a `String` that follows this template: 10 | 11 | ```java 12 | "Name: " + + "\n" + "Nationality: " + 13 | + "\n" + "Date of Birth: " + 14 | + "\n" + "Seat Number: " + 15 | + "\n" + "Passport: " + 16 | + "\n"; 17 | ``` 18 | 19 | 20 | ## Task 2 21 | 22 | Print your object. Java should internally call `toString` and print its return value. 23 | 24 | ``` 25 | >>: Name: Rayan Slim 26 | >>: Nationality: Canadian 27 | >>: Date of Birth: 01/01/1111 28 | >>: Seat Number: 5 29 | >>: Passport: [Rayan Slim, Canadian, 01/01/1111] 30 | ``` 31 | 32 | ---------- 33 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /14. The World of Objects/08. Workbook 7.8.md: -------------------------------------------------------------------------------- 1 | # Workbook 7.8 2 | 3 | From the `Java Bootcamp Resources`, launch **`Workbook 7.8`**. 4 | 5 | ![8.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-05-44-970de47502a554e7ed6f4b9b6e4a9642.png) 6 | 7 | ## Task 1 8 | Inside the `Airline` `class`, add a constructor that does not receive any parameters. 9 | 10 | ## Task 2 11 | 12 | Inside the constructor, set `people` equal to a `new` array that can store 11 `Person` objects. 13 | 14 | ## Task 3 15 | 16 | Add a getter named `getPerson` that receives an `int index` and returns a `Person` object based on the index. 17 | 18 | ## Task 4 19 | 20 | Add a setter named `setPerson` that receives **one** parameter `Person person`. 21 | 22 | ```java 23 | /** Setter name: setPerson 24 | * 25 | * @param person 26 | * 27 | * 28 | * 29 | * 30 | * 31 | */ 32 | ``` 33 | Consider that the `people` array contains 11 elements, such that the index ranges from **0** to **10**. 34 | 35 | ``` 36 | 0 1 2 3 ... 10 37 | Person[] people = {Person, Person, Person, Person, ..., Person}; 38 | ``` 39 | 40 | The parameter `Person person` has a `seatNumber` that ranges from **1** to **11**. 41 | 42 | ![15.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_23-05-44-5a9a9f5785c048507c0693dc12717aab.png) 43 | 44 | Use the `seatNumber` to index the array **without stepping out of bounds**. Set that element equal to the `Person` object. 45 | 46 | ```java 47 | /** Setter name: setPerson 48 | * @param person (Person) 49 | * 50 | * Inside the setter: 51 | * 52 | * 1. Index the array, and set that element equal to the Person object. 53 | */ 54 | ``` 55 | 56 | ## Task 5 57 | 58 | The starter code contains an array of `Person` objects. It also contains an object of the `Airline` class. 59 | 60 | ```java 61 | public static void main(String[] args) { 62 | Person[] people = new Person[] { 63 | new Person("Cleopatra", "Egypt", "69 BC", 1), 64 | new Person("Alexander the Great", "Macedon", "356 BC", 2), 65 | new Person("Julius Caesar", "Rome", "100 BC", 3), 66 | new Person("Hannibal", "Carthage", "247 BC", 4), 67 | new Person("Confucius", "China", "551 BC", 5), 68 | new Person("Pericles", "Greece", "429 BC", 6), 69 | new Person("Spartacus", "Thrace", "111 BC", 7), 70 | new Person("Marcus Aurelius", "Rome", "121 AD", 8), 71 | new Person("Leonidas", "Greece", "540 BC", 9), 72 | new Person("Sun Tzu", "China", "544 BC", 10), 73 | new Person("Hammurabi", "Babylon", "1750 BC", 11), 74 | }; 75 | Airline airline = new Airline(); 76 | 77 | } 78 | ``` 79 | Use your `for` loop to populate the `airline` with objects from the array in `main()`. 80 | 81 | ## Task 6 82 | 83 | Print the objects at indices: **1**, **5**, **10**. 84 | 85 | ```java 86 | System.out.println(airline.getPerson(1)); 87 | System.out.println(airline.getPerson(5)); 88 | System.out.println(airline.getPerson(10)); 89 | ``` 90 | 91 | **Output:** 92 | ``` 93 | >>: Name: Alexander the Great 94 | >>: Nationality: Macedon 95 | >>: Date of Birth: 356 BC 96 | >>: Seat Number: 2 97 | >>: Passport: [null, null, null] 98 | 99 | >>: Name: Pericles 100 | >>: Nationality: Greece 101 | >>: Date of Birth: 429 BC 102 | >>: Seat Number: 6 103 | >>: Passport: [null, null, null] 104 | 105 | >>: Name: Hammurabi 106 | >>: Nationality: Babylon 107 | >>: Date of Birth: 1750 BC 108 | >>: Seat Number: 11 109 | >>: Passport: [null, null, null] 110 | ``` 111 | 112 | ---------- 113 | 114 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /15. The World of Objects (Challenge)/Part 1.md: -------------------------------------------------------------------------------- 1 | # Part 1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-52-09-961726c7868b629db69c576a50858720.png) 6 | 7 | ## Task 1 8 | 9 | Add the following fields to the `Movie` class. 10 | ```java 11 | private String name; 12 | private String format; 13 | private double rating; 14 | ``` 15 | Then create a constructor, copy constructor, getters, and setters. 16 | 17 | ## Task 2 18 | 19 | Create a `toString` method that returns the following `String`. 20 | ```java 21 | return this.rating + "\t" + this.format + "\t\t" + this.name + ""; 22 | ``` 23 | 24 | ## Task 3 25 | 26 | Populate the array inside `main()` with the following `Movie` objects. 27 | ```java 28 | new Movie("The Shawshank Redemption", "BlueRay", 9.2), 29 | new Movie("The Godfather", "BlueRay", 9.1), 30 | new Movie("The Godfather: Part II", "DVD", 9.0), 31 | new Movie("The Dark Knight", "BlueRay", 9.0), 32 | new Movie("Schindler's List", "DVD", 8.9), 33 | new Movie("The Lord of the Rings: The Return of the King", "BlueRay", 8.9), 34 | new Movie("Pulp Fiction", "DVD", 8.8), 35 | new Movie("The Lord of the Rings: The Fellowship of the Ring", "DVD", 8.8) 36 | ``` 37 | 38 | ## Final Output 39 | 40 | ```java 41 | ********************************MOVIE STORE******************************* 42 | 9.2 BlueRay The Shawshank Redemption 43 | 9.1 BlueRay The Godfather 44 | 9.0 DVD The Godfather: Part II 45 | 9.0 BlueRay The Dark Knight 46 | 8.9 DVD Schindlers List 47 | 8.9 BlueRay The Lord of the Rings: The Return of the King 48 | 8.8 DVD Pulp Fiction 49 | 8.8 DVD The Lord of the Rings: The Fellowship of the Ring 50 | ``` 51 | 52 | ---------- 53 | 54 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /15. The World of Objects (Challenge)/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-52-50-3093777a85285ad2e3829ff71f115e0d.png) 6 | 7 | ## Task 1 8 | 9 | The `Store` constructor must grant `this.movies` the capacity to store 10 elements. 10 | 11 | ```java 12 | public Store() { 13 | // TODO 14 | } 15 | ``` 16 | ## Task 2 17 | 18 | The getter must return a **`new`** copy of the `Movie` object being requested. 19 | 20 | ```java 21 | public Movie getMovie(int index) { 22 | // TODO 23 | return null; 24 | } 25 | ``` 26 | 27 | ## Task 3 28 | 29 | The setter must update the array with a **`new`** copy of the `Movie` object. 30 | 31 | ```java 32 | public void setMovie(int index, Movie movie) { 33 | // TODO 34 | } 35 | ``` 36 | 37 | ## Task 4 38 | 39 | Inside `main()`, populate the store (defined on top) with movies before printing it. 40 | 41 | ```java 42 | ********************************MOVIE STORE******************************* 43 | 9.2 BlueRay The Shawshank Redemption 44 | 9.1 BlueRay The Godfather 45 | 9.0 DVD The Godfather: Part II 46 | 9.0 BlueRay The Dark Knight 47 | 8.9 DVD Schindlers List 48 | 8.9 BlueRay The Lord of the Rings: The Return of the King 49 | 8.8 DVD Pulp Fiction 50 | 8.8 DVD The Lord of the Rings: The Fellowship of the Ring 51 | ``` 52 | 53 | ---------- 54 | 55 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /16. Extra Practice/Part 1.md: -------------------------------------------------------------------------------- 1 | # The World of Objects - Extra Practice 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-45-35-fc3a726b8efda1383a99329b586504f7.png) 6 | 7 | ## **Task 1** 8 | 9 | Create a new file named `Contact.java`. Inside the file, create the `Contact` class. 10 | 11 | 12 | ```java 13 | public class Contact { 14 | 15 | } 16 | ``` 17 | 18 | The Contact class will define the following fields: 19 | 20 | ```java 21 | private String name; 22 | private String phoneNumber; 23 | private String birthDate; 24 | private int age; 25 | ``` 26 | 27 | The Contact class serves as a blueprint for creating Contact objects. 28 | 29 | 30 | ## Task 2 31 | 32 | Create a constructor that initializes the fields of a newly created object. 33 | 34 | 35 | ## Task 3 36 | 37 | Create a constructor that initializes a new object using an existing object's fields. 38 | 39 | ## Task 4 40 | 41 | Test your constructor by creating four instances (objects) of the Contact class. 42 | 43 | ```java 44 | public static void main(String[] args) { 45 | Contact contact1 = new Contact("Alice", "123-456-7890", "1990-01-01", 33); 46 | Contact contact2 = new Contact("Bob", "234-567-8901", "1992-02-02", 31); 47 | Contact contact3 = new Contact("Charlie", "345-678-9012", "1994-03-03", 29); 48 | Contact contact4 = new Contact("David", "456-789-0123", "1996-04-04", 27); 49 | } 50 | ``` 51 | ## Task 5 52 | 53 | Use breakpoints to visualize the initialization of each field as objects are created. 54 | 55 | ## Task 6 56 | 57 | Test the copy constructor by creating two objects with fields copied from two existing objects. 58 | 59 | 60 | ```java 61 | public static void main(String[] args) { 62 | // Assuming the Contact objects from Task 4 are available 63 | Contact copyContact1 = new Contact(contact1); 64 | Contact copyContact2 = new Contact(contact3); 65 | } 66 | ``` 67 | 68 | ## Task 7 69 | 70 | Use breakpoints to inspect field initialization in the new objects created using the copy constructor. 71 | 72 | ---------- 73 | 74 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /16. Extra Practice/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-48-26-034dd97d10e3824d3feabf695ddd5a4b.png) 6 | 7 | ## **Task 1** 8 | 9 | Modify the `Contact` class by removing the `age` parameter from the constructor. 10 | 11 | ```java 12 | public Contact(String name, String phoneNumber, String birthDate) { 13 | this.name = name; 14 | this.phoneNumber = phoneNumber; 15 | this.birthDate = birthDate; 16 | // Remove the age update 17 | } 18 | ``` 19 | Age will be derived from the `birthDate` that is passed in. 20 | 21 | 22 | ## Task 2 23 | 24 | This task provides an excellent opportunity to practice navigating the web to search documentation and find resources. 25 | 26 | ### Part 1 27 | 28 | Create a `toAge` method that converts the `birthDate` string to an age. 29 | 30 | 31 | ```java 32 | public int toAge(String birthDate) { 33 | // Your implementation here 34 | } 35 | ``` 36 | 37 | ### Part 2 38 | `LocalDate` makes it really easy to work with dates. 39 | 40 | Convert the `String` into a LocalDate using the [**`LocalDate.parse` method**](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#parse-java.lang.CharSequence-java.time.format.DateTimeFormatter-). Ensure that the `LocalDate` follows the pattern `yyyy-MM-dd`. 41 | 42 | ```java 43 | public int toAge(String birthDate) { 44 | // 1. Convert birthDate String to LocalDate 45 | } 46 | ``` 47 | 48 | ### Part 3 49 | 50 | Define a `LocalDate` object representing the current date using the [**`LocalDate.now` method**](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#now--). 51 | 52 | ```java 53 | public int toAge(String birthDate) { 54 | // 1. Convert birthDate String to LocalDate 55 | // 2. Get the current date 56 | } 57 | ``` 58 | 59 | ### Part 4 60 | 61 | Define a `Period` object representing the period between two dates using the [**`Period.between` method**](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Period.html#between(java.time.LocalDate,java.time.LocalDate)) 62 | 63 | ```java 64 | public int toAge(String birthDate) { 65 | // 1. Convert birthDate String to LocalDate 66 | // 2. Get the current date 67 | // 3. Calculate the period between both dates 68 | } 69 | ``` 70 | 71 | ### Part 5 72 | Extract the number of years from the `Period` object and return it using the [**`Period.getYears` method**](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Period.html#getYears()) 73 | 74 | ```java 75 | public int toAge(String birthDate) { 76 | // 1. Convert birthDate String to LocalDate 77 | // 2. Get the current date 78 | // 3. Calculate the period between both dates 79 | // 4. Return the number of years 80 | } 81 | ``` 82 | 83 | ## Task 3 84 | 85 | Modify the constructor to update the `age` field by calling `toAge` and passing in the `birthDate`. 86 | 87 | 88 | ## Task 4 89 | 90 | Use breakpoints to visualize the runtime of the `age` field being updated automatically from the `birthDate`. 91 | 92 | 93 | ## Task 5 94 | 95 | Update the `birthDate` of one of the previously created objects: 96 | 97 | ```java 98 | public static void main(String[] args) { 99 | // contacts from before 100 | contact1.setBirthDate("1989-01-01"); 101 | } 102 | 103 | ``` 104 | ## Task 6 105 | 106 | The `age` should be automatically updated once the `birthDate` is updated, so make `setAge` `private`, as it should not be accessible outside of this class. 107 | 108 | We only need to call `setAge` from `setBirthDate` so that `age` is automatically updated when the `birthDate` is updated. 109 | 110 | 111 | ## Task 7 112 | 113 | Use breakpoints to visualize the runtime of the person's `birthDate` and `age` updating simultaneously. 114 | 115 | ---------- 116 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 117 | -------------------------------------------------------------------------------- /16. Extra Practice/Part 3.md: -------------------------------------------------------------------------------- 1 | # Part 3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 3`**. 4 | 5 | ![3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-49-24-14298c0c7ce32397cb3221e821ae2b47.png) 6 | 7 | 8 | ## Task 1 9 | Create a new file named `ContactManager.java`. Inside the file, create the `ContactManager` class. 10 | 11 | ```java 12 | public class ContactManager { 13 | 14 | } 15 | ``` 16 | 17 | The `ContactManager` class will define the following field: 18 | 19 | ```java 20 | private Contact[] contacts; // array of Contact objects 21 | ``` 22 | 23 | ## Task 2 24 | 25 | Create a constructor for the `ContactManager` class that takes an array of `Contact` objects as a parameter. 26 | 27 | ```java 28 | public ContactManager(Contact[] contacts) { 29 | 30 | 31 | } 32 | ``` 33 | 34 | The constructor must initialize the `contacts` field with deep copies of the objects. 35 | 36 | 37 | ```java 38 | public ContactManager(Contact[] contacts) { 39 | // 1. set field equal to a new array with the same length as the parameter 40 | // 2. Set each element in the field equal to a deep copy of an object in the contacts parameter 41 | } 42 | ``` 43 | 44 | ## Task 3 45 | 46 | Create a `getContact` method that takes an index as a parameter and returns a deep copy of the `Contact` object at that index. 47 | 48 | ```java 49 | public Contact getContact(int index) { 50 | // return deep copy of object at that index. 51 | } 52 | ``` 53 | 54 | ## Task 4 55 | 56 | Create a `setContact` method that takes a `Contact` object and an index and sets the `Contact` object at the specified index to a deep copy of the given object. 57 | 58 | 59 | ```java 60 | public void setContact(Contact contact, int index) { 61 | this.contacts[index] = new Contact(contact); 62 | } 63 | ``` 64 | 65 | ## Task 5 66 | 67 | Test the `ContactManager` class by creating a few Contact objects, initializing a `ContactManager` object with those contacts, and then using the `getContact` and `setContact` methods to manipulate the contacts. 68 | 69 | ```java 70 | public static void main(String[] args) { 71 | Contact contact1 = new Contact("Alice", "123-456-7890", "1990-01-01"); 72 | Contact contact2 = new Contact("Bob", "234-567-8901", "1992-02-02"); 73 | 74 | Contact[] contacts = {contact1, contact2}; 75 | ContactManager contactManager = new ContactManager(contacts); 76 | 77 | // Test the getContact method 78 | Contact retrievedContact = contactManager.getContact(0); 79 | System.out.println(retrievedContact.getName()); 80 | 81 | // Test the setContact method 82 | Contact newContact = new Contact("Charlie", "345-678-9012", "1994-03-03"); 83 | contactManager.setContact(newContact, 0); 84 | 85 | // Verify that the contact was updated 86 | retrievedContact = contactManager.getContact(0); 87 | System.out.println(retrievedContact.getName()); 88 | } 89 | ``` 90 | 91 | ## Task 6 92 | Use breakpoints to visualize how the `ContactManager` class is handling the deep copying of `Contact` objects when using the `getContact` and `setContact` methods. 93 | 94 | ---------- 95 | 96 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 97 | 98 | 99 | -------------------------------------------------------------------------------- /17. List/Workbook 8.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 8.1 2 | 3 | From the `Java Bootcamp Resources`, launch **`starter`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-41-33-68fce9306d0a534a7e49be3377f32a44.png) 6 | 7 | ## Task 1 8 | 9 | Initialize the `List` field inside the `Store` constructor, 10 | ```java 11 | private List movies; 12 | 13 | public Store() { 14 | 15 | } 16 | ``` 17 | **`LinkedList`** or **`ArrayList`?** 18 | 19 | This application prioritizes retrieving/updating data and does not add/remove elements from the middle. 20 | 21 | ## Task 2 22 | 23 | Finish writing the code for these methods. 24 | 25 | ```java 26 | public Movie getMovie(int index) { 27 | return null; 28 | } 29 | 30 | public void setMovie(int index, Movie movie) { 31 | // TODO 32 | } 33 | 34 | public void addMovie(Movie movie) { 35 | // TODO 36 | } 37 | ``` 38 | 39 | ## Task 3 40 | 41 | Inside the `main()` method, populate the store using a **`foreach`** loop. 42 | ```java 43 | public static void main(String[] args) { 44 | Movie[] movies = new Movie[] { 45 | new Movie("The Shawshank Redemption", "BlueRay", 9.2), 46 | new Movie("The Godfather", "BlueRay", 9.1), 47 | new Movie("The Godfather: Part II", "DVD", 9.0), 48 | new Movie("12 Angry Men", "DVD", 8.9), 49 | new Movie("The Dark Knight", "BlueRay", 9.0), 50 | new Movie("Schindler's List", "DVD", 8.9), 51 | new Movie("The Lord of the Rings: The Return of the King", "BlueRay", 8.9), 52 | new Movie("Pulp Fiction", "DVD", 8.8), 53 | new Movie("The Good, the Bad and the Ugly", "DVD", 8.8), 54 | new Movie("The Lord of the Rings: The Fellowship of the Ring", "DVD", 8.8) 55 | }; 56 | 57 | // TODO: Populate store using a foreach loop. 58 | 59 | printStore(); 60 | userInput(); 61 | 62 | } 63 | ``` 64 | 65 | Don't use a regular loop because we don't need the index. 66 | 67 | 68 | ## Final Output 69 | 70 | ``` 71 | ********************************MOVIE STORE******************************* 72 | 9.2 BlueRay The Shawshank Redemption 73 | 9.1 BlueRay The Godfather 74 | 9.0 DVD The Godfather: Part II 75 | 8.9 DVD 12 Angry Men 76 | 9.0 BlueRay The Dark Knight 77 | 8.9 DVD Schindler's List 78 | 8.9 BlueRay The Lord of the Rings: The Return of the King 79 | 8.8 DVD Pulp Fiction 80 | 8.8 DVD The Good, the Bad and the Ugly 81 | 8.8 DVD The Lord of the Rings: The Fellowship of the Ring 82 | 83 | 84 | Please choose an integer between 0 - 9: 5 85 | Set a new rating for Schindler's List: 9.8 86 | 87 | ********************************MOVIE STORE******************************* 88 | 9.2 BlueRay The Shawshank Redemption 89 | 9.1 BlueRay The Godfather 90 | 9.0 DVD The Godfather: Part II 91 | 8.9 DVD 12 Angry Men 92 | 9.0 BlueRay The Dark Knight 93 | 9.8 DVD Schindler's List 94 | 8.9 BlueRay The Lord of the Rings: The Return of the King 95 | 8.8 DVD Pulp Fiction 96 | 8.8 DVD The Good, the Bad and the Ugly 97 | 8.8 DVD The Lord of the Rings: The Fellowship of the Ring 98 | 99 | To edit another rating, type: 'continue': stop 100 | ``` 101 | ---------- 102 | 103 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /18. Extra Practice/Part 1.md: -------------------------------------------------------------------------------- 1 | # List Collections - Extra Practice 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-37-30-eb761bb9128ea9c6561d841cc7089007.png) 6 | 7 | ## Task 1 8 | 9 | Create a new file named `Book.java`. Inside the file, create the Book class. 10 | 11 | ```java 12 | public class Book { 13 | 14 | } 15 | ``` 16 | The `Book` class will define the following fields: 17 | 18 | ```java 19 | private String title; 20 | private String author; 21 | private double rating; 22 | private double price; 23 | ``` 24 | The Book class serves as a blueprint for creating Book objects. 25 | 26 | ## Task 2 27 | 28 | Create a constructor that initializes the fields of a newly created object. 29 | 30 | 31 | ## Task 3 32 | 33 | Create a constructor that initializes a new object using an existing object's fields. 34 | 35 | ## Task 4 36 | Create getter and setter methods for each field of the Book class. 37 | 38 | ## Task 5 39 | Test your constructor and getter/setter methods by creating instances (objects) of the Book class. 40 | 41 | ```java 42 | public static void main(String[] args) { 43 | Book book1 = new Book("To Kill a Mockingbird", "Harper Lee", 4.27, 15.99); 44 | Book book2 = new Book("1984", "George Orwell", 4.17, 12.99); 45 | Book book3 = new Book("Moby-Dick", "Herman Melville", 3.5, 14.99); 46 | Book book4 = new Book("Pride and Prejudice", "Jane Austen", 4.25, 10.99); 47 | } 48 | ``` 49 | 50 | ## Task 6 51 | Test the copy constructor by creating two objects with fields copied from two existing objects. 52 | 53 | ```java 54 | public static void main(String[] args) { 55 | // Assuming the Book objects from Task 5 are available 56 | Book copyBook1 = new Book(book1); 57 | Book copyBook2 = new Book(book3); 58 | } 59 | ``` 60 | ## Task 7 61 | 62 | Use breakpoints to inspect field initialization in the new objects created using the copy constructor and verify the getter/setter methods are working correctly. 63 | 64 | ----- 65 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /18. Extra Practice/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-38-51-ef9d6a68ba1e8d8f4c623cb6ac49414d.png) 6 | 7 | ## Task 1 8 | Create a new file named `Store.java`. Inside the file, create the Store class. 9 | 10 | ```java 11 | public class Store { 12 | 13 | } 14 | ``` 15 | 16 | The `Store` class will define the following field: 17 | 18 | ```java 19 | private ArrayList books; 20 | ``` 21 | 22 | ## Task 2 23 | Create a constructor for the `Store` class that initializes an empty `ArrayList` of `Book` objects. 24 | 25 | ## Task 3 26 | Create a `getBook` method that takes an index as a parameter and returns a deep copy of the `Book` object at that index. 27 | 28 | 29 | ## Task 4 30 | Create a `setBook` method that takes a `Book` object and an index as parameters and sets the `Book` object at the specified index to a deep copy of the given object. 31 | 32 | ## Task 5 33 | 34 | Create an `addBook` method that takes a `Book` object as a parameter and adds a deep copy of the given object to the books `ArrayList`. 35 | 36 | ## Task 6 37 | Create a `contains` method that takes a `Book` object as a parameter and returns `true` if the books ArrayList contains the given object, `false` otherwise. 38 | 39 | ```java 40 | public boolean contains(Book book) { 41 | return this.books.contains(book); 42 | } 43 | ``` 44 | **Hint**: do not forget about the `equals` method. 45 | ## Task 7 46 | Create a `sellBook` method that takes a `String` title as a parameter and removes the `Book` object with the specified title from the `books` `ArrayList`. 47 | 48 | ## Task 8 49 | Test the `Store` class by creating a few `Book` objects, initializing a `Store` object with those books, and then using the `getBook`, `setBook`, `addBook`, `contains`, and `sellBook` methods to manipulate the books. Use breakpoints to visualize the runtime. 50 | 51 | ```java 52 | public static void main(String[] args) { 53 | Book book1 = new Book("To Kill a Mockingbird", "Harper Lee", 4.27, 15.99); 54 | Book book2 = new Book("1984", "George Orwell", 4.17, 12.99); 55 | 56 | Store store = new Store(); 57 | store.addBook(book1); 58 | store.addBook(book2); 59 | 60 | // Test the getBook method 61 | Book retrievedBook = store.getBook(0); 62 | System.out.println(retrievedBook.getTitle()); 63 | 64 | // Test the setBook method 65 | Book newBook = new Book("Moby-Dick", "Herman Melville", 3.5, 14.99); 66 | store.setBook(0, newBook); 67 | 68 | // Verify that the book was updated 69 | retrievedBook = store.getBook(0); 70 | System.out.println(retrievedBook.getTitle()); 71 | 72 | // Test the contains method 73 | System.out.println(store.contains(book2)); // should be true before selling the book 74 | 75 | // Test the sellBook method 76 | store.sellBook("1984"); 77 | System.out.println(store.contains(book2)); // should be false now 78 | 79 | } 80 | ``` 81 | 82 | ## Task 9 83 | 84 | If everything works, feel free to create a fun app from your objects by introducing user interactivity! 85 | 86 | ----- 87 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /19. Exception Handling/Part 1.md: -------------------------------------------------------------------------------- 1 | # Part 1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-30-35-a8806f44f26eae971c22881783ef06a0.png) 6 | 7 | 8 | ## Task 1 9 | 10 | Validate the name that gets passed into `setName`. 11 | ```java 12 | public void setName(String name) { 13 | // TODO 14 | } 15 | ``` 16 | Throw an `IllegalArgumentException` if the name is `null` or `blank`. 17 | 18 | 19 | ## Task 2 20 | 21 | Validate the format that gets passed into `setFormat`. 22 | ```java 23 | public void setFormat(String format) { 24 | // TODO 25 | } 26 | ``` 27 | Throw an `IllegalArgumentException` if the format is `null` or `blank`. 28 | 29 | ## Task 3 30 | 31 | Validate the rating that gets passed into `setRating`. 32 | ```java 33 | public void setRating(double rating) { 34 | // TODO 35 | } 36 | ``` 37 | Throw an `IllegalArgumentException` if the rating is less than 0 or greater than 10. 38 | 39 | ---------- 40 | 41 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /19. Exception Handling/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-30-00-e670f6ff3d72c0a18b468f1ae9baa972.png) 6 | 7 | 8 | ## Task 0 9 | 10 | The `loadMovies` method is already implemented. 11 | ```java 12 | public static void loadMovies(String fileName) throws FileNotFoundException { 13 | // reads input from file... 14 | } 15 | ``` 16 | 17 | If you want to visualize its runtime, feel free to watch the video solution. 18 | 19 | ## Task 1 20 | 21 | This method should return `true` if the choice is less than 0 or greater than 9. 22 | ```java 23 | public static boolean incorrectChoice(int choice) { 24 | // TODO 25 | } 26 | ``` 27 | 28 | ## Task 2 29 | 30 | This method should return `true` if the rating is less than 0 or greater than 10. 31 | ```java 32 | public static boolean incorrectRating(double rating) { 33 | // TODO 34 | } 35 | ``` 36 | 37 | ## Task 3 38 | 39 | The method `promptForChoice` will return the integer they choose. 40 | ```java 41 | public static int promptForChoice(Scanner scanner) { 42 | while (true) { 43 | System.out.print("\nPlease choose an integer between 0 - 9: "); 44 | 45 | int choice = scanner.nextInt(); 46 | return choice; <-------------- 47 | } 48 | } 49 | ``` 50 | 51 | **Scenario One**: `continue` the while loop if the user doesn't enter an integer. 52 | 53 | ```java 54 | public static int promptForChoice(Scanner scanner) { 55 | while (true) { 56 | System.out.print("\nPlease choose an integer between 0 - 9: "); 57 | 58 | // 1. Anticipate the user not entering an integer. <-------------- 59 | 60 | int choice = scanner.nextInt(); 61 | 62 | return choice; 63 | } 64 | } 65 | ``` 66 | 67 | **Scenario Two**: `continue` the while loop if the user enters an incorrect choice. 68 | 69 | ```java 70 | public static int promptForChoice(Scanner scanner) { 71 | while (true) { 72 | System.out.print("\nPlease choose an integer between 0 - 9: "); 73 | 74 | // 1. Anticipate the user not entering an integer. 75 | 76 | int choice = scanner.nextInt(); 77 | 78 | // 2. Anticipate the choice being incorrect. <-------------- 79 | return choice; 80 | } 81 | } 82 | ``` 83 | 84 | ## Task 4 85 | 86 | The method `promptForRating` will return the rating they choose. 87 | ```java 88 | public static double promptForRating(Scanner scanner, String name) { 89 | while (true) { 90 | System.out.print("\nSet a new rating for " + name + ": "); 91 | 92 | 93 | double rating = scanner.nextDouble(); 94 | return rating; <--------- 95 | } 96 | } 97 | ``` 98 | 99 | **Scenario One**: `continue` the while loop if the user doesn't enter a `double`. 100 | 101 | ```java 102 | public static double promptForRating(Scanner scanner, String name) { 103 | while (true) { 104 | System.out.print("\nSet a new rating for " + name + ": "); 105 | 106 | // 1. Anticipate the user not entering a double. <------------- 107 | 108 | double rating = scanner.nextDouble(); 109 | 110 | return rating; 111 | } 112 | } 113 | ``` 114 | 115 | **Scenario Two**: `continue` the while loop if the user enters an incorrect rating. 116 | 117 | ```java 118 | public static double promptForRating(Scanner scanner, String name) { 119 | while (true) { 120 | System.out.print("\nSet a new rating for " + name + ": "); 121 | 122 | // 1. Anticipate the user not entering a double. 123 | 124 | double rating = scanner.nextDouble(); 125 | 126 | // 2. Anticipate the rating being incorrect. <---------- 127 | 128 | return rating; 129 | } 130 | } 131 | ``` 132 | 133 | ---------- 134 | 135 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /20. Extra Practice/Part 1.md: -------------------------------------------------------------------------------- 1 | # Part 1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-25-30-8bd3a3b04c6af2166e20a2cd9f058a0f.png) 6 | 7 | 8 | ## Task 1 9 | 10 | Create a new file named `Magazine.java`. Inside the file, create the Magazine class. 11 | 12 | ```java 13 | public class Magazine { 14 | 15 | } 16 | 17 | ``` 18 | 19 | The Magazine class will define the following fields: 20 | 21 | ```java 22 | private String title; 23 | private String publisher; 24 | private int issueNumber; 25 | private int publicationYear; 26 | ``` 27 | 28 | ## Task 2 29 | Create getter and setter methods for each field of the `Magazine` class. Ensure that the setter methods perform the following argument validations and throw an `IllegalArgumentException` with an appropriate error message if the input is invalid: 30 | 31 | - `setTitle` method: 32 | 33 | - Check if the input `title` is `null` or `blank`. 34 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Title cannot be null or blank."` 35 | 36 | - `setPublisher` method: 37 | - Check if the input `publisher` is null or `blank`. 38 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Publisher cannot be null or blank."` 39 | 40 | - `setIssueNumber` method: 41 | 42 | - Check if the input `issueNumber` is less than or equal to `0`. 43 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Issue number must be greater than 0."` 44 | 45 | - `setPublicationYear` method: 46 | 47 | - Check if the input `publicationYear` is less than or equal to 0. 48 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Publication year must be greater than 0."` 49 | 50 | 51 | After implementing the setter methods with the appropriate validations, create the corresponding getter methods for each field. 52 | 53 | 54 | 55 | ## Task 3 56 | Create a constructor that initializes the fields of a newly created object by calling the setter methods. 57 | 58 | ```java 59 | public Magazine(String title, String publisher, int issueNumber, int publicationYear) { 60 | setTitle(title); 61 | setPublisher(publisher); 62 | setIssueNumber(issueNumber); 63 | setPublicationYear(publicationYear); 64 | } 65 | ``` 66 | Using the setter methods in the constructor ensures that the argument validation is performed in a single place, keeping the code DRY (Don't Repeat Yourself). 67 | 68 | ## Task 4 69 | Test your constructor and getter/setter methods by creating instances (objects) of the Magazine class. Uncomment each test one by one to ensure that the methods throw an `IllegalArgumentException` when the input is invalid. Remember to re-comment the test before moving on to the next one. 70 | 71 | 72 | 73 | ```java 74 | public static void main(String[] args) { 75 | Magazine magazine1 = new Magazine("Magazine 1", "Publisher 1", 1, 2020); 76 | System.out.println(magazine1.getTitle()); 77 | 78 | // Uncomment the following line to test invalid input for setTitle method 79 | // magazine1.setTitle(""); 80 | 81 | // Uncomment the following line to test invalid input for setPublisher method 82 | // magazine1.setPublisher(""); 83 | 84 | // Uncomment the following line to test invalid input for setIssueNumber method 85 | // magazine1.setIssueNumber(-1); 86 | 87 | // Uncomment the following line to test invalid input for setPublicationYear method 88 | // magazine1.setPublicationYear(0); 89 | 90 | // Uncomment the following line to test invalid input for the constructor 91 | // Magazine magazine2 = new Magazine("", "Publisher 2", 2, 2020); 92 | } 93 | ``` 94 | 95 | When testing each method, the program will throw an `IllegalArgumentException` if the input is invalid. This helps us to identify mistakes in our application and fix the issues, preventing the creation of objects with an invalid state that could lead to unexpected behavior or errors during program execution. 96 | 97 | ----- 98 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /20. Extra Practice/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-26-24-e01edb91ebfa86f2335f6ed4398b259d.png) 6 | 7 | ## Task 1 8 | Create a new file named `MagazineLibrary`.java. Inside the file, create the MagazineLibrary class. 9 | 10 | ```java 11 | public class MagazineLibrary { 12 | 13 | } 14 | ``` 15 | 16 | The MagazineLibrary class will define the following field: 17 | 18 | ```java 19 | private ArrayList magazines; 20 | ``` 21 | 22 | ## Task 2 23 | Create a constructor for the `MagazineLibrary` class that initializes the `magazines` field to an empty ArrayList. 24 | 25 | ## Task 3 26 | Create a `getMagazine` method that takes an index as a parameter and returns a deep copy of the Magazine object at that index. 27 | 28 | 29 | **Hint**: You must return to the `Magazine` class and give it a copy constructor. 30 | 31 | ## Task 4 32 | Create a `setMagazine` method that takes a Magazine object and an index as parameters and sets the Magazine object at the specified index to a deep copy of the given object. 33 | 34 | ## Task 5 35 | Create an `addMagazine` method that takes a Magazine object as a parameter and adds a deep copy of the object to the magazines `ArrayList`. 36 | 37 | ## Task 6 38 | Test the `MagazineLibrary` class by creating a few `Magazine` objects, initializing a `MagazineLibrary` object with those magazines, and then using the `getMagazine`, `setMagazine`, and `addMagazine` methods to manipulate the magazines. 39 | 40 | ```java 41 | public static void main(String[] args) { 42 | Magazine magazine1 = new Magazine("Magazine 1", "Publisher 1", 1, 2020); 43 | Magazine magazine2 = new Magazine("Magazine 2", "Publisher 2", 2, 2021); 44 | 45 | MagazineLibrary library = new MagazineLibrary(); 46 | 47 | // Test the addMagazine method 48 | library.addMagazine(magazine1); 49 | library.addMagazine(magazine2); 50 | 51 | // Test the getMagazine method 52 | Magazine retrievedMagazine = library.getMagazine(0); 53 | System.out.println(retrievedMagazine.getTitle()); 54 | 55 | // Test the setMagazine method 56 | Magazine newMagazine = new Magazine("Magazine 3", "Publisher 3", 3, 2022); 57 | library.setMagazine(newMagazine, 0); 58 | 59 | // Verify that the magazine was updated 60 | retrievedMagazine = library.getMagazine(0); 61 | System.out.println(retrievedMagazine.getTitle()); 62 | } 63 | ``` 64 | 65 | ## Task 7 66 | Use breakpoints to inspect how the `MagazineLibrary` class manages the `ArrayList` of `Magazine` objects with deep copying when using the `getMagazine`, `setMagazine`, and `addMagazine` methods. 67 | 68 | ----- 69 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /20. Extra Practice/Part 3.md: -------------------------------------------------------------------------------- 1 | # Part 3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 3`**. 4 | 5 | ![3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-27-09-669aa067281080e0190d14baa5a97fa4.png) 6 | 7 | ## Task 1 8 | Inside the Main class, create a method called `isNullOrBlank` that takes a `String` input and returns `true` if the input is `null` or `blank`. 9 | 10 | 11 | ```java 12 | public static boolean isNullOrBlank(String input) { 13 | // TODO 14 | } 15 | ``` 16 | 17 | ## Task 2 18 | 19 | Create a method called `incorrectIssueNumber` that takes an `int` input and returns `true` if the input is less than or equal to 0. 20 | 21 | ```java 22 | public static boolean incorrectIssueNumber(int issueNumber) { 23 | // TODO 24 | } 25 | ``` 26 | 27 | ## Task 3 28 | Create a method called `incorrectPublicationYear` that takes an `int` input and returns `true` if the input is less than or equal to `0`. 29 | 30 | ```java 31 | public static boolean incorrectPublicationYear(int publicationYear) { 32 | // TODO 33 | } 34 | ``` 35 | 36 | ## Task 4 37 | Create a method called `promptForTitle` that takes a `Scanner` input and returns a valid `title` entered by the user. 38 | 39 | ```java 40 | public static String promptForTitle(Scanner scanner) { 41 | while (true) { 42 | System.out.print("\nPlease enter a valid title: "); 43 | String title = scanner.nextLine(); 44 | // TODO 45 | } 46 | } 47 | ``` 48 | ## Task 5 49 | Create a method called `promptForPublisher` that takes a `Scanner` input and returns a valid publisher entered by the user. 50 | 51 | ```java 52 | public static String promptForPublisher(Scanner scanner) { 53 | while (true) { 54 | System.out.print("\nPlease enter a valid publisher: "); 55 | String publisher = scanner.nextLine(); 56 | // TODO 57 | } 58 | } 59 | ``` 60 | 61 | ## Task 6 62 | 63 | Create a method called `promptForIssueNumber` that takes a `Scanner` input and returns a valid issue number entered by the user. 64 | 65 | ```java 66 | public static int promptForIssueNumber(Scanner scanner) { 67 | while (true) { 68 | System.out.print("\nPlease enter a valid issue number (greater than 0): "); 69 | // First check if the next input is not an integer 70 | // scanner.next(); 71 | // continue; 72 | 73 | int issueNumber = scanner.nextInt(); 74 | // TODO 75 | } 76 | } 77 | ``` 78 | ## Task 7 79 | Create a method called `promptForPublicationYear` that takes a Scanner input and returns a valid publication year entered by the user. 80 | 81 | ```java 82 | public static int promptForPublicationYear(Scanner scanner) { 83 | while (true) { 84 | System.out.print("\nPlease enter a valid publication year (greater than 0): "); 85 | // First check if the next input is not an integer 86 | // scanner.next(); 87 | // continue; 88 | int publicationYear = scanner.nextInt(); 89 | // TODO 90 | } 91 | } 92 | ``` 93 | ## Task 8 94 | Test the interactive methods in the main method. 95 | 96 | ```java 97 | public static void main(String[] args) { 98 | Scanner scanner = new Scanner(System.in); 99 | 100 | String title = promptForTitle(scanner); 101 | String publisher = promptForPublisher(scanner); 102 | int issueNumber = promptForIssueNumber(scanner); 103 | int publicationYear = promptForPublicationYear(scanner); 104 | 105 | Magazine newMagazine = new Magazine(title, publisher, issueNumber, publicationYear); 106 | 107 | MagazineLibrary library = new MagazineLibrary(); 108 | library.addMagazine(newMagazine); 109 | 110 | System.out.println("Magazine added to the library: " + newMagazine.getTitle()); 111 | } 112 | ``` 113 | ----- 114 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /21. Map/Workbook 9.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 9.1 2 | 3 | From the `Java Bootcamp Resources`, launch **`starter`**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-19-48-09ed73eca9158c02aafe7abbf57da1ac.png) 6 | 7 | ## Task 1 8 | 9 | The `Team` class contains two fields. 10 | 11 | ```java 12 | private String name; 13 | private Map players; 14 | ``` 15 | Fill in the logic for the constructor. 16 | ```java 17 | public Team(String name) { 18 | // set the name. 19 | // set players equal to a new HashMap. 20 | } 21 | ``` 22 | ## Task 2 23 | 24 | Fill in the logic for the getters and setters 25 | 26 | ```java 27 | public String getName() { 28 | // return the name 29 | } 30 | 31 | public void setName(String name) { 32 | // set the name 33 | 34 | } 35 | 36 | public String getPlayer(String position) { 37 | // return a player from the HashMap. 38 | } 39 | 40 | public void setPlayer(String position, String player) { 41 | // Add a entry into the HashMap 42 | } 43 | 44 | ``` 45 | 46 | ## Task 3 47 | 48 | The `Game` class contains two fields. 49 | 50 | ```java 51 | private String arena; 52 | private LocalDate date; 53 | ``` 54 | The `LocalDate` class provides the **[`now()`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html#now())** method. 55 | 56 | ```java 57 | public class LocalDate { 58 | 59 | public static LocalDate now() { 60 | return now(Clock.systemDefaultZone()); 61 | } 62 | 63 | } 64 | ``` 65 | The `static` keyword allows you to call the method from the class itself. 66 | 67 | ```java 68 | LocalDate.now() 69 | ``` 70 | 71 | Use this information to fill the logic in the `Game` constructor. 72 | 73 | ```java 74 | public Game(String arena) { 75 | // set the arena. 76 | // set the date equal to the current date. 77 | } 78 | ``` 79 | 80 | ## Task 4 81 | 82 | The `LocalDate` class provides the following methods. 83 | 84 | ```java 85 | public class LocalDate { 86 | 87 | public int getYear() { 88 | return year; 89 | } 90 | 91 | public int getMonthValue() { 92 | return month; 93 | } 94 | 95 | public int getDayOfMonth() { 96 | return day; 97 | } 98 | 99 | } 100 | ``` 101 | You can invoke these methods from any object of the `LocalDate` class. 102 | 103 | ```java 104 | date.getDayOfMonth(); 105 | date.getMonthValue(); 106 | date.getYear(); 107 | ``` 108 | 109 | Use this information to fill the first line inside `begin()`. 110 | ```java 111 | "\n - This matchup takes place at the " + this.arena + " arena on " + "" + "."; 112 | ``` 113 | Execute your code. 114 | ``` 115 | >>: - This matchup takes place at the Etihad Stadium arena on 04/01/2023. 116 | >>: ... 117 | >>: ... 118 | 119 | ``` 120 | 121 | ## Task 5 122 | 123 | Task 4 familiarized you with `LocalDate` getters. In this case, favor calling `format`. 124 | 125 | ```java 126 | String formattedDate = this.date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); 127 | ``` 128 | Execute your code. 129 | ``` 130 | >>: - This matchup takes place at the Etihad Stadium arena on 04/01/2023. 131 | >>: ... 132 | >>: ... 133 | 134 | ``` 135 | 136 | 137 | ## Task 6 138 | 139 | Consider that `main()` already populates two teams with players. 140 | ```java 141 | Team bulls = new Team("Chicago Bulls"); 142 | bulls.setPlayer("SHOOTING_GUARD", "Michael Jordan"); 143 | bulls.setPlayer("SMALL_FORWARD", "Scottie Pippen"); 144 | bulls.setPlayer("POWER_FORWARD", "Dennis Rodman"); 145 | bulls.setPlayer("CENTER", "Bill Wennington"); 146 | bulls.setPlayer("POINT_GUARD", "Randy Brown"); 147 | 148 | Team pistons = new Team("Detroit Pistons"); 149 | pistons.setPlayer("SHOOTING_GUARD", "Joe Dumars"); 150 | pistons.setPlayer("SMALL_FORWARD", "Grant Hill"); 151 | pistons.setPlayer("POWER_FORWARD", "Otis Thorpe"); 152 | pistons.setPlayer("CENTER", "William Bedford"); 153 | pistons.setPlayer("POINT_GUARD", "Isiah Thomas"); 154 | ``` 155 | 156 | Use this information to fill the remaining lines inside `begin()`. 157 | 158 | ---------- 159 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /22. Map (Extra Practice)/Part 1.md: -------------------------------------------------------------------------------- 1 | # Part 1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-16-01-a051cdcf04351ef759b53aa73c92548f.png) 6 | 7 | 8 | ## Task 1 9 | Create a new file named `City.java`. Inside the file, create the City class. 10 | 11 | ```java 12 | public class City { 13 | 14 | } 15 | ``` 16 | The City class will define the following fields: 17 | 18 | ```java 19 | private String name; 20 | private String country; 21 | private long population; 22 | ``` 23 | 24 | ## Task 2 25 | Create getter and setter methods for each field of the `City` class. Ensure that the setter methods perform the following argument validations and throw an `IllegalArgumentException` with an appropriate error message if the input is invalid: 26 | 27 | - `setName` method: 28 | 29 | - Check if the input `name` is `null` or `blank`. 30 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Name cannot be null or blank."` 31 | 32 | - `setCountry` method: 33 | 34 | - Check if the input `country` is `null` or `blank`. 35 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Country cannot be null or blank."` 36 | 37 | - `setPopulation` method: 38 | 39 | - Check if the input `population` is less than or equal to 0. 40 | - If the validation fails, throw an `IllegalArgumentException` with the message `"Population must be greater than 0."` 41 | 42 | After implementing the setter methods with the appropriate validations, create the corresponding getter methods for each field. 43 | 44 | ## Task 3 45 | Create a constructor that initializes the fields of a newly created object by calling the setter methods. 46 | 47 | ``` java 48 | public City(String name, String country, long population) { 49 | setName(name); 50 | setCountry(country); 51 | setPopulation(population); 52 | } 53 | ``` 54 | 55 | Using the setter methods in the constructor ensures that the argument validation is performed in a single place, keeping the code DRY (Don't Repeat Yourself). 56 | 57 | ## Task 4 58 | Test your constructor and getter/setter methods by creating instances (objects) of the City class. Uncomment each test one by one to ensure that the methods throw an `IllegalArgumentException` when the input is invalid. Remember to re-comment the test before moving on to the next one. 59 | 60 | ```java 61 | public static void main(String[] args) { 62 | City city1 = new City("New York", "USA", 8500000); 63 | System.out.println(city1.getName()); 64 | 65 | // Uncomment the following line to test invalid input for setName method 66 | // city1.setName(""); 67 | 68 | // Uncomment the following line to test invalid input for setCountry method 69 | // city1.setCountry(""); 70 | 71 | // Uncomment the following line to test invalid input for setPopulation method 72 | // city1.setPopulation(-1); 73 | 74 | // Uncomment the following line to test invalid input for the constructor 75 | // City city2 = new City("", "USA", 8500000); 76 | } 77 | ``` 78 | When testing each method, the program will throw an `IllegalArgumentException` if the input is invalid. This helps us to identify mistakes in our application and fix the issues, preventing the creation of objects with an invalid state that could lead to unexpected behavior or errors during program execution. 79 | 80 | ----- 81 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 82 | 83 | 84 | -------------------------------------------------------------------------------- /22. Map (Extra Practice)/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-16-59-2eac9b21641a48fbb0913b71d992d415.png) 6 | 7 | 8 | ## Task 1 9 | Create a new file named `CityPopulationTracker.java`. Inside the file, create the `CityPopulationTracker` class. 10 | 11 | ```java 12 | public class CityPopulationTracker { 13 | 14 | } 15 | ``` 16 | 17 | The `CityPopulationTracker` class will define the following field: 18 | 19 | ```java 20 | private HashMap cityPopulations; 21 | ``` 22 | 23 | ## Task 2 24 | Create a constructor for the `CityPopulationTracker` class that initializes the `cityPopulations` field to an empty `HashMap`. 25 | 26 | ## Task 3 27 | Create a `getCity` method that takes a `city` name as a parameter and returns a deep copy of the `City` object associated with that city. 28 | 29 | ## Task 4 30 | Create a `setCity` method that takes a `City` object as a parameter, and sets a deep copy of the `City` object in the `HashMap` with the corresponding city name as the key. 31 | 32 | ## Task 5 33 | Create an `addCity` method that takes a `City` object as a parameter, and adds a deep copy of the `City` object to the `HashMap` with the corresponding city name as the key. 34 | 35 | ## Task 6 36 | Test the `CityPopulationTracker` class by adding a few `City` objects, and then use the `getCity`, `setCity`, and `addCity` methods to manipulate the city data. 37 | 38 | ```java 39 | public static void main(String[] args) { 40 | CityPopulationTracker tracker = new CityPopulationTracker(); 41 | 42 | // Test the addCity method 43 | tracker.addCity(new City("New York", "USA", 8550405)); 44 | tracker.addCity(new City("Los Angeles", "USA", 3971883)); 45 | 46 | // Test the getCity method 47 | City nyCity = tracker.getCity("New York"); 48 | System.out.println("Population of New York: " + nyCity.getPopulation()); 49 | 50 | // Test the setCity method 51 | City updatedNyCity = new City("New York", "USA", 8600000); 52 | tracker.setCity(updatedNyCity); 53 | 54 | // Verify that the city data was updated 55 | nyCity = tracker.getCity("New York"); 56 | System.out.println("Updated population of New York: " + nyCity.getPopulation()); 57 | } 58 | ``` 59 | 60 | ## Task 7 61 | Use breakpoints to inspect how the `CityPopulationTracker` class manages the `HashMap` of city names and `City` objects with deep copying when using the `getCity`, `setCity`, and `addCity` methods. 62 | 63 | 64 | ----- 65 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 66 | 67 | -------------------------------------------------------------------------------- /22. Map (Extra Practice)/Part 3.md: -------------------------------------------------------------------------------- 1 | # Part 3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 3`**. 4 | 5 | ![3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_22-17-46-0a6f5c23863c8bfc358a210a31caa3e1.png) 6 | 7 | 8 | ## Task 1 9 | 10 | Inside the `Main` class, create a method called `isNullOrBlank` that takes a `String` input and returns `true` if the input is `null` or `blank`. 11 | 12 | ```java 13 | public static boolean isNullOrBlank(String input) { 14 | // TODO 15 | } 16 | ``` 17 | ## Task 2 18 | 19 | Create a method called `incorrectPopulation` that takes an `int` input and `returns` `true` if the input is less than or equal to 0. 20 | 21 | ```java 22 | public static boolean incorrectPopulation(int population) { 23 | // TODO 24 | } 25 | ``` 26 | ## Task 3 27 | Create a method called `promptForCityName` that takes a `Scanner` input and returns a valid city name entered by the user. 28 | 29 | ```java 30 | public static String promptForCityName(Scanner scanner) { 31 | while (true) { 32 | System.out.print("\nPlease enter a valid city name: "); 33 | String cityName = scanner.nextLine(); 34 | // TODO 35 | } 36 | } 37 | ``` 38 | 39 | ## Task 4 40 | Create a method called `promptForCountry` that takes a `Scanner` input and returns a valid country entered by the user. 41 | 42 | ```java 43 | public static String promptForCountry(Scanner scanner) { 44 | while (true) { 45 | System.out.print("\nPlease enter a valid country: "); 46 | String country = scanner.nextLine(); 47 | // TODO 48 | } 49 | } 50 | ``` 51 | ## Task 5 52 | Create a method called `promptForPopulation` that takes a `Scanner` input and returns a valid population entered by the user. 53 | 54 | ```java 55 | public static int promptForPopulation(Scanner scanner) { 56 | while (true) { 57 | System.out.print("\nPlease enter a valid population (greater than 0): "); 58 | // First check if the next input is not an integer 59 | // scanner.next(); 60 | // continue; 61 | 62 | int population = scanner.nextInt(); 63 | // TODO 64 | } 65 | } 66 | ``` 67 | 68 | ## Task 6 69 | Test the interactive methods in the main method. 70 | 71 | ```java 72 | public static void main(String[] args) { 73 | Scanner scanner = new Scanner(System.in); 74 | 75 | String cityName = promptForCityName(scanner); 76 | 77 | String country = promptForCountry(scanner); 78 | 79 | int population = promptForPopulation(scanner); 80 | 81 | City newCity = new City(cityName, country, population); 82 | 83 | CityPopulationTracker tracker = new CityPopulationTracker(); 84 | tracker.addCity(newCity); 85 | 86 | System.out.println("City added to the tracker: " + newCity.getName()); 87 | } 88 | ``` 89 | ----- 90 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /23. Static and Final/Workbook 10.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 10.1 2 | 3 | From the `Java Bootcamp Resources`, launch **`starter`**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_19-04-44-1f96398f7b9b87fb54ee97e1bce870e8.png) 6 | 7 | ## Task 1 8 | 9 | The `details()` method contains many loose integers. 10 | ```java 11 | "\nCourt length (feet): " + 94 + 12 | "\nRim height (feet): " + 10 + 13 | "\nDistance from three-point arc: " + 23 + 14 | "\nPoints awarded beyond the three-point arc: " + 3 + 15 | "\nPoints awarded inside the three-point arc: " + 2 + 16 | "\nPoints awarded from a free throw: " + 1 + 17 | "\nLength of each quarter (minutes): " + 12 + 18 | "\nSeconds to attempt shot after gaining possession: " + 24; 19 | ``` 20 | Create eight constants inside `Regulation` and use them inside the `Game` class. 21 | ```java 22 | public class Regulation { 23 | 24 | COURT_LENGTH 25 | RIM_HEIGHT 26 | THREE_POINT_DISTANCE 27 | BEYOND_THREE_POINT_ARC 28 | INSIDE_THREE_POINT_ARC 29 | FREE_THROW 30 | QUARTER_LENGTH 31 | POSSESSION_TIME 32 | 33 | } 34 | ``` 35 | 36 | ---------- 37 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /24. Enums/Workbook 11.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 11.1 2 | 3 | From the `Java Bootcamp Resources`, launch **`starter`**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_19-03-59-e94444e749037b861a66df16f719c842.png) 6 | 7 | 8 | ## Task 1 9 | 10 | Use the position values inside `main()` to fill up the `Position` `enum` with constants. 11 | 12 | ```java 13 | public enum Position { 14 | 15 | 16 | } 17 | ``` 18 | 19 | ## Task 2 20 | 21 | Update the `players` field inside `Team` to store `Position` keys rather than `String`. 22 | 23 | ```java 24 | private Map players; 25 | ``` 26 | 27 | ## Task 3 28 | 29 | Update `getPlayer()` to receive a `Position` enum constant rather than a `String`. 30 | ```java 31 | public String getPlayer(String position) <---- 32 | ``` 33 | 34 | ## Task 4 35 | Update `setPlayer()` to receive a `Position` enum constant rather than a `String`. 36 | ```java 37 | public void setPlayer(String position, String player) 38 | ``` 39 | The enum type is guaranteed to be one of five constants. So remove the safety mechanisms. 40 | 41 | ```java 42 | if (!position.equals("SHOOTING_GUARD") || !position.equals("SMALL_FORWARD") || !position.equals("POWER_FORWARD") ... 43 | throw new IllegalArgumentException("INVALID POSITION"); 44 | ``` 45 | Although you should still ensure that a `null` doesn't get passed in. 46 | ```java 47 | if (position == null) 48 | throw new IllegalArgumentException("Position cannot be null"); 49 | ``` 50 | 51 | ## Task 5 52 | enum constants are implicitly `static` and `final`. Import every constant into `Main` and fill in the `main()` method. 53 | 54 | ## Task 6 55 | 56 | Import every constant into `Game` and fill in the `begin()` method. 57 | 58 | ---------- 59 | 60 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /25. Extra Practice/Part 2.md: -------------------------------------------------------------------------------- 1 | # Part 2 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 2`**. 4 | 5 | ![2.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_19-00-46-88db7a5f544b37750e972d6ac4784359.png) 6 | 7 | ## Task 1 8 | 9 | The `CarDealership` `class` will define an `ArrayList` of `Car` objects. 10 | 11 | ## Task 2 12 | Create a constructor for the `CarDealership` class that initializes the `cars` field to an empty `ArrayList`. 13 | 14 | ## Task 3 15 | Create a `getCar` method that takes an index as a parameter and returns a deep copy of the `Car` object at that index. 16 | 17 | **Hint**: You must return to the Car class and give it a copy constructor. 18 | 19 | ## Task 4 20 | Create a `setCar` method that takes a `Car` object and an index as parameters and sets the `Car `object at the specified index to a deep copy of the given object. 21 | 22 | ## Task 5 23 | Create an `addCar` method that takes a `Car` object as a parameter and adds a deep copy of the object to the `cars` `ArrayList`. 24 | 25 | ## Task 6 26 | Test the `CarDealership` class by creating a few Car objects, initializing a `CarDealership` object with those cars, and then using the `getCar`, `setCar`, and `addCar` methods to manipulate the cars. 27 | 28 | ```java 29 | public static void main(String[] args) { 30 | Car car1 = new Car("Toyota", "Camry", BodyType.SEDAN, 2020, 30000); 31 | Car car2 = new Car("Honda", "Civic", BodyType.SEDAN, 2021, 25000); 32 | 33 | CarDealership dealership = new CarDealership(); 34 | 35 | // Test the addCar method 36 | dealership.addCar(car1); 37 | dealership.addCar(car2); 38 | 39 | // Test the getCar method 40 | Car retrievedCar = dealership.getCar(0); 41 | System.out.println(retrievedCar.getMake() + " " + retrievedCar.getModel()); 42 | 43 | // Test the setCar method 44 | Car newCar = new Car("Ford", "Mustang", BodyType.COUPE, 2022, 45000); 45 | dealership.setCar(newCar, 0); 46 | 47 | // Verify that the car was updated 48 | retrievedCar = dealership.getCar(0); 49 | System.out.println(retrievedCar.getMake() + " " + retrievedCar.getModel()); 50 | } 51 | ``` 52 | 53 | ## Task 7 54 | Use breakpoints to inspect how the CarDealership class manages the `ArrayList` of `Car` objects with deep copying when using the `getCar`, `setCar`, and `addCar` methods. 55 | 56 | ---------- 57 | 58 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 59 | 60 | -------------------------------------------------------------------------------- /25. Extra Practice/Part 3.md: -------------------------------------------------------------------------------- 1 | # Part 3 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 3`**. 4 | 5 | ![3.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_19-02-20-f7560a5523051b60198013057566dc19.png) 6 | # 7 | 8 | ## Task 1 9 | Inside the Main class, create a method called `isNullOrBlank` that takes a `String` input and returns `true` if the input is `null` or `blank`. 10 | 11 | ```java 12 | public static boolean isNullOrBlank(String input) { 13 | // TODO 14 | } 15 | ``` 16 | 17 | ## Task 2 18 | Create a method called `invalidYear` that takes an `int` input and returns `true` if the input is less than your minimum production year (see your Car class). 19 | 20 | ```java 21 | public static boolean invalidYear(int year) { 22 | // TODO 23 | } 24 | ``` 25 | 26 | ## Task 3 27 | Create a method called `invalidPrice` that takes a double input and returns true if the input is less than the minimum price or greater than the maximum price (see your Car class). 28 | 29 | ```java 30 | public static boolean invalidPrice(double price) { 31 | // TODO 32 | } 33 | ``` 34 | 35 | ## Task 4 36 | 37 | Create a method called `invalidBodyType` that: 38 | 39 | 1. Takes a `String` input and capitalizes it. 40 | 2. Returns `true` if the input does not match one of the body types in the enum. 41 | 42 | The second part is tricky but here's a hint: you can call `valueOf` from your enum. It returns an enum constant if it recognizes the string, otherwise, it will throw an `IllegalArgumentException`. In which case, catch the exception and return a boolean. 43 | 44 | ```java 45 | public static boolean invalidBodyType(String bodyType) { 46 | // TODO 47 | } 48 | ``` 49 | 50 | ## Task 5 51 | Create a method called `promptForBodyType` that takes a `Scanner` input and returns a valid body type entered by the user. 52 | 53 | ```java 54 | public static BodyType promptForBodyType(Scanner scanner) { 55 | while (true) { 56 | System.out.print("\nPlease enter a valid car body type: "); 57 | String bodyType = scanner.nextLine(); 58 | // TODO 59 | } 60 | } 61 | ``` 62 | 63 | 64 | ## Task 6 65 | 66 | Create a method called `promptForMake` that takes a `Scanner` input and returns a valid `make` entered by the user. 67 | 68 | ```java 69 | public static String promptForMake(Scanner scanner) { 70 | while (true) { 71 | System.out.print("\nPlease enter a valid car make: "); 72 | String make = scanner.nextLine(); 73 | // TODO 74 | } 75 | } 76 | ``` 77 | 78 | ## Task 7 79 | Create a method called `promptForModel` that takes a `Scanner` input and returns a valid `model` entered by the user. 80 | 81 | ```java 82 | public static String promptForModel(Scanner scanner) { 83 | while (true) { 84 | System.out.print("\nPlease enter a valid car model: "); 85 | String model = scanner.nextLine(); 86 | // TODO 87 | } 88 | } 89 | ``` 90 | 91 | ## Task 8 92 | Create a method called `promptForYear` that takes a `Scanner` input and returns a valid production year entered by the user. 93 | 94 | ```java 95 | public static int promptForYear(Scanner scanner) { 96 | while (true) { 97 | System.out.print("\nPlease enter a valid production year: "); 98 | // TODO 99 | } 100 | } 101 | ``` 102 | 103 | ## Task 9 104 | Create a method called `promptForPrice` that takes a `Scanner` input and returns a valid price entered by the user. 105 | 106 | ```java 107 | public static double promptForPrice(Scanner scanner) { 108 | while (true) { 109 | System.out.print("\nPlease enter a valid car price: "); 110 | // TODO 111 | } 112 | } 113 | ``` 114 | 115 | ## Task 10 116 | Test the interactive methods in the main method. 117 | 118 | ```java 119 | public static void main(String[] args) { 120 | Scanner scanner = new Scanner(System.in); 121 | 122 | String make = promptForMake(scanner); 123 | String model = promptForModel(scanner); 124 | BodyType bodyType = promptForBodyType(scanner); 125 | int year = promptForYear(scanner); 126 | double price = promptForPrice(scanner); 127 | 128 | Car newCar = new Car(make, model, bodyType, year, price); 129 | 130 | CarDealership dealership = new CarDealership(); 131 | dealership.addCar(newCar); 132 | 133 | System.out.println("Car added to the dealership: " + newCar.getMake() + " " + newCar.getModel()); 134 | } 135 | 136 | ``` 137 | 138 | ---------- 139 | 140 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 141 | 142 | -------------------------------------------------------------------------------- /26. Inheritance/Workbook 12.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 12.1 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-52-02-77df0685688093d0299dba834b498db3.png) 6 | 7 | ## Task 1 8 | 9 | The `Sphere` and `Cylinder` classes share a common field. 10 | 11 | ![classes.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-52-02-c3d4355537cc9e1c109ba1c1e8ad3410.png) 12 | 13 | Refactor the code so that `Cylinder` and `Sphere` inherit `radius` from `Shape`. 14 | 15 | 16 | ## Task 2 17 | 18 | Refactor the code so that `Cylinder` and `Sphere` inherit getters and setters from `Shape`. 19 | 20 | ---------- 21 | 22 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /26. Inheritance/Workbook 12.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 12.2 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-51-08-03692470427bec5370be2f17c37199e7.png) 6 | 7 | ## Task 1 8 | 9 | Create a constructor inside `Shape` that updates the `radius` of the **current object**. 10 | 11 | 12 | ## Task 2 13 | 14 | Create a constructor inside `Cylinder` that invokes the parent constructor and updates `height`. 15 | 16 | ## Task 3 17 | 18 | Create a constructor inside `Sphere` that invokes the parent constructor. 19 | 20 | ## Task 4 21 | 22 | Add this code to your `main()` method and feel free to visualize the runtime. 23 | 24 | 25 | ```java 26 | Cylinder cylinder = new Cylinder(1.0, 2.0); 27 | Sphere sphere = new Sphere(1.0); 28 | 29 | System.out.println("Sphere - radius: " + sphere.getRadius()); 30 | System.out.println("Cylinder - radius: " + cylinder.getRadius() + " height " + cylinder.getHeight()); 31 | ``` 32 | ---------- 33 | 34 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /26. Inheritance/Workbook 12.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 12.3 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-51-08-03692470427bec5370be2f17c37199e7.png) 6 | 7 | 8 | ## Task 1 9 | 10 | The `Main` class contains two errors. 11 | ``` 12 | Line 18: The method getArea() is undefined for the type Shape 13 | Line 19: The method getVolume() is undefined for the type Shape 14 | ``` 15 | Define two `abstract` methods inside `Shape` to expose these behaviors. 16 | 17 | ## Task 2 18 | 19 | It follows that children of `Shape` must define concrete implementations. 20 | ``` 21 | Cylinder must implement the inherited abstract method Shape.getArea() 22 | Cylinder must implement the inherited abstract method Shape.getVolume() 23 | 24 | Sphere must implement the inherited abstract method Shape.getArea() 25 | Sphere must implement the inherited abstract method Shape.getVolume() 26 | ``` 27 | Use the following table to write equations for area and volume. 28 | 29 | | Shape | Volume Formula | Surface Area Formula | 30 | | ----- | -------------- | -------------------- | 31 | | Cylinder | $V = \pi r^2h$ | $A = 2\pi r^2 + 2\pi rh$| 32 | | Sphere | $V = \left(\frac{4}{3}\right) \pi r^3$ | $A = 4\pi r^2$ | 33 | 34 | ---------- 35 | 36 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.1.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.1 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-42-48-e972bb666fc3b9aa8e54201ab9e23930.png) 6 | 7 | ## Task 1 8 | 9 | Use `forEach` to iterate the `ArrayList` and print the following messages. 10 | ```java 11 | System.out.println("Date: " + p.getDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 12 | System.out.println("Amount: " + p.getAmount()); 13 | System.out.println("---"); 14 | ``` 15 | Consider that `forEach` relies on a `Consumer` to perform its task. 16 | 17 | 18 | | Functional Interface | Example | 19 | | ----- | -------------------- | 20 | | Consumer | `x -> { code } `| 21 | | Predicate | `x -> { return boolean }`| 22 | | Function | `x -> { return value }`| 23 | | BiConsumer | `(x, y) -> { code }`| 24 | | Comparator | `(x, y) -> { return int }`| 25 | | BinaryOperator | `(x, y) -> { return value (same type) }`| 26 | 27 | 28 | ### **Expected Output** 29 | ``` 30 | Date: 01/01/2020 31 | Amount: 100.0 32 | --- 33 | Date: 15/02/2020 34 | Amount: 200.0 35 | --- 36 | Date: 30/03/2020 37 | Amount: 300.0 38 | --- 39 | Date: 01/04/2020 40 | Amount: 50.0 41 | --- 42 | Date: 15/05/2020 43 | Amount: 75.0 44 | --- 45 | Date: 30/06/2020 46 | Amount: 100.0 47 | --- 48 | ``` 49 | 50 | ---------- 51 | 52 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.2.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.2 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-40-04-bf6d6d854132a67b79453db4384f2c8d.png) 6 | 7 | ## Task 1 8 | 9 | Considering that `sort` relies on a `Comparator`, sort the `prices` in **descending** order. 10 | 11 | | Functional Interface | Example | 12 | | ----- | -------------------- | 13 | | Consumer | `x -> { code } `| 14 | | Predicate | `x -> { return boolean }`| 15 | | Function | `x -> { return value }`| 16 | | BiConsumer | `(x, y) -> { code }`| 17 | | Comparator | `(x, y) -> { return int }`| 18 | | BinaryOperator | `(x, y) -> { return value (same type) }`| 19 | 20 | 21 | ## Task 2 22 | Use `forEach` to print each price in the sorted `List`. 23 | 24 | ### **Expected Output** 25 | 26 | ``` 27 | Prices 28 | ------ 29 | 111.99 30 | 88.99 31 | 77.99 32 | 55.99 33 | 55.99 34 | 33.99 35 | 11.49 36 | ``` 37 | 38 | ## Task 3 39 | 40 | Sort the `books` `List` in **ascending** (alphabetical) order. 41 | 42 | 43 | ## Task 4 44 | 45 | Use `forEach` to print each book in the sorted `List`. 46 | 47 | ``` 48 | Library 49 | -------- 50 | Moby-Dick 51 | One Hundred Years of Solitude 52 | Pride and Prejudice 53 | The Alchemist 54 | The Brothers Karamazov 55 | The Catcher in the Rye 56 | The Great Gatsby 57 | The Lord of the Rings 58 | The Picture of Dorian Gray 59 | To Kill a Mockingbird 60 | ``` 61 | ---------- 62 | 63 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.3.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.3 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-32-26-a7b9b7c6eaa6a82be27ef1bf4fd98efd.png) 6 | 7 | ## Task 1 8 | 9 | Use `forEach` to iterate the `HashMap` and print the following message. 10 | ```java 11 | System.out.println(sku + "\t" + item.getPrice() + "\t" + item.getName()) 12 | ``` 13 | Consider that it will rely on a `BiConsumer` to perform its task. 14 | 15 | | Functional Interface | Example | 16 | | ----- | -------------------- | 17 | | Consumer | `x -> { code } `| 18 | | Predicate | `x -> { return boolean }`| 19 | | Function | `x -> { return value }`| 20 | | BiConsumer | `(x, y) -> { code }`| 21 | | Comparator | `(x, y) -> { return int }`| 22 | | BinaryOperator | `(x, y) -> { return value (same type) }`| 23 | 24 | ### Expected Output 25 | ``` 26 | SKU Price Item 27 | DOFO-008 10.0 Super Doo-dad 28 | THNG-003 2.99 Thingamajig 29 | WIDG-005 6.99 Super Widget 30 | GADG-006 8.99 Super Gadget 31 | THNG-007 15.0 Super Thingamajig 32 | WIDG-001 3.99 Widget 33 | GADG-002 5.99 Gadget 34 | DBOO-004 4.99 Doo-dad 35 | ``` 36 | 37 | ---------- 38 | 39 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.4.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.4 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-28-03-4054c6d41ff547f8c8a60b400ccaaf58.png) 6 | 7 | ## Intermediate Operation 8 | 9 | `filter`: include students with a score higher than 80. 10 | 11 | ## Terminal Operation 12 | `forEach`: print this message for each filtered student. 13 | ```java 14 | System.out.println("Congratulations " + student.getName() + " for achieving a score of " + student.getScore()) 15 | ``` 16 | 17 | ### Expected Output 18 | ``` 19 | >>: Congratulations Alice for achieving a score of 85.6 20 | >>: Congratulations Dave for achieving a score of 92.7 21 | >>: Congratulations Gina for achieving a score of 91.4 22 | >>: Congratulations Jasmine for achieving a score of 82.5 23 | ``` 24 | ---------- 25 | 26 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.5.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.5 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-27-23-1f880ed9d029c1fc8e8c035b17ccafb6.png) 6 | 7 | ## Intermediate Operations 8 | 9 | **1. `filter`**: include books of the `Romance` genre. 10 | 11 | **2. `map`**: reduce the price of each element by half. 12 | 13 | **3. `sorted`**: sort each element in ascending order of the year. 14 | 15 | ## Terminal Operation 16 | **`forEach`**: print each element in the stream. 17 | 18 | ``` 19 | These books are on sale 20 | ----------------------- 21 | Romance 1813 $6.71 Pride and Prejudice 22 | Romance 1847 $5.97 Jane Eyre 23 | Romance 1847 $8.08 Wuthering Heights 24 | ``` 25 | ---------- 26 | 27 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.6.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.6 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-25-35-803e9dc16d1839b670faeb221c2b78c0.png) 6 | 7 | ## Task 1 8 | ```java 9 | List names = Arrays.asList("Alice", "Bob", "Charlie", "Dave"); 10 | ``` 11 | 12 | **1. `map`**: transform each name into this greeting `"Hello, " + name + "!"`. 13 | 14 | **2. `forEach`**: print every greeting in the stream. 15 | 16 | ``` 17 | >>: Hello, Alice! 18 | >>: Hello, Bob! 19 | >>: Hello, Charlie! 20 | >>: Hello, Dave! 21 | ``` 22 | 23 | ## Task 2 24 | ```java 25 | List usernames = Arrays.asList("sparklingunicorn", "galactic_goddess", "neon_ninja", "purplepixiedust"); 26 | ``` 27 | 28 | **1. `filter`**: keep the username that matches `neon_ninja`. 29 | 30 | **2. `findFirst().orElse(null)`**: return the first element in the stream. 31 | 32 | 33 | ``` 34 | >>: Found you: neon_ninja 35 | ``` 36 | 37 | ## Task 3 38 | 39 | ```java 40 | List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); 41 | ``` 42 | 43 | **1. `filter`**: keep the numbers that are even. 44 | 45 | **2. `count()`**: count the number of elements in the stream. 46 | 47 | 48 | ``` 49 | >>: There are 3 even numbers in this list 50 | ``` 51 | 52 | -------- 53 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /28. Higher Order Functions/Workbook 13.7.md: -------------------------------------------------------------------------------- 1 | # Workbook 13.7 2 | 3 | From the `Java Bootcamp Resources`, launch **starter**. 4 | 5 | ![starter.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-25-35-803e9dc16d1839b670faeb221c2b78c0.png) 6 | 7 | ## Task 1 8 | 9 | Use `Files.lines(path)` to create a stream of `String` elements from the data source. 10 | 11 | ## Task 2 12 | 13 | Process the stream in a pipeline of operations: 14 | 15 | **1. `filter`**: uses the method [**`startsWith`**](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html#startsWith(java.lang.String)) to remove `Spam` emails. 16 | 17 | **2. `forEach()`**: prints every element in the stream. 18 | 19 | ``` 20 | >>: Primary: Just checking in, how was your weekend? 21 | >>: Social: You have been invited to join the DEF group! 22 | >>: Social: You have been invited to join the ABC network! 23 | >>: Social: You have been added to the ABC group! 24 | >>: Primary: I hope you're doing well! 25 | >>: Primary: Just wanted to catch up, how have you been? 26 | >>: Primary: Hi, how are you doing? 27 | >>: Promotions: 20% off all shoes! 28 | >>: Promotions: Get a free gift with your next purchase! 29 | >>: Social: You have been invited to join the XYZ network! 30 | >>: Social: You have a new follower on XYZ! 31 | >>: Primary: How has your week been going? 32 | >>: Promotions: 50% off your first purchase! 33 | >>: Promotions: 10% off your next vacation! 34 | >>: Promotions: New clearance sale at XYZ store! 35 | ``` 36 | 37 | -------- 38 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /29. Extra Practice/Part 1.md: -------------------------------------------------------------------------------- 1 | # Part 1 2 | 3 | From the `Java Bootcamp Resources`, launch **`Part 1`**. 4 | 5 | ![1.png](https://img-c.udemycdn.com/redactor/raw/article_lecture/2025-01-03_18-23-35-8a2f41145a36160948d612b01d9db3d4.png) 6 | 7 | 8 | ## Task 1 9 | Inside the `MovieStore` class, create the following field: 10 | 11 | ```java 12 | private List movies; 13 | ``` 14 | 15 | ## Task 2 16 | Create a constructor class that initializes the `movies` field to an empty `ArrayList`. 17 | 18 | ```java 19 | public MovieStore() { 20 | this.movies = new ArrayList<>(); 21 | } 22 | ``` 23 | 24 | ## Task 3 25 | Create a method named `addMovie` that takes a Movie object as a parameter and adds it to the `movies` list. 26 | 27 | ## Task 4 28 | Create a method named `filterByGenre` that takes a `String` representing a genre as a parameter and returns a `List` containing only movies of the specified genre. 29 | 30 | - `stream()` - Converts the movies list into a Stream. 31 | - `filter()` - Filters the stream of movies, keeping only movies with the specified genre. Outputs a filtered `Stream`. 32 | - `toList()` - Collects the filtered stream of movies into a List. 33 | 34 | ## Task 5 35 | Create a method named `sortByReleaseYear` that returns a `List` containing all movies sorted by their release year in ascending order. 36 | 37 | - `stream()` - Converts the movies list into a Stream. 38 | - `sorted()` - Sorts the stream of movies by their release year in ascending order. Outputs a sorted `Stream`. 39 | - `toList()` - Collects the sorted stream of movies into a List. 40 | 41 | 42 | ## Task 6 43 | Create a method named `getTopRatedMovies` that takes an `int` value n as a parameter and returns a `List` containing the top n rated movies in descending order. 44 | 45 | - `stream()` - Converts the movies list into a Stream. 46 | - `sorted()` - Sorts the stream of movies by their rating in descending order. Outputs a sorted `Stream`. 47 | - `limit()` - Trims the sorted stream to the top n rated movies. Outputs a limited Stream. 48 | - `toList()` - Collects the limited stream of movies into a List. 49 | 50 | ## Task 7 51 | Test the `MovieStore` class by creating a few `Movie` objects, initializing a `MovieStore` object, and then using the methods from Tasks 4 to 6 to perform various operations on the movies. 52 | 53 | ```java 54 | public static void main(String[] args) { 55 | Movie movie1 = new Movie("Inception", "Christopher Nolan", "Sci-Fi", 2010, 8.8); 56 | Movie movie2 = new Movie("The Dark Knight", "Christopher Nolan", "Action", 2008, 9.0); 57 | Movie movie3 = new Movie("The Matrix", "Lana Wachowski, Lilly Wachowski", "Sci-Fi", 1999, 8.7); 58 | Movie movie4 = new Movie("Pulp Fiction", "Quentin Tarantino", "Crime", 1994, 8.9); 59 | 60 | MovieStore movieStore = new MovieStore(); 61 | movieStore.addMovie(movie1); 62 | movieStore.addMovie(movie2); 63 | movieStore.addMovie(movie3); 64 | movieStore.addMovie(movie4); 65 | 66 | List sciFiMovies = movieStore.filterByGenre("Sci-Fi"); 67 | List sortedMovies = movieStore.sortByReleaseYear(); 68 | List topRatedMovies = movieStore.getTopRatedMovies(3); 69 | 70 | System.out.println("Sci-Fi Movies:"); 71 | sciFiMovies.forEach(movie -> System.out.println(movie)); 72 | 73 | System.out.println("\nSorted by Release Year:"); 74 | sortedMovies.forEach(movie -> System.out.println(movie)); 75 | 76 | System.out.println("\nTop Rated Movies:"); 77 | topRatedMovies.forEach(movie -> System.out.println(movie)); 78 | } 79 | ``` 80 | 81 | ----- 82 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /30. Capstone Project/Part 1.md: -------------------------------------------------------------------------------- 1 | # Capstone Project 2 | 3 | Congratulations on reaching the Capstone Project. This project will test the skills that you learned in Module 2. As such, a video solution will not be provided, but you will still have access to a final solution inside your Bootcamp Resources. 4 | 5 | ## Download the starter project 6 | ----------------------------------- 7 | 8 | Launch the `starter-code` folder inside `Java Bootcamp Resources` -> `Module 2` -> `Casptone Project`. 9 | 10 | 11 | ## Task 1 12 | 13 | Inside `TradeAccount.java`, create an abstract `TradeAccount` class. The `abstract` class will define the following field: 14 | 15 | ```java 16 | private String id; 17 | ``` 18 | 19 | ## Task 2 20 | 21 | Create getter and setter methods for the `id` field in the `TradeAccount` class. Do not worry about argument validation. 22 | 23 | ## Task 3 24 | 25 | Create a constructor that initializes the `id` field of a newly created `TradeAccount` object. 26 | 27 | ## Task 4 28 | 29 | Add an abstract method called `clone` to the `TradeAccount` class. The `clone` method will have no parameters and return a `TradeAccount` object. 30 | 31 | ## Task 5 32 | 33 | Make sure that `CashAccount` extends the `TradeAccount` class. The `CashAccount` class will define the following field: 34 | 35 | ```java 36 | private BigDecimal cashBalance; 37 | ``` 38 | 39 | ## Task 6 40 | 41 | Create getter and setter methods for the `cashBalance` field in the `CashAccount` class. Do not worry about argument validation. 42 | 43 | ## Task 7 44 | 45 | Create a constructor that initializes the fields of a newly created `CashAccount` object by calling the superclass constructor and updating the `cashBalance` field. 46 | 47 | ## Task 8 48 | 49 | Override the clone method in the `CashAccount` class. The method should return a new `CashAccount` object with the same `id` and `cashBalance`. 50 | 51 | ## Task 9 52 | 53 | Make sure that `MarginAccount` extends the `TradeAccount` class. The `MarginAccount` class will define the following field: 54 | 55 | ```java 56 | private BigDecimal margin; 57 | ``` 58 | 59 | ## Task 10 60 | 61 | Create getter and setter methods for the `margin` field in the `MarginAccount` class. Do not worry about argument validation. 62 | 63 | ## Task 11 64 | 65 | Create a constructor that initializes the fields of a newly created `MarginAccount` object by calling the superclass constructor and updating the `margin` field. 66 | 67 | ## Task 12 68 | Override the clone method in the `MarginAccount` class. The method should return a new `MarginAccount` object with the same `id` and `margin`. 69 | 70 | ## Task 13 71 | Test your implementation by creating instances of the `CashAccount` and `MarginAccount` classes and calling their clone methods. 72 | 73 | ```java 74 | public static void main(String[] args) { 75 | CashAccount cashAccount = new CashAccount("C123", new BigDecimal("1000.00")); 76 | System.out.println("Cash Account Details:"); 77 | System.out.println("ID: " + cashAccount.getId()); 78 | System.out.println("Cash Balance: " + cashAccount.getCashBalance()); 79 | 80 | CashAccount clonedCashAccount = (CashAccount) cashAccount.clone(); 81 | System.out.println("Cloned Cash Account Details:"); 82 | System.out.println("ID: " + clonedCashAccount.getId()); 83 | System.out.println("Cash Balance: " + clonedCashAccount.getCashBalance()); 84 | 85 | System.out.println(); 86 | 87 | MarginAccount marginAccount = new MarginAccount("M456", new BigDecimal("5000.00")); 88 | System.out.println("Margin Account Details:"); 89 | System.out.println("ID: " + marginAccount.getId()); 90 | System.out.println("Margin: " + marginAccount.getMargin()); 91 | 92 | MarginAccount clonedMarginAccount = (MarginAccount) marginAccount.clone(); 93 | System.out.println("Cloned Margin Account Details:"); 94 | System.out.println("ID: " + clonedMarginAccount.getId()); 95 | System.out.println("Margin: " + clonedMarginAccount.getMargin()); 96 | } 97 | ``` 98 | 99 | Compile and run the `Main` class to test your implementation. The output should display the details of the cash account and margin account instances, as well as the cloned instances. 100 | 101 | ---------- 102 | 103 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /30. Capstone Project/Part 2.md: -------------------------------------------------------------------------------- 1 | # Capstone Project 2 | 3 | This workbook assumes that you successfully completed Part 1. 4 | 5 | ## Task 1 6 | Inside `TradeAccountRepository.java`, create a `TradeAccountRepository` class. The class will define a `private datastore` field: 7 | 8 | ```java 9 | private Map datastore = new HashMap<>(); 10 | ``` 11 | 12 | The `datastore` field will be used to store `TradeAccount` objects using their `id` as the key. 13 | 14 | ## Task 2 15 | 16 | - Create a method called `createTradeAccount` in the `TradeAccountRepository` class. 17 | - The method should have one parameter, a `TradeAccount` object, and return no value. 18 | - The `createTradeAccount` method should store a clone of the `TradeAccount` object in the datastore using the id field as the key. 19 | 20 | ## Task 3 21 | - Create a method called `retrieveTradeAccount` in the `TradeAccountRepository` class. 22 | - The method should have one parameter, a `String id`, and return a `TradeAccount` object. 23 | - The retrieveTradeAccount method should return null or a clone of the TradeAccount object stored in the datastore with the specified id. Use the line of code below (or something similar) to ensure that clone doesn't potentially get called on a null, thereby causing a NullPointerException. 24 | 25 | ```java 26 | this.datastore.get(id) == null ? null : this.datastore.get(id).clone(); 27 | ``` 28 | 29 | 30 | 31 | ## Task 4 32 | - Create a method called `updateTradeAccount` in the `TradeAccountRepository` class. 33 | - The method should have one parameter, a `TradeAccount` object, and return no value. 34 | - The updateTradeAccount method should update the `TradeAccount` object in the datastore using the `id` field as the key. It should store a clone of the `TradeAccount` object to ensure that the original object is not modified. 35 | 36 | ## Task 5 37 | - Create a method called `deleteTradeAccount` in the `TradeAccountRepository` class. 38 | - The method should have one parameter, a `String id`, and return no value. 39 | - The `deleteTradeAccount` method should remove the `TradeAccount` object with the specified `id` from the datastore. 40 | 41 | ## Task 6 42 | Test your implementation by creating a `TradeAccountRepository` object and performing the create, retrieve, update, and delete operations. 43 | 44 | ```java 45 | public static void main(String[] args) { 46 | TradeAccountRepository repository = new TradeAccountRepository(); 47 | 48 | CashAccount cashAccount = new CashAccount("C123", new BigDecimal("1000.00")); 49 | repository.createTradeAccount(cashAccount); 50 | 51 | MarginAccount marginAccount = new MarginAccount("M456", new BigDecimal("5000.00")); 52 | repository.createTradeAccount(marginAccount); 53 | 54 | TradeAccount retrievedCashAccount = repository.retrieveTradeAccount("C123"); 55 | System.out.println("Retrieved Cash Account ID: " + retrievedCashAccount.getId()); 56 | System.out.println("Cash Balance: " + ((CashAccount) retrievedCashAccount).getCashBalance()); 57 | 58 | TradeAccount retrievedMarginAccount = repository.retrieveTradeAccount("M456"); 59 | System.out.println("Retrieved Margin Account ID: " + retrievedMarginAccount.getId()); 60 | System.out.println("Margin: " + ((MarginAccount) retrievedMargin 61 | ``` 62 | 63 | ---------- 64 | 65 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 66 | -------------------------------------------------------------------------------- /30. Capstone Project/Part 3.md: -------------------------------------------------------------------------------- 1 | # Capstone Project 2 | 3 | This workbook assumes that you successfully completed Part 2. 4 | 5 | ## Task 1 6 | Create an interface called `TradeAccountService` with two methods: 7 | 8 | ```java 9 | public interface TradeAccountService { 10 | public void deposit(String id, BigDecimal amount); 11 | public void withdraw(String id, BigDecimal amount); 12 | } 13 | ``` 14 | 15 | ## Task 2 16 | Create a class called `CashAccountService` that implements the `TradeAccountService` interface. The class should have a `TradeAccountRepository` object as a private field. 17 | 18 | ## Task 3 19 | In the `CashAccountService` class, implement the `deposit` and `withdraw` methods: 20 | 21 | - The `deposit` method should add the given amount to the `cashBalance` field of the specified `CashAccount` object. 22 | - The `withdraw` method should subtract the given amount from the `cashBalance` field of the specified `CashAccount` object. 23 | 24 | Also, implement the following methods: 25 | 26 | - `createTradeAccount` 27 | - `retrieveTradeAccount` 28 | - `updateTradeAccount` 29 | - `deleteTradeAccount` 30 | 31 | These methods should interact with the `TradeAccountRepository` object to manage `CashAccount` objects. 32 | 33 | ## Task 4 34 | Create a class called `MarginAccountService` that implements the `TradeAccountService` interface. The class should have a `TradeAccountRepository` object as a `private` field: 35 | 36 | ## Task 5 37 | In the `MarginAccountService` class, implement the `deposit` and `withdraw` methods: 38 | 39 | - The `deposit` method should add the given amount to the `margin` field of the specified `MarginAccount` object. 40 | - The `withdraw` method should subtract the given amount from the `margin` field of the specified `MarginAccount` object. 41 | 42 | Also, implement the following methods: 43 | 44 | - `createTradeAccount` 45 | - `retrieveTradeAccount` 46 | - `updateTradeAccount` 47 | - `deleteTradeAccount` 48 | 49 | These methods should interact with the `TradeAccountRepository` object to manage `MarginAccount` objects. 50 | 51 | ## Task 6 52 | 53 | Below is a code snippet to test your implementation. Make sure that you get a similar output. 54 | 55 | ### Output 56 | ``` 57 | >>: Updated CashAccount balance: 1300 58 | >>: Updated MarginAccount margin: 2500 59 | ``` 60 | 61 | ### Sample Code 62 | ```java 63 | 64 | public static void main(String[] args) { 65 | TradeAccountRepository repository = new TradeAccountRepository(); 66 | CashAccountService cashAccountService = new CashAccountService(repository); 67 | MarginAccountService marginAccountService = new MarginAccountService(repository); 68 | 69 | // Create CashAccount and MarginAccount objects 70 | CashAccount cashAccount = new CashAccount("1", BigDecimal.valueOf(1000)); 71 | MarginAccount marginAccount = new MarginAccount("2", BigDecimal.valueOf(2000), BigDecimal.valueOf(10000)); 72 | 73 | // Add the accounts to the repository 74 | cashAccountService.createTradeAccount(cashAccount); 75 | marginAccountService.createTradeAccount(marginAccount); 76 | 77 | // Deposit and withdraw amounts 78 | cashAccountService.deposit("1", BigDecimal.valueOf(500)); 79 | cashAccountService.withdraw("1", BigDecimal.valueOf(200)); 80 | marginAccountService.deposit("2", BigDecimal.valueOf(1000)); 81 | marginAccountService.withdraw("2", BigDecimal.valueOf(500)); 82 | 83 | // Retrieve and print the updated account balances 84 | CashAccount updatedCashAccount = cashAccountService.retrieveTradeAccount("1"); 85 | MarginAccount updatedMarginAccount = marginAccountService.retrieveTradeAccount("2"); 86 | System.out.println("Updated CashAccount balance: " + updatedCashAccount.getCashBalance()); 87 | System.out.println("Updated MarginAccount margin: " + updatedMarginAccount.getMargin()); 88 | 89 | // Delete the accounts 90 | cashAccountService.deleteTradeAccount("1"); 91 | marginAccountService.deleteTradeAccount("2"); 92 | } 93 | ``` 94 | 95 | ---------- 96 | 97 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /30. Capstone Project/Part 4.md: -------------------------------------------------------------------------------- 1 | # Capstone Project 2 | 3 | This workbook assumes that you successfully completed Part 3. 4 | 5 | ## Preliminary Task 6 | Remove all the code inside of your `Main` class. At the class level, declare the following variables: 7 | ```java 8 | static Path[] paths = new Path[] {Paths.get("data/accounts.txt"), Paths.get("data/transactions.txt")}; 9 | 10 | static TradeAccountRepository tradeAccountRepository = new TradeAccountRepository(); 11 | static CashAccountService cashAccountService = new CashAccountService(tradeAccountRepository); 12 | static MarginAccountService marginAccountService = new MarginAccountService(tradeAccountRepository); 13 | ``` 14 | 15 | - The `paths` array holds the file paths for `data/accounts.txt` and `data/transactions.txt`. 16 | - Instances of `TradeAccountRepository`, `CashAccountService`, and `MarginAccountService` will be used to manage the data. 17 | 18 | 19 | ## Task 1 20 | - Write a method called `loadTradeAccounts` to read the file data/accounts.txt. 21 | - For each line in the file, split the line into an array of strings and create either a `CashAccount` or a `MarginAccount` object based on the account type. 22 | - Add the created account to the corresponding account service (`cashAccountService` or `marginAccountService`). 23 | 24 | 25 | ## Task 2 26 | 27 | - Write a method called `applyTransactions` to read the file data/transactions.txt. 28 | - For each line in the file, split the line into an array of strings and determine the account type, transaction type (`DEPOSIT` or `WITHDRAW`), and the amount. 29 | - Use the appropriate account service (`cashAccountService` or `marginAccountService`) to deposit or withdraw the specified amount. 30 | 31 | ## Task 3 32 | 33 | Copy this method to print the cash balance of the `CashAccount` and `MarginAccount` objects. 34 | 35 | ```java 36 | public static void finalTest() throws IOException { 37 | System.out.println("Account A1234B Cash Balance: " + cashAccountService.retrieveTradeAccount("A1234B").getCashBalance()); 38 | System.out.println("Account E3456F Cash Balance: " + cashAccountService.retrieveTradeAccount("E3456F").getCashBalance()); 39 | System.out.println("Account I5678J Cash Balance: " + cashAccountService.retrieveTradeAccount("I5678J").getCashBalance()); 40 | System.out.println("Account C2345D Margin: " + marginAccountService.retrieveTradeAccount("C2345D").getMargin()); 41 | System.out.println("Account G4567H Margin: " + marginAccountService.retrieveTradeAccount("G4567H").getMargin()); 42 | } 43 | ``` 44 | 45 | ## Task 4 46 | 47 | In the `main` method, use a `try-catch` block to call the `loadTradeAccounts`, `applyTransactions`, and `finalTest` methods. 48 | 49 | ```java 50 | public static void main(String[] args) { 51 | try { 52 | loadTradeAccounts(); 53 | applyTransactions(); 54 | finalTest(); 55 | } catch (IOException exception) { 56 | System.out.println(exception.getMessage()); 57 | } 58 | } 59 | ``` 60 | 61 | ### Expected Output 62 | ```java 63 | Account A1234B Cash Balance: 512.00 64 | Account E3456F Cash Balance: 325.45 65 | Account I5678J Cash Balance: 125.20 66 | Account C2345D Margin: 15.40 67 | Account G4567H Margin: 224.95 68 | ``` 69 | 70 | # Congratulations on Finishing the Course! 71 | 72 | ---------- 73 | 74 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Workbooks and Challenges for the Java Bootcamp 2 | 3 | ##### **Go From Zero to DevOps Master**: *[Java → Spring Boot → Docker → Kubernetes](https://rslim087a.github.io/zero-devops-roadmap/)* 4 | -------------------------------------------------------------------------------- /docs/quiz-styles.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --primary-color: #2196f3; 3 | --secondary-color: #1565c0; 4 | --success-color: #4caf50; 5 | --error-color: #f44336; 6 | --border-color: #e0e0e0; 7 | --text-color: #333; 8 | --bg-color: #f5f5f5; 9 | } 10 | 11 | body { 12 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; 13 | line-height: 1.6; 14 | color: var(--text-color); 15 | background-color: var(--bg-color); 16 | margin: 0; 17 | padding: 20px; 18 | } 19 | 20 | .quiz-content { 21 | max-width: 800px; 22 | margin: 0 auto; 23 | background: white; 24 | padding: 2rem; 25 | border-radius: 8px; 26 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); 27 | } 28 | 29 | .question { 30 | margin-bottom: 2.5rem; 31 | padding: 1.5rem; 32 | border: 1px solid var(--border-color); 33 | border-radius: 8px; 34 | } 35 | 36 | .question span { 37 | font-size: 1.25rem; 38 | font-weight: 600; 39 | color: var(--secondary-color); 40 | } 41 | 42 | .question-prompt { 43 | margin: 1rem 0; 44 | font-size: 1.1rem; 45 | } 46 | 47 | .question-answer label { 48 | display: block; 49 | padding: 1rem; 50 | margin: 0.5rem 0; 51 | border: 2px solid var(--border-color); 52 | border-radius: 6px; 53 | cursor: pointer; 54 | transition: all 0.2s ease; 55 | } 56 | 57 | .question-answer label:hover { 58 | background-color: #f8f9fa; 59 | border-color: var(--primary-color); 60 | } 61 | 62 | .question-answer input[type="radio"] { 63 | display: none; 64 | } 65 | 66 | .question-answer span { 67 | display: inline-block; 68 | width: 20px; 69 | height: 20px; 70 | border: 2px solid var(--border-color); 71 | border-radius: 50%; 72 | margin-right: 10px; 73 | position: relative; 74 | vertical-align: middle; 75 | } 76 | 77 | .question-answer .selected { 78 | border-color: var(--primary-color); 79 | background: var(--primary-color); 80 | box-shadow: 0 0 0 4px white inset; 81 | } 82 | 83 | .correct { 84 | border-color: var(--success-color) !important; 85 | background-color: #e8f5e9 !important; 86 | } 87 | 88 | .incorrect { 89 | border-color: var(--error-color) !important; 90 | background-color: #ffebee !important; 91 | } 92 | 93 | code { 94 | background-color: #f8f9fa; 95 | border: 1px solid #e9ecef; 96 | border-radius: 4px; 97 | color: #e91e63; 98 | font-family: 'Courier New', Courier, monospace; 99 | padding: 0.2rem 0.4rem; 100 | font-size: 0.9em; 101 | } 102 | 103 | pre { 104 | background-color: #f8f9fa; 105 | border: 1px solid #e9ecef; 106 | border-radius: 4px; 107 | padding: 1rem; 108 | overflow-x: auto; 109 | } 110 | 111 | .submit-button { 112 | background-color: var(--primary-color); 113 | color: white; 114 | border: none; 115 | padding: 0.8rem 1.5rem; 116 | border-radius: 4px; 117 | cursor: pointer; 118 | font-size: 1rem; 119 | margin-top: 1rem; 120 | transition: background-color 0.2s ease; 121 | } 122 | 123 | .submit-button:hover { 124 | background-color: var(--secondary-color); 125 | } 126 | 127 | img { 128 | max-width: 100%; 129 | height: auto; 130 | margin: 1rem 0; 131 | border-radius: 4px; 132 | } 133 | 134 | ul.answers { 135 | list-style-type: none; 136 | padding: 0; 137 | margin: 0; 138 | } 139 | 140 | /* This updates the score display */ 141 | .score { 142 | position: fixed; 143 | top: 20px; 144 | right: 20px; 145 | background-color: white; 146 | padding: 0.8rem 1.2rem; 147 | border-radius: 8px; 148 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); 149 | font-weight: 500; 150 | font-variant-numeric: tabular-nums; 151 | font-feature-settings: "tnum"; 152 | } 153 | 154 | .answers li { 155 | list-style: none; 156 | } 157 | 158 | /* and to be extra safe, add this too */ 159 | .question-answer { 160 | list-style: none; 161 | padding: 0; 162 | margin: 0; 163 | } 164 | 165 | .back-button { 166 | position: fixed; 167 | top: 20px; 168 | left: 20px; 169 | padding: 12px 24px; 170 | background: #2196f3; 171 | color: white; 172 | border: none; 173 | border-radius: 8px; 174 | text-decoration: none; 175 | font-family: Arial, sans-serif; 176 | font-size: 18px; 177 | font-weight: 500; 178 | box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3); 179 | transition: all 0.2s ease; 180 | } 181 | 182 | .back-button:hover { 183 | background: #1976d2; 184 | transform: translateY(-2px); 185 | box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4); 186 | } 187 | --------------------------------------------------------------------------------