{"id":21735866,"url":"https://github.com/izzyluuuuh/strategy-pattern","last_synced_at":"2025-03-21T00:26:07.544Z","repository":{"id":224138271,"uuid":"762527008","full_name":"izzyluuuuh/strategy-pattern","owner":"izzyluuuuh","description":"Implementation of Strategy Pattern Using Java","archived":false,"fork":false,"pushed_at":"2024-02-25T02:46:46.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T21:09:29.926Z","etag":null,"topics":["application-development","java","strategy-design-pattern"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izzyluuuuh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-24T01:01:14.000Z","updated_at":"2024-02-24T01:52:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"8b41feed-cf77-41b9-96d6-ff13032412cb","html_url":"https://github.com/izzyluuuuh/strategy-pattern","commit_stats":null,"previous_names":["izzyluuuuh/strategy-pattern"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Fstrategy-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Fstrategy-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Fstrategy-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzyluuuuh%2Fstrategy-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzyluuuuh","download_url":"https://codeload.github.com/izzyluuuuh/strategy-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244714010,"owners_count":20497757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application-development","java","strategy-design-pattern"],"created_at":"2024-11-26T05:15:19.947Z","updated_at":"2025-03-21T00:26:07.523Z","avatar_url":"https://github.com/izzyluuuuh.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strategy Pattern\n## Implementation of Strategy Pattern Using Java\n\nThe **Strategy pattern** allows developers to define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.\n\n### Project Name: *TestStrategy*\n\n1. Create an interface named **Payment**. An interface is a group of related methods with empty bodies. Classes that implement an interface must use the methods of that interface.\n2. Create a void method for your interface named **pay**. It should be **public** and with a **double** parameter named **amount**. Interface methods come with semicolons instead of a pair of curly brackets.\n3. Create a class named **Online** that implements the interface you created earlier. In this class, declare two (2) private String variables named **email** and **password**.\n4. Add two (2) String parameters to the constructor of this class. Follow the names of your variables earlier.\n5. Insert the following statements into your constructor.\n```java\nthis.email = email;\n\nthis.password = password;\n```\n6. Use the **pay** method from the interface. Copy the code below.\n```java\npublic void pay (double amount) {\n\n  System.out.println(\"Paid using online account: \" + amount)\n```\n7. Add another class named **Mobile** that also implements the same interface. Declare two private variables named **number** (String) and **pin** (int).\n8. Add two (2) parameters to the constructor of this class. Follow the names and types of your variables in the previous step.\n9. Insert two (2) **this** statements into your constructor. Refer to the sample in Step 5.\n10. Use the **pay** method again but edit the display message. Refer to the sample in Step 6.\n11. Add a class named **Cart**. Declare a private **double** variable named **amount**.\n12. Add a **double** parameter to its constructor. Then, write a **this** statement similar to the sample in Step 6.\n13. Add a **pay** method. Copy the code below for its content.\n```java\npublic void pay(Payment mode) {\n\n  mode.pay(amount);\n\n}\n```\n14. Use the public class named **TestStrategy** to execute your Strategy pattern implementation. In its main method, instantiate a **Cart** object named **cart**. Copy the code below.\n```java\nCart cart = new Cart(1512.75);\n\ncart.pay(new Online(\"mark.reyes@gmail.com\", \"Wasd8456!\")); \n\ncart = new Cart(375.25);\n```\n15. Add a statement that uses the mobile payment mode. Refer to the second statement in the sample above.\n\n**Sample Output:**\n```java\nPaid using online account: 1512.75\n\nPaid using mobile wallet: 375.25 \n```\n\n🖥️ Midterm Task Performance for my 3rd-year college course \"Application Development and Emerging Technologies.\"\n\u003e SY2324-1T\n\n💻 Use NetBeans 🖱️\n\n💙 Instagram: [@izzyluuuuh](https://www.instagram.com/izzyluuuuh/)\n\n## Actual Output\n![preview img](https://github.com/izzyluuuuh/strategy-pattern/blob/main/teststrategy-output.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzyluuuuh%2Fstrategy-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzyluuuuh%2Fstrategy-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzyluuuuh%2Fstrategy-pattern/lists"}