├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── _01_02b └── Employee.java ├── _01_02e └── Employee.java ├── _01_03b └── Employee.java ├── _01_03e └── Employee.java ├── _01_04 ├── MenuBuilder.java └── MenuItem.java ├── _01_05b ├── MenuBuilder.java └── MenuItem.java ├── _01_05e ├── MenuBuilder.java └── MenuItem.java ├── _02_02 └── Instructions.md ├── _02_03b └── Instructions.md ├── _02_03e ├── Instructions.md └── Ticket.java ├── _02_04 └── Ticket.java ├── _02_05b └── Ticket.java ├── _02_05e └── Ticket.java ├── _02_06 ├── Ticket.java └── TicketMachine.java ├── _02_07b ├── Ticket.java └── TicketMachine.java ├── _02_07e ├── Ticket.java └── TicketMachine.java ├── _03_02 ├── GradingSystem.java └── Main.java ├── _03_03b ├── GradingSystem.java └── Main.java ├── _03_03e ├── GradingSystem.java └── Main.java ├── _03_04 └── ForLoops.java ├── _03_05b └── ForLoops.java ├── _03_05e └── ForLoops.java ├── _03_06 └── EnhancedForLoops.java ├── _03_07b └── EnhancedForLoops.java └── _03_07e └── EnhancedForLoops.java /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/java/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster 4 | ARG VARIANT="17-bullseye" 5 | FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} 6 | 7 | # [Option] Install Maven 8 | ARG INSTALL_MAVEN="false" 9 | ARG MAVEN_VERSION="" 10 | # [Option] Install Gradle 11 | ARG INSTALL_GRADLE="false" 12 | ARG GRADLE_VERSION="" 13 | RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \ 14 | && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi 15 | 16 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 17 | ARG NODE_VERSION="none" 18 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 19 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Java", 3 | "build": { 4 | "dockerfile": "Dockerfile", 5 | "args": { 6 | "VARIANT": "17", //Can change to another of Java 7 | "INSTALL_MAVEN": "false", 8 | "INSTALL_GRADLE": "false", 9 | "NODE_VERSION": "lts/*" 10 | } 11 | }, 12 | 13 | // Configure tool-specific properties. 14 | "customizations": { 15 | "vscode": { 16 | "settings": { 17 | "java.home": "/docker-java-home" 18 | }, 19 | "extensions": [ 20 | "vscjava.vscode-java-pack", 21 | "GitHub.github-vscode-theme" 22 | ] 23 | } 24 | }, 25 | "remoteUser": "vscode", 26 | "onCreateCommand": "echo PS1='\"$ \"' >> ~/.bashrc" //Set Terminal Prompt to $ 27 | } 28 | 29 | // DevContainer Reference: https://code.visualstudio.com/docs/remote/devcontainerjson-reference 30 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) deotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1.2 13 | env: 14 | key: main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .tmp 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.bracketPairColorization.enabled": true, 3 | "editor.cursorBlinking": "solid", 4 | "editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace", 5 | "editor.fontLigatures": false, 6 | "editor.fontSize": 22, 7 | "editor.formatOnPaste": true, 8 | "editor.formatOnSave": true, 9 | "editor.lineNumbers": "on", 10 | "editor.matchBrackets": "always", 11 | "editor.minimap.enabled": false, 12 | "editor.smoothScrolling": true, 13 | "editor.tabSize": 2, 14 | "editor.useTabStops": true, 15 | "editor.wordWrap": "on", 16 | "emmet.triggerExpansionOnTab": true, 17 | "explorer.openEditors.visible": 0, 18 | "files.autoSave": "afterDelay", 19 | "screencastMode.onlyKeyboardShortcuts": true, 20 | "terminal.integrated.fontSize": 18, 21 | "workbench.activityBar.visible": true, 22 | "workbench.colorTheme": "Visual Studio Dark", 23 | "workbench.fontAliasing": "antialiased", 24 | "workbench.statusBar.visible": true, 25 | "java.server.launchMode": "Standard" 26 | } 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2022 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | Please note, this project may automatically load third party code from external 8 | repositories (for example, NPM modules, Composer packages, or other dependencies). 9 | If so, such third party code may be subject to other license terms than as set 10 | forth above. In addition, such third party code may also depend on and load 11 | multiple tiers of dependencies. Please review the applicable licenses of the 12 | additional dependencies. 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Practice It: Java 2 | This is the repository for the LinkedIn Learning course Practice It: Java. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![1666990137684](https://user-images.githubusercontent.com/25848438/200746910-2bf98861-d1a5-4046-a741-667e03daa3ec.jpeg) 5 | 6 | Looking for a chance to practice using your Java skills in a real-world scenario? You’re in luck. This course was designed to offer accessible and interactive training for learners like you. Join instructor Bethan Palmer to learn more about the basics of writing code in Java, one of the most widely used object-oriented programming languages in the world. Find out how to work with variables, classes, and objects, before turning your attention to control flow. Bethan shares insights and pointers from her own experience to help you get the most out of each task. By the end of this course, you’ll be prepared to wield your newly acquired skills so you can keep coding in Java on your own.

This course is integrated with GitHub Codespaces, an instant cloud developer environment that offers all the functionality of your favorite IDE without the need for any local machine setup. With GitHub Codespaces, you can get hands-on practice from any machine, at any time—all while using a tool that you’ll likely encounter in the workplace. Check out the [Using GitHub Codespaces with this course][gcs-video-url] video to learn how to get started. 7 | 8 | ### Instructor 9 | 10 | Bethan Palmer 11 | 12 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/bethan-palmer?u=104). 13 | 14 | [lil-course-url]: https://www.linkedin.com/learning/practice-it-java 15 | [gcs-video-url]: https://www.linkedin.com/learning/practice-it-java/using-github-codespaces-with-this-course 16 | -------------------------------------------------------------------------------- /_01_02b/Employee.java: -------------------------------------------------------------------------------- 1 | package _01_02b; 2 | 3 | public class Employee { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Create a variable called age of type int and assign it the value 29. 8 | 9 | // Print the age variable to the console. 10 | 11 | // Create a variable called isAManager of type boolean and assign it the value 12 | // true. 13 | 14 | // Print the isAManager variable to the console. 15 | 16 | // Create a variable called yearsOfService of type double and assign it the 17 | // value 2.5. 18 | 19 | // Print the yearsOfService variable to the console. 20 | 21 | // Create a variable called baseSalary of type int and assign it the value 3000. 22 | 23 | // Create a variable called overtimePayment of type int and assign it the value 24 | // 40. 25 | 26 | // Create a variable called totalPayment of type int and assign it to the value 27 | // of baseSalary added to overtimePayment. 28 | 29 | // Print the totalPayment variable to the console. 30 | 31 | // Create three variables all of type double on a single line. 32 | // They should be called firstBonus, secondBonus and thirdBonus and they should 33 | // be assigned the values 10.00, 22.00 and 35.00. 34 | 35 | // Print out the sum of the variables called firstBonus, secondBonus and 36 | // thirdBonus. 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /_01_02e/Employee.java: -------------------------------------------------------------------------------- 1 | package _01_02e; 2 | 3 | public class Employee { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Create a variable called age of type int and assign it the value 29. 8 | int age = 29; 9 | 10 | // Print the age variable to the console. 11 | System.out.println(age); 12 | 13 | // Create a variable called isAManager of type boolean and assign it the value 14 | // true. 15 | 16 | // Print the isAManager variable to the console. 17 | 18 | // Create a variable called yearsOfService of type double and assign it the 19 | // value 2.5. 20 | 21 | // Print the yearsOfService variable to the console. 22 | 23 | // Create a variable called baseSalary of type int and assign it the value 3000. 24 | 25 | // Create a variable called overtimePayment of type int and assign it the value 26 | // 40. 27 | 28 | // Create a variable called totalPayment of type int and assign it to the value 29 | // of baseSalary added to overtimePayment. 30 | 31 | // Print the totalPayment variable to the console. 32 | 33 | // Create three variables all of type double on a single line. 34 | // They should be called firstBonus, secondBonus and thirdBonus and they should 35 | // be assigned the values 10.00, 22.00 and 35.00. 36 | 37 | // Print out the sum of the variables called firstBonus, secondBonus and 38 | // thirdBonus. 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /_01_03b/Employee.java: -------------------------------------------------------------------------------- 1 | package _01_03b; 2 | 3 | public class Employee { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Create a variable called age of type int and assign it the value 29. 8 | int age = 29; 9 | 10 | // Print the age variable to the console. 11 | System.out.println(age); 12 | 13 | // Create a variable called isAManager of type boolean and assign it the value 14 | // true. 15 | 16 | // Print the isAManager variable to the console. 17 | 18 | // Create a variable called yearsOfService of type double and assign it the 19 | // value 2.5. 20 | 21 | // Print the yearsOfService variable to the console. 22 | 23 | // Create a variable called baseSalary of type int and assign it the value 3000. 24 | 25 | // Create a variable called overtimePayment of type int and assign it the value 26 | // 40. 27 | 28 | // Create a variable called totalPayment of type int and assign it to the value 29 | // of baseSalary added to overtimePayment. 30 | 31 | // Print the totalPayment variable to the console. 32 | 33 | // Create three variables all of type double on a single line. 34 | // They should be called firstBonus, secondBonus and thirdBonus and they should 35 | // be assigned the values 10.00, 22.00 and 35.00. 36 | 37 | // Print out the sum of the variables called firstBonus, secondBonus and 38 | // thirdBonus. 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /_01_03e/Employee.java: -------------------------------------------------------------------------------- 1 | package _01_03e; 2 | 3 | public class Employee { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Create a variable called age of type int and assign it the value 29. 8 | int age = 29; 9 | 10 | // Print the age variable to the console. 11 | System.out.println(age); 12 | 13 | // Create a variable called isAManager of type boolean and assign it the value 14 | // true. 15 | boolean isAManager = true; 16 | 17 | // Print the isAManager variable to the console. 18 | System.out.println(isAManager); 19 | 20 | // Create a variable called yearsOfService of type double and assign it the 21 | // value 2.5. 22 | double yearsOfService = 2.5; 23 | 24 | // Print the yearsOfService variable to the console. 25 | System.out.println(yearsOfService); 26 | 27 | // Create a variable called baseSalary of type int and assign it the value 3000. 28 | int baseSalary = 3000; 29 | 30 | // Create a variable called overtimePayment of type int and assign it the value 31 | // 40. 32 | int overtimePayment = 40; 33 | 34 | // Create a variable called totalPayment of type int and assign it to the value 35 | // of baseSalary added to overtimePayment. 36 | int totalPayment = baseSalary + overtimePayment; 37 | 38 | // Print the totalPayment variable to the console. 39 | System.out.println(totalPayment); 40 | 41 | // Create three variables all of type double on a single line. 42 | // They should be called firstBonus, secondBonus and thirdBonus and they should 43 | // be assigned the values 10.00, 22.00 and 35.00. 44 | double firstBonus = 10.00, secondBonus = 22.00, thirdBonus = 35.00; 45 | 46 | // Print out the sum of the variables called firstBonus, secondBonus and 47 | // thirdBonus. 48 | System.out.println(firstBonus + secondBonus + thirdBonus); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /_01_04/MenuBuilder.java: -------------------------------------------------------------------------------- 1 | package _01_04; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class MenuBuilder { 6 | public static void main(String[] args) { 7 | 8 | // Create a variable called menuTitle of type String and assign it the value "My 9 | // Dream Menu:". 10 | 11 | // Print the menuTitle variable to the console. 12 | 13 | // Create a variable called menu of type ArrayList. 14 | 15 | // Create a variable called starter of type MenuItem and pass in the name of 16 | // your favourite starter. 17 | 18 | // Add the starter variable to the ArrayList called menu. 19 | 20 | // Create a variable called mainCourse of type MenuItem and pass in the name of 21 | // your favourite main course. 22 | 23 | // Add the mainCourse variable to the ArrayList called menu. 24 | 25 | // Create a variable called dessert of type MenuItem and pass in the name of 26 | // your favourite dessert. 27 | 28 | // Add the dessert variable to the ArrayList called menu. 29 | 30 | // Print the menu variable to the console. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /_01_04/MenuItem.java: -------------------------------------------------------------------------------- 1 | package _01_04; 2 | 3 | public class MenuItem { 4 | 5 | private String name; 6 | 7 | public MenuItem(String name) { 8 | this.name = name; 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | return name; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /_01_05b/MenuBuilder.java: -------------------------------------------------------------------------------- 1 | package _01_05b; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class MenuBuilder { 6 | public static void main(String[] args) { 7 | 8 | // Create a variable called menuTitle of type String and assign it the value "My 9 | // Dream Menu:". 10 | 11 | // Print the menuTitle variable to the console. 12 | 13 | // Create a variable called menu of type ArrayList. 14 | 15 | // Create a variable called starter of type MenuItem and pass in the name of 16 | // your favourite starter. 17 | 18 | // Add the starter variable to the ArrayList called menu. 19 | 20 | // Create a variable called mainCourse of type MenuItem and pass in the name of 21 | // your favourite main course. 22 | 23 | // Add the mainCourse variable to the ArrayList called menu. 24 | 25 | // Create a variable called dessert of type MenuItem and pass in the name of 26 | // your favourite dessert. 27 | 28 | // Add the dessert variable to the ArrayList called menu. 29 | 30 | // Print the menu variable to the console. 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /_01_05b/MenuItem.java: -------------------------------------------------------------------------------- 1 | package _01_05b; 2 | 3 | public class MenuItem { 4 | 5 | private String name; 6 | 7 | public MenuItem(String name) { 8 | this.name = name; 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | return name; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /_01_05e/MenuBuilder.java: -------------------------------------------------------------------------------- 1 | package _01_05e; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class MenuBuilder { 6 | public static void main(String[] args) { 7 | 8 | // Create a variable called menuTitle of type String and assign it the value "My 9 | // Dream Menu:". 10 | String menuTitle = "My Dream Menu:"; 11 | 12 | // Print the menuTitle variable to the console. 13 | System.out.println(menuTitle); 14 | 15 | // Create a variable called menu of type ArrayList. 16 | ArrayList menu = new ArrayList<>(); 17 | 18 | // Create a variable called starter of type MenuItem and pass in the name of 19 | // your favourite starter. 20 | MenuItem starter = new MenuItem("Calamari"); 21 | 22 | // Add the starter variable to the ArrayList called menu. 23 | menu.add(starter); 24 | 25 | // Create a variable called mainCourse of type MenuItem and pass in the name of 26 | // your favourite main course. 27 | MenuItem mainCourse = new MenuItem("Lasagne"); 28 | 29 | // Add the mainCourse variable to the ArrayList called menu. 30 | menu.add(mainCourse); 31 | 32 | // Create a variable called dessert of type MenuItem and pass in the name of 33 | // your favourite dessert. 34 | MenuItem dessert = new MenuItem("Banoffee Pie"); 35 | 36 | // Add the dessert variable to the ArrayList called menu. 37 | menu.add(dessert); 38 | 39 | // Print the menu variable to the console. 40 | System.out.println(menu); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /_01_05e/MenuItem.java: -------------------------------------------------------------------------------- 1 | package _01_05e; 2 | 3 | public class MenuItem { 4 | 5 | private String name; 6 | 7 | public MenuItem(String name) { 8 | this.name = name; 9 | } 10 | 11 | @Override 12 | public String toString() { 13 | return name; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /_02_02/Instructions.md: -------------------------------------------------------------------------------- 1 | 1. Create a class called Ticket 2 | 2. Give the class an empty constructor 3 | 3. Create 3 private field variables in the class: 4 | - A field of type String called destination 5 | - A field called price of type double 6 | - A field called isReturn of type boolean 7 | -------------------------------------------------------------------------------- /_02_03b/Instructions.md: -------------------------------------------------------------------------------- 1 | 1. Create a class called Ticket 2 | 2. Give the class an empty constructor 3 | 3. Create 3 field variables in the class: 4 | - A field of type String called destination 5 | - A field called price of type double 6 | - A field called isReturn of type boolean 7 | -------------------------------------------------------------------------------- /_02_03e/Instructions.md: -------------------------------------------------------------------------------- 1 | 1. Create a class called Ticket 2 | 2. Give the class an empty constructor 3 | 3. Create 3 field variables in the class: 4 | - A field of type String called destination 5 | - A field called price of type double 6 | - A field called isReturn of type boolean 7 | -------------------------------------------------------------------------------- /_02_03e/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_03e; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /_02_04/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_04; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | // Add three methods to set the value of each field, called setDestination, 14 | // setPrice and setIsReturn. 15 | 16 | // Add a separate method to get the value of each field, called getDestination, 17 | // getPrice and getIsReturn. 18 | 19 | } 20 | -------------------------------------------------------------------------------- /_02_05b/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_05b; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | // Add three public methods to set the value of each field, called 14 | // setDestination, setPrice and setIsReturn. 15 | 16 | // Add three public methods to get the value of each field, called 17 | // getDestination, getPrice and getIsReturn. 18 | 19 | } 20 | -------------------------------------------------------------------------------- /_02_05e/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_05e; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | // Add three public methods to set the value of each field, called 14 | // setDestination, setPrice and setIsReturn. 15 | 16 | public void setDestination(String destination) { 17 | this.destination = destination; 18 | } 19 | 20 | public void setPrice(int price) { 21 | this.price = price; 22 | } 23 | 24 | public void setIsReturn(boolean isReturn) { 25 | this.isReturn = isReturn; 26 | } 27 | 28 | // Add three public methods to get the value of each field, called 29 | // getDestination, getPrice and getIsReturn. 30 | 31 | public String getDestination() { 32 | return destination; 33 | } 34 | 35 | public double getPrice() { 36 | return price; 37 | } 38 | 39 | public boolean getIsReturn() { 40 | return isReturn; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /_02_06/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_06; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | // Add three public methods to set the value of each field, called 14 | // setDestination, setPrice and setIsReturn. 15 | 16 | public void setDestination(String destination) { 17 | this.destination = destination; 18 | } 19 | 20 | public void setPrice(double price) { 21 | this.price = price; 22 | } 23 | 24 | public void setIsReturn(boolean isReturn) { 25 | this.isReturn = isReturn; 26 | } 27 | 28 | // Add three public methods to get the value of each field, called 29 | // getDestination, getPrice and getIsReturn. 30 | 31 | public String getDestination() { 32 | return destination; 33 | } 34 | 35 | public double getPrice() { 36 | return price; 37 | } 38 | 39 | public boolean getIsReturn() { 40 | return isReturn; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /_02_06/TicketMachine.java: -------------------------------------------------------------------------------- 1 | package _02_06; 2 | 3 | public class TicketMachine { 4 | 5 | public static void main(String[] args) { 6 | // Create an object called ticket of type Ticket 7 | 8 | // Set the destination of the ticket to New York 9 | 10 | // Set the price of the ticket to 15.30 11 | 12 | // Set the isReturn value to true 13 | 14 | // Print the ticket's destination to the console 15 | 16 | // Print the ticket's price to the console 17 | 18 | // Print the ticket's isReturn value to the console 19 | 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /_02_07b/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_07b; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | // Add three public methods to set the value of each field, called 14 | // setDestination, setPrice and setIsReturn. 15 | 16 | public void setDestination(String destination) { 17 | this.destination = destination; 18 | } 19 | 20 | public void setPrice(double price) { 21 | this.price = price; 22 | } 23 | 24 | public void setIsReturn(boolean isReturn) { 25 | this.isReturn = isReturn; 26 | } 27 | 28 | // Add three public methods to get the value of each field, called 29 | // getDestination, getPrice and getIsReturn. 30 | 31 | public String getDestination() { 32 | return destination; 33 | } 34 | 35 | public double getPrice() { 36 | return price; 37 | } 38 | 39 | public boolean getIsReturn() { 40 | return isReturn; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /_02_07b/TicketMachine.java: -------------------------------------------------------------------------------- 1 | package _02_07b; 2 | 3 | public class TicketMachine { 4 | 5 | public static void main(String[] args) { 6 | // Create an object called ticket of type Ticket 7 | 8 | // Set the destination of the ticket to New York 9 | 10 | // Set the price of the ticket to 15.30 11 | 12 | // Set the isReturn value to true 13 | 14 | // Print the ticket's destination to the console 15 | 16 | // Print the ticket's price to the console 17 | 18 | // Print the ticket's isReturn value to the console 19 | 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /_02_07e/Ticket.java: -------------------------------------------------------------------------------- 1 | package _02_07e; 2 | 3 | public class Ticket { 4 | 5 | public Ticket() { 6 | 7 | } 8 | 9 | private String destination; 10 | private double price; 11 | private boolean isReturn; 12 | 13 | // Add three public methods to set the value of each field, called 14 | // setDestination, setPrice and setIsReturn. 15 | 16 | public void setDestination(String destination) { 17 | this.destination = destination; 18 | } 19 | 20 | public void setPrice(double price) { 21 | this.price = price; 22 | } 23 | 24 | public void setIsReturn(boolean isReturn) { 25 | this.isReturn = isReturn; 26 | } 27 | 28 | // Add three public methods to get the value of each field, called 29 | // getDestination, getPrice and getIsReturn. 30 | 31 | public String getDestination() { 32 | return destination; 33 | } 34 | 35 | public double getPrice() { 36 | return price; 37 | } 38 | 39 | public boolean getIsReturn() { 40 | return isReturn; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /_02_07e/TicketMachine.java: -------------------------------------------------------------------------------- 1 | package _02_07e; 2 | 3 | public class TicketMachine { 4 | 5 | public static void main(String[] args) { 6 | // Create an object called ticket of type Ticket 7 | Ticket ticket = new Ticket(); 8 | 9 | // Set the destination of the ticket to New York 10 | ticket.setDestination("New York"); 11 | 12 | // Set the price of the ticket to 15.30 13 | ticket.setPrice(15.30); 14 | 15 | // Set the isReturn value to true 16 | ticket.setIsReturn(true); 17 | 18 | // Print the ticket's destination to the console 19 | System.out.println(ticket.getDestination()); 20 | 21 | // Print the ticket's price to the console 22 | System.out.println(ticket.getPrice()); 23 | 24 | // Print the ticket's isReturn value to the console 25 | System.out.println(ticket.getIsReturn()); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /_03_02/GradingSystem.java: -------------------------------------------------------------------------------- 1 | package _03_02; 2 | 3 | public class GradingSystem { 4 | 5 | public boolean isAPass(int percentage) { 6 | // Return true if the percentage is higher than or equal to 60. 7 | // Otherwise return false. 8 | return false; 9 | } 10 | 11 | public char getGrade(int percentage) { 12 | // If the percentage is 90 or above, return 'A'. 13 | // If it's 80-89, return 'B'. 14 | // If it's 70-79, return 'C'. 15 | // If it's 60-69, return 'D'. 16 | // If it's less than 60, return 'F'. 17 | return 'X'; 18 | } 19 | 20 | public String retakeMessage(int percentage, boolean allowedToRetake) { 21 | // If percentage is less than 60 and allowedToRetake is true, return a String 22 | // that says "The student has been entered for a retake." 23 | // If percentage is less than 60 and allowedToRetake is false, return a String 24 | // that says "The student is not allowed to retake this exam." 25 | // If percentage is 60 or higher, return a String that says "A retake is not 26 | // required." 27 | return ""; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /_03_02/Main.java: -------------------------------------------------------------------------------- 1 | package _03_02; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | GradingSystem gradingSystem = new GradingSystem(); 7 | int percentage = 85; 8 | System.out.println("Percentage: " + percentage); 9 | System.out.println("Pass: " + gradingSystem.isAPass(percentage)); 10 | System.out.println("Grade: " + gradingSystem.getGrade(percentage)); 11 | System.out.println(gradingSystem.retakeMessage(percentage, true)); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /_03_03b/GradingSystem.java: -------------------------------------------------------------------------------- 1 | package _03_03b; 2 | 3 | public class GradingSystem { 4 | 5 | public boolean isAPass(int percentage) { 6 | // Return true if the percentage is higher than or equal to 60. 7 | // Otherwise return false. 8 | return false; 9 | } 10 | 11 | public char getGrade(int percentage) { 12 | // If the percentage is 90 or above, return 'A'. 13 | // If it's 80-89, return 'B'. 14 | // If it's 70-79, return 'C'. 15 | // If it's 60-69, return 'D'. 16 | // If it's less than 60, return 'F'. 17 | return 'X'; 18 | } 19 | 20 | public String retakeMessage(int percentage, boolean allowedToRetake) { 21 | // If percentage is less than 60 and allowedToRetake is true, return a String 22 | // that says "The student has been entered for a retake." 23 | // If percentage is less than 60 and allowedToRetake is false, return a String 24 | // that says "The student is not allowed to retake this exam." 25 | // If percentage is 60 or higher, return a String that says "A retake is not 26 | // required." 27 | return ""; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /_03_03b/Main.java: -------------------------------------------------------------------------------- 1 | package _03_03b; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | GradingSystem gradingSystem = new GradingSystem(); 7 | int percentage = 85; 8 | System.out.println("Percentage: " + percentage); 9 | System.out.println("Pass: " + gradingSystem.isAPass(percentage)); 10 | System.out.println("Grade: " + gradingSystem.getGrade(percentage)); 11 | System.out.println(gradingSystem.retakeMessage(percentage, true)); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /_03_03e/GradingSystem.java: -------------------------------------------------------------------------------- 1 | package _03_03e; 2 | 3 | public class GradingSystem { 4 | 5 | public boolean isAPass(int percentage) { 6 | // Return true if the percentage is higher than or equal to 60. 7 | // Otherwise return false. 8 | if (percentage >= 60) { 9 | return true; 10 | } else { 11 | return false; 12 | } 13 | } 14 | 15 | public char getGrade(int percentage) { 16 | // If the percentage is 90 or above, return 'A'. 17 | // If it's 80-89, return 'B'. 18 | // If it's 70-79, return 'C'. 19 | // If it's 60-69, return 'D'. 20 | // If it's less than 60, return 'F'. 21 | if (percentage >= 90) { 22 | return 'A'; 23 | } else if (percentage >= 80) { 24 | return 'B'; 25 | } else if (percentage >= 70) { 26 | return 'C'; 27 | } else if (percentage >= 60) { 28 | return 'D'; 29 | } else { 30 | return 'F'; 31 | } 32 | } 33 | 34 | public String retakeMessage(int percentage, boolean allowedToRetake) { 35 | // If percentage is less than 60 and allowedToRetake is true, return a String 36 | // that says "The student has been entered for a retake." 37 | // If percentage is less than 60 and allowedToRetake is false, return a String 38 | // that says "The student is not allowed to retake this exam." 39 | // If percentage is 60 or higher, return a String that says "A retake is not 40 | // required." 41 | if (percentage < 60 && allowedToRetake) { 42 | return "The student has been entered for a retake."; 43 | } else if (percentage < 60 && !allowedToRetake) { 44 | return "The student is not allowed to retake this exam."; 45 | } else { 46 | return "A retake is not required."; 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /_03_03e/Main.java: -------------------------------------------------------------------------------- 1 | package _03_03e; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | GradingSystem gradingSystem = new GradingSystem(); 7 | int percentage = 85; 8 | System.out.println("Percentage: " + percentage); 9 | System.out.println("Pass: " + gradingSystem.isAPass(percentage)); 10 | System.out.println("Grade: " + gradingSystem.getGrade(percentage)); 11 | System.out.println(gradingSystem.retakeMessage(percentage, true)); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /_03_04/ForLoops.java: -------------------------------------------------------------------------------- 1 | package _03_04; 2 | 3 | public class ForLoops { 4 | 5 | public static void main(String[] args) { 6 | // Write a for loop that prints out the phrase "I love for loops" 5 times 7 | 8 | // Write a for loop that prints out the numbers 1 to 10 9 | 10 | // Write a for loop that prints out the numbers 10 to 1 11 | 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /_03_05b/ForLoops.java: -------------------------------------------------------------------------------- 1 | package _03_05b; 2 | 3 | public class ForLoops { 4 | 5 | public static void main(String[] args) { 6 | // Write a for loop that prints out the phrase "I love for loops" 5 times 7 | 8 | // Write a for loop that prints out the numbers 1 to 10 9 | 10 | // Write a for loop that prints out the numbers 10 to 1 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /_03_05e/ForLoops.java: -------------------------------------------------------------------------------- 1 | package _03_05e; 2 | 3 | public class ForLoops { 4 | 5 | public static void main(String[] args) { 6 | // Write a for loop that prints out the phrase "I love for loops" 5 times 7 | for (int i = 0; i < 5; i++) { 8 | System.out.println("I love for loops"); 9 | } 10 | 11 | // Write a for loop that prints out the numbers 1 to 10 12 | for (int i = 1; i <= 10; i++) { 13 | System.out.println(i); 14 | } 15 | 16 | // Write a for loop that prints out the numbers 10 to 1 17 | for (int i = 10; i > 0; i--) { 18 | System.out.println(i); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /_03_06/EnhancedForLoops.java: -------------------------------------------------------------------------------- 1 | package _03_06; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class EnhancedForLoops { 7 | 8 | public static void main(String[] args) { 9 | int[] primeNumbers = { 2, 3, 5, 7, 11, 13, 17, 19 }; 10 | // Write an enhanced for loop to print out each prime number in the array. 11 | 12 | List weekDays = Arrays.asList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"); 13 | // Write an enhanced for loop to print out each week day in the list. 14 | 15 | int[] randomNumbers = { 23, 51, 72, 84, 1, 60, 34, 102 }; 16 | // Write an enhanced for loop to print out the numbers in the array that are 17 | // greater than 50. 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /_03_07b/EnhancedForLoops.java: -------------------------------------------------------------------------------- 1 | package _03_07b; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class EnhancedForLoops { 7 | 8 | public static void main(String[] args) { 9 | int[] primeNumbers = { 2, 3, 5, 7, 11, 13, 17, 19 }; 10 | // Write an enhanced for loop to print out each prime number in the array. 11 | 12 | List weekDays = Arrays.asList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"); 13 | // Write an enhanced for loop to print out each week day in the list. 14 | 15 | int[] randomNumbers = { 23, 51, 72, 84, 1, 60, 34, 102 }; 16 | // Write an enhanced for loop to print out the numbers in the array that are 17 | // greater than 50. 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /_03_07e/EnhancedForLoops.java: -------------------------------------------------------------------------------- 1 | package _03_07e; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class EnhancedForLoops { 7 | 8 | public static void main(String[] args) { 9 | int[] primeNumbers = { 2, 3, 5, 7, 11, 13, 17, 19 }; 10 | // Write an enhanced for loop to print out each prime number in the array. 11 | for (int primeNumber : primeNumbers) { 12 | System.out.println(primeNumber); 13 | } 14 | 15 | List weekDays = Arrays.asList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"); 16 | // Write an enhanced for loop to print out each week day in the list. 17 | for (String weekDay : weekDays) { 18 | System.out.println(weekDay); 19 | } 20 | 21 | int[] randomNumbers = { 23, 51, 72, 84, 1, 60, 34, 102 }; 22 | // Write an enhanced for loop to print out the numbers in the array that are 23 | // greater than 50. 24 | for (int randomNumber : randomNumbers) { 25 | if (randomNumber > 50) { 26 | System.out.println(randomNumber); 27 | } 28 | } 29 | 30 | } 31 | 32 | } 33 | --------------------------------------------------------------------------------