{"id":27993981,"url":"https://github.com/ahmeddwalid/oop-project","last_synced_at":"2025-05-08T19:05:16.058Z","repository":{"id":216053253,"uuid":"739825905","full_name":"ahmeddwalid/OOP-project","owner":"ahmeddwalid","description":"Object Oriented Programming class third term project","archived":false,"fork":false,"pushed_at":"2024-01-08T18:58:10.000Z","size":1159,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T19:05:02.284Z","etag":null,"topics":["java","joptionpane","oop","oops-in-java","uml","uml-class-diagram","uml-diagram","uml-diagrams"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmeddwalid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-06T16:59:13.000Z","updated_at":"2025-01-20T20:22:33.000Z","dependencies_parsed_at":"2024-01-08T08:24:13.963Z","dependency_job_id":"7296a8ef-3b55-4da6-b401-5633c4576e82","html_url":"https://github.com/ahmeddwalid/OOP-project","commit_stats":null,"previous_names":["ahmeddwalid/oop-project"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOOP-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOOP-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOOP-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOOP-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmeddwalid","download_url":"https://codeload.github.com/ahmeddwalid/OOP-project/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253133127,"owners_count":21859111,"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":["java","joptionpane","oop","oops-in-java","uml","uml-class-diagram","uml-diagram","uml-diagrams"],"created_at":"2025-05-08T19:05:15.390Z","updated_at":"2025-05-08T19:05:16.023Z","avatar_url":"https://github.com/ahmeddwalid.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n\u003cdiv id=\"top\"\u003e\u003c/div\u003e\n\n  \u003ch2 align=\"center\"\u003eOOP Project\u003c/h2\u003e\n  \u003ch3 align=\"center\"\u003eAhmed Walid\u003c/h3\u003e\n  \u003ch3 align=\"center\"\u003eAhmed Mohamed\u003c/h3\u003e\n  \u003ch3 align=\"center\"\u003eAlsayed Aly\u003c/h3\u003e\n  \n  \u003cp align=\"center\"\u003e\n    Simple ordering system\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/ahmeddwalid/OOP-project/blob/main/README.md\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/ahmeddwalid/OOP-project/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/ahmeddwalid/OOP-project/pulls\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n   \u003c/li\u003e\n   \u003cli\u003e\u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#the-uml\"\u003eThe UML\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#the-java-code\"\u003eThe Code\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#the-runtime\"\u003eThe Runtime\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contact\"\u003eContact\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\n    \u003ca href=\"#acknowledgments\"\u003eAcknowledgments\u003c/a\u003e\n    \u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project\n\n\nIn this project a simple ordering system is implemented in which the user has a shopping menu displayed with the following:\n\n- Main menu:\n~~~\nPizza, $40\nCheeseburger, $20\nCoffee, $5\nSoda, $4\nWater, $2\n~~~\n- Takes input from the user that represents each item and its quantity.\n- Adds the items with their quantities to the user’s shopping cart.\n- On checkout, takes input from the user representing their payment method (PayPal or CreditCard).\n- Calculates and displays the amount of the order to the user and performs the payment using the method determined by the user and displays a confirmation message of the payment status (success or failure).\n\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!-- FEATURES --\u003e\n## Features\n\n- UML diagram\n- JOptionPane is used for the GUI to display and take inputs from the user\n- Added abstract classes\n- Added polymorphism\n- Added screenshots of the run \n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!--UML--\u003e\n# The UML\n\n![Unified Modeling Language](images/UML.png \"The UML\")\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!--CODE--\u003e\n# The Java code\n\n### MyClass.java\n~~~\npackage project;\n\nimport javax.swing.JOptionPane;\nimport java.util.Date;\n\npublic class MyClass {\n\n    public static void main(String[] args) {\n        String purchase;\n        PaymentMethod PaymentMethod;   // polymorphism \n        ShoppingCart cart = new ShoppingCart();\n        do {\n            String name = JOptionPane.showInputDialog(\"Please, select a product:\\n-   Pizza, $40 \\n-   Cheeseburger, $20\\n-   Coffee, $5\\n-   Soda, $4\\n-   Water, $2\\n\" + \"\\nEnter item’s name \");\n            double price = Double.parseDouble(JOptionPane.showInputDialog(\"Please, select a product:\\n-   Pizza, $40 \\n-   Cheeseburger, $20\\n-   Coffee, $5\\n-   Soda, $4\\n-   Water, $2\\n\" + \"\\nEnter item’s Price \"));\n            int quantity = Integer.parseInt(JOptionPane.showInputDialog(\"Please, select a product:\\n-   Pizza, $40 \\n-   Cheeseburger, $20\\n-   Coffee, $5\\n-   Soda, $4\\n-   Water, $2\\n\" + \"\\nEnter item’s Quantity \"));\n\n            Item item = new Item(name, quantity, price);\n            cart.add(item);\n            String discountInput = JOptionPane.showInputDialog(\"Do you have discount? (Y/N)\");\n            if (discountInput.equals(\"Y\") || discountInput.equals(\"y\")) {\n                int discountAmount = Integer.parseInt(JOptionPane.showInputDialog(\"Enter Discount Percentage\"));\n                item.setPrice(price, discountAmount);\n            }\n            purchase = JOptionPane.showInputDialog(\"Proceed to checkout (Y/N)\");\n        } while (purchase.equals(\"N\") || purchase.equals(\"n\"));\n        String choice = JOptionPane.showInputDialog(\"choose a payment method (PayPal or CreditCard)\");\n        if (choice.equals(\"Paypal\") || choice.equals(\"paypal\") || choice.equals(\"PayPal\")) {\n            String email = JOptionPane.showInputDialog(\"Enter Email \");\n            String Password = JOptionPane.showInputDialog(\"Enter Password \");\n            int balance = Integer.parseInt(JOptionPane.showInputDialog(\"Enter Balance\"));\n            PaymentMethod = new PayPal(email, Password);                //polymorphism\n            ((PayPal) PaymentMethod).setBalance(balance);\n            if (PaymentMethod.isValid()) {\n                JOptionPane.showMessageDialog(null, \"Valid\", \"PaymentMethod\", JOptionPane.INFORMATION_MESSAGE);\n            } else {\n                JOptionPane.showMessageDialog(null, \"InValid\", \"PaymentMethod\", JOptionPane.INFORMATION_MESSAGE);\n            }\n\n        } else {\n            String name = JOptionPane.showInputDialog(\"Enter cardName \");\n            String cardNumber = JOptionPane.showInputDialog(\"Enter cardNumber \");\n            int cvv = Integer.parseInt(JOptionPane.showInputDialog(\"Enter cvv\"));\n            int year = Integer.parseInt(JOptionPane.showInputDialog(\"Enter expiryDate (year)\"));\n            int month = Integer.parseInt(JOptionPane.showInputDialog(\"Enter expiryDate (month)\"));\n            int day = Integer.parseInt(JOptionPane.showInputDialog(\"Enter expiryDate (day)\"));\n            Date expiryDate = new Date(year - 1900, month - 1, day);\n\n            int Balance = Integer.parseInt(JOptionPane.showInputDialog(\"Enter Balance\"));\n\n            PaymentMethod = new CreditCard(name, cardNumber, cvv, expiryDate);\n            ((CreditCard) PaymentMethod).setBalance(Balance);\n            if (PaymentMethod.isValid()) {\n                JOptionPane.showMessageDialog(null, \"Valid\", \"PaymentMethod\", JOptionPane.INFORMATION_MESSAGE);\n            } else {\n                JOptionPane.showMessageDialog(null, \"InValid\", \"PaymentMethod\", JOptionPane.INFORMATION_MESSAGE);\n            }\n\n        }\n        JOptionPane.showMessageDialog(null, cart.checkout(PaymentMethod), \"CheckOut\", JOptionPane.INFORMATION_MESSAGE);\n\n        String display = JOptionPane.showInputDialog(\"DO you want to see what's in your cart? (Y/N)\");\n        if (display.equals(\"Y\") || display.equals(\"y\")) {\n            cart.display();\n        }\n\n    }\n\n}\n~~~\n\n### Item.java\n~~~\npackage project;\npublic class Item \n{\n    private String name;\n    private int quantity;\n    private double price;\n    public static int count = 0;\n    Item(String name,int quantity,double price)\n    {\n        this.name=name;\n        this.quantity=quantity;\n        this.price=price;\n                count++;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    public int getQuantity() {\n        return quantity;\n    }\n\n    public void setQuantity(int quantity) {\n        this.quantity = quantity;\n    }\n\n    public void setPrice(double price) {\n        this.price = price;\n    }\n   \n    public void setPrice(double price, int discountPercent) {\n        this.price = ((price * discountPercent) / 100);        // OverLoading\n    }\n     public double getPrice() {\n        return price;\n    }\n}\n~~~\n\n### PaymentMethod.java\n~~~\npackage project;\n\npublic interface PaymentMethod {\n\n    public boolean isValid();\n\n    public String pay(int amount);\n}\n~~~\n\n### PayPal.java\n~~~\npackage project;\n\nimport java.util.regex.*;\nimport javax.swing.JOptionPane;\n\npublic class PayPal implements PaymentMethod {\n\n    private String email, password;\n    private int balance;\n\n    PayPal(String email, String password) {\n        this.email = email;\n        this.password = password;\n        balance = 0;\n    }\n\n    public String getEmail() {\n        return email;\n    }\n\n    public void setEmail(String email) {\n        this.email = email;\n    }\n\n    public String getPassword() {\n        return password;\n    }\n\n    public void setPassword(String password) {\n        this.password = password;\n    }\n\n    public int getBalance() {\n        return balance;\n    }\n\n    public void setBalance(int balance) {\n        this.balance = balance;\n    }\n\n    @Override\n    public boolean isValid() {\n        //email\n        String emailRegex = \"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,6}$\";\n        Pattern emailPattern = Pattern.compile(emailRegex);\n        Matcher emailMatcher = emailPattern.matcher(email);\n\n        //password\n        String passwordRegex = \"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^\u0026+=])(?=\\\\S+$).{8,}$\";\n        Pattern passwordPattern = Pattern.compile(passwordRegex);\n        Matcher passwordMatcher = passwordPattern.matcher(password);\n\n        return (emailMatcher.matches() \u0026\u0026 passwordMatcher.matches());\n    }\n\n    @Override\n    public String pay(int amount) {\n        if (isValid() \u0026\u0026 amount \u003c= balance) {\n            balance -= amount;\n            return \"Successful Remaining balance = \" + balance;\n        } else {\n            return \"failed\";\n        }\n\n    }\n}\n~~~\n\n### CreditCard.java\n~~~\npackage project;\n\nimport java.util.Date;\n\npublic class CreditCard implements PaymentMethod {\n\n    private String cardName, cardNumber;\n    private int cvv, balance;\n    private Date expiryDate;\n\n    CreditCard(String cardName, String cardNumber, int cvv, Date expiryDate) {\n        balance = 0;\n        this.cvv = cvv;\n        this.cardName = cardName;\n        this.expiryDate = expiryDate;\n    }\n\n    public String getCardName() {\n        return cardName;\n    }\n\n    public void setCardName(String cardName) {\n        this.cardName = cardName;\n    }\n\n    public String getCardNumber() {\n        return cardNumber;\n    }\n\n    public void setCardNumber(String cardNumber) {\n        this.cardNumber = cardNumber;\n    }\n\n    public int getCvv() {\n        return cvv;\n    }\n\n    public void setCvv(int cvv) {\n        this.cvv = cvv;\n    }\n\n    public int getBalance() {\n        return balance;\n    }\n\n    public void setBalance(int balance) {\n        this.balance = balance;\n    }\n\n    public Date getExpiryDate() {\n        return expiryDate;\n    }\n\n    public void setExpiryDate(Date expiryDate) {\n        this.expiryDate = expiryDate;\n    }\n\n    @Override\n    public boolean isValid() {\n        Date CurrentDate = new Date();\n        return expiryDate.after(CurrentDate);\n    }\n\n    public String pay(int amount) {\n        if (isValid() \u0026\u0026 balance \u003e= amount) {\n\n            balance -= amount;\n\n            return \"Successful Remaining balance = \" + balance;\n        } else {\n            return \"failed\";\n        }\n    }\n}\n~~~\n\n### Display\n~~~\npackage project;\n\npublic abstract class Display {\n\n    public abstract void display();\n}\n~~~\n\n### ShoppingCart.java\n~~~\npackage project;\n\nimport javax.swing.JOptionPane;\nimport java.util.ArrayList;\n\npublic class ShoppingCart extends Display {\n\n    ArrayList\u003cItem\u003e orderItems;\n\n    public ShoppingCart() {\n        orderItems = new ArrayList\u003c\u003e();      // composition relationship\n    }\n\n    public void add(Item item) {\n        if (orderItems.size() \u003c 10) {\n            orderItems.add(item);\n        } else {\n            JOptionPane.showMessageDialog(null, \"Error\", \"Add Item\", JOptionPane.INFORMATION_MESSAGE);\n        }\n    }\n\n    public void remove(Item item) {\n        if (!orderItems.isEmpty() \u0026\u0026 orderItems.contains(item)) {\n            orderItems.remove(item);\n        } else {\n            JOptionPane.showMessageDialog(null, \"Error\", \"remove Item\", JOptionPane.INFORMATION_MESSAGE);\n        }\n\n    }\n\n    public double getTotalAmount() {\n        double total = 0;\n        for (int i = 0; i \u003c orderItems.size(); i++) {\n            total += (orderItems.get(i).getPrice()) * (orderItems.get(i).getQuantity());\n        }\n        return total;\n    }\n\n    public String checkout(PaymentMethod paymentMethod) {\n        JOptionPane.showMessageDialog(null, \"number of items in your Cart = \" + Item.count + \" And Your TotalAmount = \" + getTotalAmount(), \"Checkout\", JOptionPane.INFORMATION_MESSAGE);\n        return paymentMethod.pay((int) getTotalAmount());\n    }\n\n    @Override\n    public void display() // Override (Abstract class)\n    {\n        for (int i = 0; i \u003c orderItems.size(); i++) {\n\n            JOptionPane.showMessageDialog(null, \"item in index (\" + (i + 1) + \") :\\n\" + \"item’s name:\" + orderItems.get(i).getName() + \"\\n\" + \"item’s price :\" + orderItems.get(i).getPrice() + \"\\n\" + \"item’s Quantity :\" + orderItems.get(i).getQuantity(), \"Display\", JOptionPane.INFORMATION_MESSAGE);\n        }\n    }\n}\n~~~\n\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!--RUNTIME--\u003e\n# The Runtime\n#### *All test cases*\n\n![The main menu](images/mainmenu.png)\n![The menu](images/menu1.png)\n![The menu](images/menu2.png)\n![The menu](images/menu3.png)\n![The menu](images/menu4.png)\n![The menu](images/menu5.png)\n![The menu](images/menu6.png)\n![The menu](images/menu7.png)\n![The menu](images/menu8.png)\n![The menu](images/menu9.png)\n![The menu](images/menu10.png)\n![The menu](images/menu11.png)\n![The menu](images/menu12.png)\n![The menu](images/menu13.png)\n![The menu](images/menu14.png)\n![The menu](images/menu15.png)\n![The menu](images/menu16.png)\n![The menu](images/menu17.png)\n![The menu](images/menu18.png)\n![The menu](images/menu19.png)\n![The menu](images/menu20.png)\n![The menu](images/menu21.png)\n![The menu](images/menu22.png)\n![The menu](images/menu23.png)\n![The menu](images/menu24.png)\n![The menu](images/menu25.png)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!-- CONTRIBUTING --\u003e\n# Contributing\n\nAny contributions you make are **greatly appreciated**.\n\n\nProject Link: [https://github.com/ahmeddwalid/OOP-project](https://github.com/ahmeddwalid/OOP-project)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!-- LICENSE --\u003e\n# License\n\nThis project is distributed under the [MIT License](https://choosealicense.com/licenses/mit/). See\n[```LICENSE.txt```](/LICENSE) for more information.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!-- CONTACT --\u003e\n# Contact\n\nAhmed Walid\n- [Email](ahmedwalid.c3301@gmail.com)\n\nAhmed Mohamed\n- [Email](ahmedelgeen3@gmail.com)\n\nAlsayed Aly\n- [Email](sayedalymadany@gmail.com)\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!-- ACKNOWLEDGMENTS --\u003e\n# Acknowledgments\n\n* [Java Documentation](https://docs.oracle.com/en/java/)\n* Mohaned ElDeeb [get in touch](mohanedeldeeb27@gmail.com)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmeddwalid%2Foop-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmeddwalid%2Foop-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmeddwalid%2Foop-project/lists"}