diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Java.iml b/.idea/Java.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Java.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e9710cf --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..11e3c07 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Abstraction/README.md b/Abstraction/README.md new file mode 100644 index 0000000..9919894 --- /dev/null +++ b/Abstraction/README.md @@ -0,0 +1,35 @@ +## Abstraction + +- Hide certain details and show only what's necessary to the User +- Used through Abstract Classes/Interfaces +- Any class that inherits from an abstract class must implement all the abstract methods declared in the abstract class +- An abstract Class Cannot be instantiated + + +### Example + + +```java +public abstract class Animal{ + public abstract void animalSound(); + + public void sleep(){ + System.out.println("Zzz"); + } +} + +public class Dog extends Animal{ + public void animalSound(){ + System.out.println("Woofwoof"); + } +} + +public class Base{ + public static void main(String [] args) + { + Dog olivia = new Dog(); + olivia.animalSound(); + olivia.sleep(); + } +} +``` \ No newline at end of file diff --git a/Dynamic_Pro/Fib.class b/Dynamic_Pro/Fibonacci/Fib.class similarity index 100% rename from Dynamic_Pro/Fib.class rename to Dynamic_Pro/Fibonacci/Fib.class diff --git a/Dynamic_Pro/Fib.java b/Dynamic_Pro/Fibonacci/Fib.java similarity index 100% rename from Dynamic_Pro/Fib.java rename to Dynamic_Pro/Fibonacci/Fib.java diff --git a/Dynamic_Pro/README.md b/Dynamic_Pro/README.md index 423adf3..db9496e 100644 --- a/Dynamic_Pro/README.md +++ b/Dynamic_Pro/README.md @@ -1 +1,47 @@ ### Dynamic Programming + + + +#### Fibonacci Algorithm + +- A Tree like data structure +- Any computation I made within the tree that I plug into the formula ... +- I shouldn't have to compute again thanks to memoization it stores the value +- in an object and spits it out whenever there is a call to it +- I store the answer within the memo and caches that result +- My key is the nth number in the fibonacci sequence +- My value is the value i.e. output +- When making recursive calls, thanks to memoization, it outputs a stored value + - and doesn't have to travel through any further subtrees +- So memoizing my fib function ends up reducing the number of recursive calls I make + +##### Runtime Complexity + +- Memoizing my algo I see a linear functional call pattern +- i.e. I have n node and that's why the runtime complexity is O(n) +- where n is the top level call + +##### Space Time Complexity + +- O(n) + + +#### Grid Traveler + +- You want to travel +- You start at the top left corner and your goal is to end in the bottom right corner +- You can only go down or to the right +- You CANNOT move up or left or diagonally +- Find the # of different ways you can travel +- gridTravelTo(2,3) means how many different ways you can travel +- ...from the top left to bottom right in a 2x3(2 rows by 3 columns) + - 3 dif ways: + - right, right, down + - right,down, right, + - down, right, right +- gridTravelTo(1) means do nothing because you are already there +- gridTravelTo(0,1) means 0 rows and 1 column i.e. the grid is empty +- gridTravelTo(1,0) means 1 row and 0 columns i.e. the grid is empty +- gridTravelTo(8,0) means 8 rows and 0 columns i.e. the grid is empty +- gridTravelTo(0,0) means 0 rows and 0 columns i.e. the grid is empty +- base case: if one of your dimensions is empty then there is no grid diff --git a/Encapsulation/README.md b/Encapsulation/README.md new file mode 100644 index 0000000..0d55687 --- /dev/null +++ b/Encapsulation/README.md @@ -0,0 +1,83 @@ +### Encapsulation + +- One of the 4 pillars of OOP(A,E,I,P): +- I have 3 elements: + - Class + - Method + - Variables +- I wrap the variables and the code implementation which interacts with the methods as one +- Variables within my class cannot be accessed by other classes +- Only the methods of that particular class can access them +- All in all, it is the process by which I group information + + +#### Good Practice + +- Class Variables should always be declared private +- Setter and Getter Methods should be public + + +#### Example Encapsulating Class + +```java +public class EncapsulatingThis{ + + + + private String myFullName; + private String myIdentifNum; + private int myAge; + + + + public int getMyAge(){ + return myAge; + } + + public void setMyAge(int theAge){ + myAge = theAge; + } + + public String getMyId(){ + return myIdentifNum; + } + + public void setMyId(String myNewId){ + myIdentifNum = myNewId; + } + + + public String getMyName(){ + return myFullName; + } + + public void setMyName(String fullName){ + myFullName = fullName; + } + + //overriding the toString() method + @Override + public String toString() + { + return ("Hi my Name is: " + getMyName() + " and I am " + getMyAge() + " and my ID is: " + getMyId()); + } + +} +``` + + +#### Main Class + +```java +import java.util.*; +public class RunnerClass{ + public static void main(String [] args){ + EncapsulatingThis encapsObj = new EncapsulatingThis(); + encapsObj.setMyName("Omar"); + encapsObj.setMyAge(27); + encapsObj.setMyId("165X70B15D"); + + System.out.println(encapsObj.toString()); + } +} +``` \ No newline at end of file diff --git a/Interfaces/README.md b/Interfaces/README.md index 38bad94..b6e0cd5 100644 --- a/Interfaces/README.md +++ b/Interfaces/README.md @@ -1,8 +1,20 @@ -Interfaces are a little bit similar in concept to Inheritance. An interface defines behavior. So we have an object and right after it is a biiiig barrier, -this barrier is the interface. The barrier serves as to limit on how we interact with the object. We use an interface to work with an object. -When we program we tell the class that the object has to meet the requirements imposed by interface. Say I have a class Dog. The dog has the following behaviors -which are: walk(), woof(), eat(). We can define the behaviors thanks to interfaces. All in all, interfaces define behavior/characteristics that -classes need to implement. We can define how an animal eats/walks within the interface. Then the class can implement the interface. -A class does not extend an interface, it implements it. Whenever we work with multiple classes as a team of developer. We must believe that every developer will do -their part to implements the works of the interface of the designated class they are working on. Say for example, a class that implements the interface -walking well then we can trust that class that it can walk properly and not limp. An interface can extend interfaces but cannot extend/implement the class. +### Interfaces + +
+ +- Similar in concept to Inheritance. +- defines behavior. So we have an object and right after it is a biiiig barrier, this barrier is the interface +- The barrier serves as to limit on how we interact with the object. We use an interface to work with an object. + +- I tell the class that the object has to meet the requirements imposed by interface. Say I have a class Dog. The dog has the following behaviors which are: + - walk() + - woof() + - eat() +- We can define the behaviors thanks to interfaces. All in all, interfaces define behavior/characteristics that classes need to implement. +- We can define how an animal eats/walks within the interface. Then the class can implement the interface. + +- A class does not extend an interface, it implements it. Whenever we work with multiple classes as a team of developer. We must believe that every developer will do their part to implements the works of the interface of the designated class they are working on. + +- Say for example, a class that implements the interface walking well then we can trust that class that it can walk properly and not limp. + +- An interface can extend interfaces but cannot extend/implement the class. \ No newline at end of file diff --git a/Maps/README.md b/Maps/README.md index c9beb03..493c697 100644 --- a/Maps/README.md +++ b/Maps/README.md @@ -1,89 +1,134 @@ -### A map is an object that maps keys and values -### A map cannot contain the same keys -### A map is similar to a dictionary in Python and a Key-Value pair in JS -### Each key must be unique within a map -### Maps are very important to know when dealing with Abstraction in OOP -### Java has three types of maps: HashMap , TreeMap and and LinkedHashMap -### Ordering: - 1- HashMap:Key Order - 2- TreeMap: Key Order - 3- LinkedHasMap: Reverse Insertion Order FIFO - -### HashMap: - ``` - Key Order - ``` + +## Maps + +- A map is an object that maps keys and values + +- Cannot contain the same keys + +- similar to a dictionary in Python and a Key-Value pair in JS + +- Keys must be unique within a map + +- Maps are very important to know when dealing with Abstraction in OOP + +- Java has three types of maps: HashMap, TreeMap and LinkedHashMap + +
+ +### Ordering + +
+ +1. HashMap + +- Check if Empty: isEmpty() +- Remove a particular key: .remove() +- Does Not Maintain Insertion Order +- Holds A Value Depending on A Key +- Only Holds Unique Elements +- Lookup & Insertion: O(1) +- Only allowed to store 1 Null Key +- Allowed to store multiple null values + +2. TreeMap + +- Key Order +- Only Holds Unique Elements +- Lookup & Insertion: O(log(n)) +- Cannot Store Null as a key +- Allowed to store multiple null values +- Maintains Ascending Orders + +3. LinkedHasMap: + +- Only Holds Unique Elements +- Allowed to store only one null key +- Allowed to store multiple null values. +- Maintains Insertion Order +- FIFO + + + ```java + import java.util.*; -public class HashMap +public class HashMap { - public static void main(String args[]) - { - //HashMap Declaration - //HashMap
nameOfHashMap= new HashMap
(); - HashMap myHashMap=new HashMap();//Creating HashMap. - - myHashMap.put(2,"Papaya"); //Putting elements in Map. - myHashMap.put(3,"Mango"); - myHashMap.put(1,"Apple"); - myHashMap.put(4,"Lemon"); - - System.out.println(myHashMap); - } - - //Output: {1=Apple, 2=Papaya, 3=Mango, 4=Lemon} meaning Key Order + public static void main(String args[]) + { + //HashMap Declaration + //HashMap
nameOfHashMap= new HashMap
(); + + HashMap myHashMap=new HashMap();//Creating HashMap. + + myHashMap.put(2,"Papaya"); //Putting elements in Map. + + myHashMap.put(3,"Mango"); + + myHashMap.put(1,"Apple"); + + myHashMap.put(4,"Lemon"); + + System.out.println(myHashMap); + } + +//Output: {1=Apple, 2=Papaya, 3=Mango, 4=Lemon} meaning Key Order } + ``` + ### TreeMap + + ```java import java.util.*; -public class Main + +public class Main { - public static void main(String args[]) - { - //Tree Declaration - //TreeMap
nameOfTreeMap= new HashMap
(); - TreeMap myTreeMap=new TreeMap();//Creating HashMap. - - myTreeMap.put(2,"Papaya"); //Putting elements in Map. - myTreeMap.put(3,"Mango"); - myTreeMap.put(1,"Apple"); - myTreeMap.put(4,"Lemon"); - - System.out.println(myTreeMap); - } - - //Output: {1=Apple, 2=Papaya, 3=Mango, 4=Lemon} - //meaning Key Order + public static void main(String args[]) + { + //Tree Declaration + + //TreeMap
nameOfTreeMap= new HashMap
(); + + TreeMap myTreeMap=new TreeMap();//Creating HashMap. + + myTreeMap.put(2,"Papaya"); //Putting elements in Map. + + myTreeMap.put(3,"Mango"); + + myTreeMap.put(1,"Apple"); + + myTreeMap.put(4,"Lemon"); + + System.out.println(myTreeMap); } - - - - ``` -### LinkedHashMap - ``` - Ordered by Insertion FIFO - ``` - + +//Output: {1=Apple, 2=Papaya, 3=Mango, 4=Lemon} +//meaning Key Order +} +``` + ```java import java.util.*; -public class Main + +public class Main { - public static void main(String args[]) - { - //LHM Declaration - //LinkedHashMap
nameOfLinkedHashMap= new LinkedHashMap
(); - LinkedHashMap myLHashMap=new LinkedHashMap();//Creating Linked HashMap. - - myLHashMap.put("MW","Calculus3"); //Putting elements in Map. - myLHashMap.put("MWF","OrgCh1"); - myLHashMap.put("T","DS"); - myLHashMap.put("F","Music"); - - System.out.println(myLHashMap); - } - - //Output: {MW=Calculus3, MWF=OrgCh1, T=DS, F=Music} - //meaning Reverse Insertion Order FIFO + public static void main(String args[]) + { + //LHM Declaration + + //LinkedHashMap
nameOfLinkedHashMap= new LinkedHashMap
(); + + LinkedHashMap myLHashMap=newLinkedHashMap();//Creating Linked HashMap. + + myLHashMap.put("MW","Calculus3"); //Putting elements in Map. + myLHashMap.put("MWF","OrgCh1"); + myLHashMap.put("T","DS"); + myLHashMap.put("F","Music"); + + System.out.println(myLHashMap); + } + } - ``` +``` \ No newline at end of file diff --git a/Maven/README.md b/Maven/README.md new file mode 100644 index 0000000..ef521d9 --- /dev/null +++ b/Maven/README.md @@ -0,0 +1,308 @@ +## Maven + +- PM tool for JVM Languages + +- Used To Perform Major Tasks: + - Build Your Source Code + + - Testing Your Code + + - Packaging Your Code(JAR, WAR, EAR) + + - Generate Java docs + + - Dependency Management + + - Handling, Versioning Your Artifacts + +### How To Install + + - Head over to: https://maven.apache.org/download.cgi + - Download the Binary Zip Archive + - Extract It + +### 2- Create an environment variable in your system name it M2_HOME + + - This is where Other SW and libraries look for the Maven Installation + - Give it a path in the bin folder + +### Checking if the installation is successful + +```bash +mvn --version +``` + +### File Structure + +``` +├── /my-project-demo + ├── /.idea + ├── /src + ├── /main + ├── /java + └── /resources + ├── /test + └── /java + ├── /target + └── pom.xml +├── /External Libraries +└── /Scratches and Consoles +``` + +- All the static files go in our resources folder +- e.g. Property Files, or any file we need to read from(xml, csv,html, css, js) +- test file I store all my unit tests and integration tests +- pom.xml holds all the metadata of my Application i.e. project dependencies +- target folder holds all the java compiled class files + +### Creating A Project + + - Give it an artifact id(this is usually the name of your project) e.g. my-project-demo + - Give it group Id(this is usually the name of your company id in reverse order i.e. com.herokuapp.omarbelkady) + - Give it a version number e.g. 1.0-SNAPSHOT + + +### 3rd Party JAR files i.e. Dependencies + +- External Libraries are called "dependencies" +- Maven provides me with functionality on how to manage my dependencies +- ...thanks to the pom.xml file + +### Life Without Maven + +- I have to manually download the JAR files from the internet +- then I add them one by one + +### Dependency Section Thanks To Maven + +- Maven provides me with a dependency section where I can specify the info of the JAR I require in my project + - artifactid + - groupid + - version +- Maven will then automatically download these dependency specified, from the internet and load them into my project +- Load each dependency in a "dependency" tag +- And all your depenency tags should be in between 1 dependencies tag + +```xml + + + + + + + + + +``` + +- To add a dependency go to + +- Click on the Maven Icon to force IntelliJ to download the dependencies you have specified + +### Transitive Dependencies + +- Dependencies of my dependencies + +``` +├── /my-project-demo + ├── /.idea + ├── /src + ├── /main + ├── /java + └── /resources + ├── /test + └── /java + ├── /target + └── pom.xml +├── /External Libraries +└── /Scratches_and_Consoles +``` + +- All the static files go in our resources folder +- e.g. Property Files, or any file we need to read from(xml, csv,html, css, js) +- test file I store all my unit tests and integration tests +- pom.xml holds all the metadata of my Application i.e. project dependencies +- target folder holds all the java compiled class files + +### Maven Dependency + +- Can be categorized into two categories: + - Snapshot Dependency + - This dependency was created when the software was in active development + - Unstable + - Release Dependency: + - This dependency was created after the software was developed and is ready to be released i.e. ready to be deployed for production + - Stable + +- In all, when I am developing the software I use the snapshot versions for the dependencies. When the software is released, I use the release versions + +--- + +### Dependency Scopes + +- enables me to control the visibility of a Maven depenendency +- 5 types: + +1. **Compile**: made available at compile time within classpath [default scope] + +2. **Provided**: dependency provided at runtime by JDK or webserver, e.g. Servlet API dependency. The web server which is running my project provides me with the java servlet-api during runtime. This means that the dependency will be available in the class path of the project but will not be packaged in the JAR file nor the WAR file + +3. **Runtime**: dependency provided ONLY at runtime and NOT at compile time e.g. MySQL JDBC connector dependency. I mark the dependency as runtime to make sure I do not use the MySQL JDBC classes in my code instead of standard jdbc api + +4. **Tests**: dependency only available at the time of writing and running my unit tests e.g. junit, spring-boot-starter-test + +5. **System**: the path to the JAR should be specified manually using the < systemPath > tag. The only restriction is that I must specify the exact path of where to locate this dependency within my system. + +### Repositories + +- a special directory called a **repository** is the location where Maven stores my dependencies +- Local Repository[directory/folder in your machine] +- Remote Repository[Maven Website] where I can download the Maven dependencies +- If a dependency I specified in my pom is not in my local repository it goes ahead and connects to the remote repository and downloads the remote repository and stores the dependency within my local repository + +#### How To Define A Repository within my POM always after my closing dependency tag + +```xml + + + my-internal-website + https://myserver/repo + + +``` + +### Build Lifecycle Within Maven + +- How Does Maven Build Our Projects? + 1. default + 2. clean + 3. site + +#### Default Lifecycle Build Step Phases + +1. validate + - Makes sure pom.xml is validated or not validated +2. compile + - Compiles my source code +3. test + - Runs the unit tests in my project +4. package + - Packages the source code into an artifact +5. integration-test + - Executes the integration tests +6. verify + - Verifies the results of the integrations tests +7. install + - Installs the newly created package files(JAR or any other artifact) within my local repository + - Maven +8. deploy + - Deploy the newly created package to the remote repository + - If the newly created package is configured in the pom.xml file it will deploy the new package into the remote repository + +### Command + +```java +mvn clean install +``` + +- This command compiles the source code +- Runs the unit tests +- Creates the JAR file +- Install the JAR file into your local repository + +### Site Step + +- generate Java documentation that is present in my project + +### Plugins and Goals + +- To be able to execute the different lifecyle phases, Maven provides me with different plugins in order for me to perform each task in the lifecycle +- Every plugin has a relationship to a goal which is linked to the lifecycle phase(e.g. compile) +- To declare a plugin simple place in between a **plugin** tag that is within the **plugins** tag +- Any plugin I want to define must be within the build tag +- The build tag will usually be right below the dependencies section + +```xml + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + +``` + +- The plugin above is in charge of compiling any test files or source files I have within my project. This is familiar to running + +```java +javac nameofclass.java +``` + +#### To trigger the compile lifecycle phase + +```java +mvn compiler:compile +``` + +### Maven tab⇒ Plugin section ⇒ Hit Expand ⇒ Click on Compile Goal + +- Compilation fails +- Java compiler of Maven within IntelliJ is configured to Java version 1.X +- To fix: +      0. Go to your pom.xml +      1. Head to build section +      2. Plugins ⇒ plugin +      3. Configuration Tag +      4. Change the source & target properties to the java version installed on your machine + +### Maven Install Plugin + +- This plugin is used to run the install lifecycle phase within the maven build lifecycle + +1. Compiles My Source Code +2. Runs Our Unit Tests +3. Package The Cource Code into an Artifact +4. Installs The Artifact Within My Local Repository + + +### Maven Deploy Plugin + +- Self-explanatory plugin +- runs all the phases which are part of the install phase +- deploys the created artifact to the remote repository + +0. To deploy the artifact to the remote repo you have to specify the remote repo details within your pom +1. Create a tag right above your dependencies tag and give it a name of **distributionManagement** +2. Within the distributionManagement tag create a tag named **repository** and place the information of your repository there +3. To uniquely identify a repository I specify the **id**, **name** and **url** +4. Run the command below to deploy your plugin + +```java +mvn clean deploy +``` + +### Maven Profiles + +- Profiles can be used within maven to create customized build configurations within my project +- I can customize the behavior of a build based upon specific conditions +- e.g. I can skip the test execution due to the fact that my build process may take a long time +- I create a profile that will skip the test execution phase + +#### How To Create + +- Right below your build tag create a **profiles** tag + +- Within your profiles tag create a **profile** tag I give it an: + - *id* + - *properties* + +- After creating a profile for the above example Maven will make sure to skip the test execution + +- I head over to the terminal and run the following command: +- -P flag indicates the id of the profile + +```java +mvn -Pskip-tests clean install +``` diff --git a/MustKnow/AlgoTypes/README.md b/MustKnow/AlgoTypes/README.md new file mode 100644 index 0000000..b2bc520 --- /dev/null +++ b/MustKnow/AlgoTypes/README.md @@ -0,0 +1,33 @@ +## Types of Algorithms + +- Backtracking Algorithm + - recursive problem solving approach + - I come up with N number of solution + - If the first solution does not solve my problem I go back + - I try the second solution and so forth + - I remove the first solution + - Playing soduku you find 4 is in the row, column and box therefore you backtrack and check 5 + - Trying to find your way out in a maze + +- Brute Force Algorithm + - Check every possible solution for the problem to be solved + +- Divide And Conquer Algorithm + - Divide the problem into sub-problems and solve each sub-problem independently + - i.e. Binary Search + +- Dynamic Programming Algorithm + - function X generates the output Y + - I store the result of Y and use it in function D + +- Greedy Algorithm + - Always chooses the best solution + - Solution is built piece by piece + - The subsequent piece chosen by the algorithm is usually the most obvious + - Examples in Various DS: + +- Recursive Algorithm + - an algorithm which calls itself + - i.e. factorial + + diff --git a/MustKnow/Array Algo/README.md b/MustKnow/Array Algo/README.md new file mode 100644 index 0000000..fba5e6e --- /dev/null +++ b/MustKnow/Array Algo/README.md @@ -0,0 +1,88 @@ +### Array Algorithms + + +#### Floyd's Cycle Detection Algorithm +```java +class ListNode { + int val; + ListNode next; + + ListNode(int val) { + this.val = val; + this.next = null; + } +} + + public class FloydCycleDetection { + public static boolean hasCycle(ListNode head) { + if (head == null || head.next == null) { + return false; // No cycle if head is null or only one node exists + } + + ListNode slow = head; // Slow pointer moves one step at a time + ListNode fast = head; // Fast pointer moves two steps at a time + + while (fast != null && fast.next != null) { + slow = slow.next; // Move slow pointer one step + fast = fast.next.next; // Move fast pointer two steps + + if (slow == fast) { + return true; // Cycle detected if slow and fast pointers meet + } + } + + return false; // No cycle found + } + + public static void main(String[] args) { + // Create a linked list with a cycle + ListNode head = new ListNode(1); + ListNode node2 = new ListNode(2); + ListNode node3 = new ListNode(3); + ListNode node4 = new ListNode(4); + ListNode node5 = new ListNode(5); + + head.next = node2; + node2.next = node3; + node3.next = node4; + node4.next = node5; + node5.next = node2; // Cycle: node5 points back to node2 + + System.out.println("Does the linked list have a cycle? " + hasCycle(head)); + } + } +``` + +#### Kadane's Algorithm + +```java +public class KadanesAlgorithm { + public static int maxSubArraySum(int[] nums) { + int maxSum = nums[0]; // Initialize maxSum with the first element of the array + int currentSum = nums[0]; // Initialize currentSum with the first element of the array + + for (int i = 1; i < nums.length; i++) { + /** + Calc the currentSum for the current element by taking + the maximum of the current element itself or the sum + of the current element and the previous subarray sum + **/ + currentSum = Math.max(nums[i], currentSum + nums[i]); + + /**Update the maxSum with the maximum of the currentSum and the previous maxSum + * + * + **/ + maxSum = Math.max(maxSum, currentSum); + } + + return maxSum; // Return the maximum subarray sum + } + + public static void main(String[] args) { + int[] nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; + int maxSum = maxSubArraySum(nums); + System.out.println("Maximum subarray sum: " + maxSum); + } +} +``` \ No newline at end of file diff --git a/MustKnow/Design Pat/README.md b/MustKnow/Design Pat/README.md new file mode 100644 index 0000000..d570b02 --- /dev/null +++ b/MustKnow/Design Pat/README.md @@ -0,0 +1,8 @@ +### Design Patterns + + +#### Adapter Design Pattern +- Convert An Interface of A Class into Another Interface that clients expect +- Enables us to make incompatible classes work with one another +- i.e. delegate logic to the Adapter +- ![example](https://www.baeldung.com/wp-content/uploads/2019/02/Adapter.png) \ No newline at end of file diff --git a/MustKnow/GCDeuclid/README.md b/MustKnow/GCDeuclid/README.md new file mode 100644 index 0000000..1f940c5 --- /dev/null +++ b/MustKnow/GCDeuclid/README.md @@ -0,0 +1,25 @@ +```java +public class GCDeuclid{ + public static void logLn(Object o){ + System.out.println(o); + } + + public static void main(String [] args){ + logLn(euclidgcd(1800,54)); + } + + public static int euclidgcd(int divid, int divis){ + //2526 56837 35 + /* + * if divisor i.e. divis completely divid i.e. dividend + * remain=0 i.e. therefore divis is the gcd + * */ + int remain = divid%divis; + if(remain==0){ + return divis; + } + + return euclidgcd(divis,remain); + } +} +``` \ No newline at end of file diff --git a/MustKnow/Graphs/README.md b/MustKnow/Graphs/README.md new file mode 100644 index 0000000..21f602f --- /dev/null +++ b/MustKnow/Graphs/README.md @@ -0,0 +1,35 @@ +### Graphs Implementation + + +
+ +##### DFS +```java +import java.util.*; +class Main{ + public final int depthfirsts(int node, int result){ + /*PRE ORDER + * + * result.push(node,value); + * */ + + if(node.left) { + depthfirsts(node.left, result); + } + + + result.push(node,value); + + + if(node.right){ + depthfirsts(node.right); + } + + /*POST ORDER + * + * result.push(node,value); + * */ + return result; + } +} +``` \ No newline at end of file diff --git a/MustKnow/Main.java b/MustKnow/Main.java deleted file mode 100644 index 8b15607..0000000 --- a/MustKnow/Main.java +++ /dev/null @@ -1,30 +0,0 @@ -public class Main{ - - public void logLn(Object o){ - System.out.println(o); - } - - public void log(Object o){ - System.out.print(o); - } - - public void printArr(int [] arr){ - logLn(arr[0]); //has one operation and takes constant time to run ===> O(1) - logLn(arr[0]); //has two operation but still O(1) - } - - /* - small small will run fast but as the sample size increase e.g. 1,000,000 items then you will have it running slowly - - cost of algo: linear and is directly proportional to the size of the input therefore the runtime complexity O(n) - */ - public void logging(int [] nums){ - for(int i=0; i Docker; + Docker -- CI/CD Tools --> Gitlab; + Gitlab -- VCS --> GitHub/BitBucket; + GitHub/BitBucket -- Frameworks --> Express/Flask/Laravel/RubyOnRails; + Express/Flask/Laravel/RubyOnRails -- Prog_Lang --> Java/Python/Ruby/C#/NodeJS/Rust/PHP; + Java/Python/Ruby/C#/NodeJS/Rust/PHP -- Archi Pattern --> Microservices/Monolithic/Serverless/SOA; + Microservices/Monolithic/Serverless/SOA -- APIs --> REST/JSON/SOAP; + REST/JSON/SOAP -- Caching--> Client/Server/CDN; + Client/Server/CDN -- Testing --> + Integration/Unit/Functional; + Integration/Unit/Functional -- Database -- SQL --> MYSQL/Postgres; + Integration/Unit/Functional -- Database -- NoSQL --> MongoDB; + MongoDB --> START/FINISH + MYSQL/Postgres --> START/FINISH + +``` + + +##### Things You Must Know To Understand Java +- Abstract +- Arrays And ArrayList +- Collections +- Conditionals +- Default +- Enum +- Exception Handling +- Final Keyword +- Generics +- Interfaces +- Loops +- Maps +- OOP(Abstraction, Encapsulation, Inheritance, Polymorphism) +- Passing By Value Vs. Passing By Reference +- Reference Types Vs Primitive Types +- Sets +- Static +- ToString & Equals & Hashcode + +
+ +##### ★★★★Operations You Can Perform On A Data Structure★★★★ - Delete: Remove an item from the data structure @@ -34,6 +83,8 @@ - Used in the Average Case + + ##### DS Operations - Traverse: Visiting each item in the DS once AND ONLY ONCE @@ -45,14 +96,30 @@ -1. Stack +1. **Stack** - Linear - LIFO/FILO - Dinner Plates - When items are pushed they are placed on the top +- Only can push/pop an element from this DS at one end only +- Requires You To Have One Reference Pointer i.e. "TOP" +- Applications: + - Redoing/Undoing stuff within your application + - Memory Management +- Allows you to fully control how memory is allocated and deallocated +- Pitfalls of Stack: + - Cannot access a random element + - Not able to be scaled i.e. not flexible -2. Linked List +```java +import java.util.*; + +Stack myStack= new Stack(); +``` + + +2. **Linked List** - Sequential Order - No Random Access @@ -62,26 +129,114 @@ - A Node is composed of data and a pointer - Last node has a null pointer i.e. the pointer is used but doesn't point to anything - Folders on your computer(i.e. last folder is null because it has no folder within it) +- Node[0] = Head +- Node[n-1] = Tail + + +```java +import java.util.*; +/* +How To Declare: +LinkedListnameOfLL = new LinkedList() */ +LinkedList mylist=new LinkedList(); +``` -3. Array +3. **Array** - Indexed - When Size increases performance decreases - All the elements in the DS must be of the same type - Muffin/Egg Tray - Rectangular in shape +- Good For Storing Multiple items in it +- Address in Memory increases by the size of the datatype you store +- I.e. say I have 6 ints location in memory of the first is 104 second is 108 third is 112 +- because an int = 4 bytes that's why you increment by 4 +- Searching an Array by index is super fast, supply to an idx to the array and it will be super fast to locate it +- Calc of Mem Address Runtime is: O(1) +- Downsides: Static, failure to know size if too large: waste memory too small: array gets filled quickly +- And If I fill it up quickly I must create a 2nd array and copy the elements of the first array into the second + +- Cost of Lookup: O(1) +- Cost of Insertion: O(n) +- Cost Of Removal: O(n) + +1. Best Case: I remove from the end of the array and I delete that index +2. Worst Case: I remove from the beginning of the array and shift all the items in the right one index less to fill +3. Therefore, for the worst case it is O(n) when removing an item in the array + + +- Dynamic Array DS in Java: ArrayList +- Grows by 50% of its size everytime I add sth to it +- synchronous aka one 7652626 thread at a time + +#### Declaring an array in Java +```java +import java.util.*; +public class Arr{ + public static void main(String [] args){ + /* + 1. declare the data type of the array + 2. indicate that I want an array data structure by using the brackets.. MUST BE EMPtY + 3. give it a name + 4. use the new operator to allocate memory for the array + 5. repeat the data type of the array + 6. indicate the size of the array + + */ + int [] myArr = new int[7]; + //this output the memory location of the array + //System.out.println(myArr); + + /* + if you know the vals: + + */ + int [] myArrTw = {7, 6, 5, 2, 6, 2, 6} + + //proper way to output + System.out.println(Arrays.toString(myArr)) + } +} +``` -4. Queues +4. **Vector** : Grows by 100% of its size everytime I add sth to it... asynchronous aka multiple threads at a time -- Movie Theatre + +5. **Queues** + +- People waiting in line in the Movie Theatre +- Linear - FIFO -- aka people waiting in line +- Has Side A and Side B +- Pushes On Side A i.e. Enqueue +- Pops On Side B i.e. Dequeue - Ordered Collection - Operations: add(), remove() - +- Part of the java.util.* package +- Part of the collection Interface +- Two Classes Implement the Queue Interface: + - Linked List + - Priority Queue +- Supports all the methods in the Collection Interface +- Element & Remove Method Throws NoSuchElementException if the queue is empty +- Poll Method removes the head of the queue and returns it + - if the queue is empty the poll method call returns null +- Requires You To Have Two Reference Pointers i.e. "FRONT" & "REAR" + +```java +//How To Declare a Priority Queue of type String +import java.util.*; + +public class queueimpl{ + public static void main(String [] args){ + Queue mypq = new PriorityQueue<>(); + } +} +``` -5. Hash Table +6. **Hash Table** - Contains an index and its corresponding Hash_Value @@ -89,17 +244,52 @@ - Cannot store null as a key nor as a value - First parameter within your Hash Table declaration is the data type of the key - Second parameter within your Hash Table declaration is the data type of the value +- Restaurant Pager i.e. you give your name and they assign a number to you when a seat frees up you get an empty table + +```java +/* +How To Declare a Hash Table of type: +- Integer for the key +- String for the value +*/ + +import java.util.*; + +public class HashTable{ + public static void main(String [] args){ + Integer mystr; + Hashtable myhashtable = new Hashtable(); + myhashtable.put(1,"Blue"); + myhashtable.put(2,"Red"); + myhashtable.put(3,"Yellow"); -6. Trees + //Storage of the keys in the HashTable Set + Set keys = myhashtable.keySet(); + + Iterator itr = keys.iterator(); + + + while (itr.hasNext()) { + // Getting Key + mystr = itr.next(); + System.out.println("Key: "+mystr+"\nValue: "+myhashtable.get(mystr)); + } + } +} + +``` + +7.**Trees** - Hierarchical Structure where data is org in a hierarchy and everything is linked together - Not the same as linked list because LL is linear +- Log(n) runtime complexity where n is the number of levels - Trees are faster to access than a LL because they are non-linear - Node: person who holds our data - Child Node: person who has a parent -- Leaf Node: person who has no children +- Leaf: person who has no children - Edge: person who connects two nodes -- Root: Person who is the topmost node +- Root: person who is the topmost node - Node Height: # of edges from the node to the deepest leaf node - Node Depth: # of edges from the root to the node - Tree Height: Depth of the deepest node @@ -107,74 +297,340 @@ - Leaves: Person who has no children - Use when you want to store items in a hierarchial fashion - Quicker to access/search than a LL but slower than an Array - - Binary Tree + - AVL Tree: + - Self-balanced trees + - Searching, Inserting, Deleting in the worst case is logarithmic time complexity + - Balance factor is determined by the height of the right subtree tree + - ... minus the height of the left subtree + - I have a height of 1 in the left subtree ... I have a height of 1 in the right subtree + - balance factor = 0 + - Objective: make sure every node is balanced i.e. bf = -1,0,1 + - all nodes must be balanced ... if one node is not balanced the whole tree is unbalanced + - balance factor in relation to its neighboring subtree + - -1 means the right subtree is greater than the left subtree + - 1 means the left subtree is greater than the right subtree + - 0 means the left subtree and right subtree have equal lengths + - LL rotation means I inserted a node in the left subtree of the left subtree of A + - LR rotation means I inserted a node in the right subtree of the left subtree of A + - RR rotation means I inserted a node in the right subtree of the right subtree of A + - RL rotation means I inserted a node in the left subtree of the right subtree of A + - Binary Tree - Can Have 0,1,2 nodes + - right child is always larger & left child is always smaller - Binary Search Tree: - Used for sorting, getting and searching data - Non-linear - Arranged in some order - no duplicate vals - val on the left most subtree of the node is always smaller than the val on its immediate right + - B-tree + - every b-tree has an order i.e. the number of levels + - Root node must have a minimum of two children + - A leaf in a b-tree the i.e. the parent to the last level in a b-tree(i.e. child nodes) + - ...must always have more nodes than the child so as the keys(1 key... 2 child nodes, 2 keys, 3 child nodes) + - the keys cannot be larger than the leaf nodes + - All leaf nodes must be at the same level + - whenever you delete a leaf node all you have to do is do a rotation to the values + - if you delete a middle value you must do rebalancing + - whenever one of the rules is violated, I have to rebalance and restructure my tree + - ... by shifting the center value + - once you access one element in the block you have access to all the elements in the block + - B*-tree + - Values in the middle are not essentially referred to as value + - they are just navigation values(go left, go down, go right) + - the parent is always the largest value of its left child subtree + - the number of values I am allowed to store at the leaf level is determined by a parameter k* + - so if k* = 2 that means I am allowed to have a max of 2k* elements at the leaf level + - ...and a minimum of 2 + - m is the order of the tree i.e. the number of the levels + - B* trees have a smaller height than Btrees because all the data is stored in the leaf level - Node on the left is always less than the node on the right +- Linux File Structure +- Classification Tree in Biology + +- Runtime of Operations Performed on A Balanced Tree + +| Operation | Runtime | +| ----------- | ----------- | +| Inserting | log(n) | +| Deleting | log(n) | +| Rebalancing | log(n) | +| Searching | log(n) | +#### 4 Cases of AVL Trees of Balance Factors + +- We will never have to make more rotations than the number of levels +- Number of level is log2(n) + +##### Case A +``` + A(-2) + / \ + B(-1) C(0) height of 3 vs height of 1 + / \ ∴ BF=-2 + D(-1) E(0) + / +F(0) +``` + +- Balance Factor of: -2 +- The left most subtree has a height that is 2 levels greater than the right subtree +- Perform a single right rotation + +``` + B(0) + / \ + D(0) A(0) + / / \ + F(0) E(0) C(0) + +``` +
+
+ + +##### Case B +``` + A(-2) + / \ + B(1) C(0) + / \ +D(0) E(1) + \ + F(0) +``` +
+
+ +- Perform a single left rotation on the subtree +- Make E the root node of the left subtree +- Make B the left child node of E +- Make F the right child node of E +``` + A(-2) + / \ + E C(0) + / \ + B F + / + D +``` + + + + +##### Case C + +``` + A(-2) + / \ + B(1) C(0) + / \ + D(0) E(1) + \ + F(0) +``` + +- Perform a single left rotation +- Make A the root node of the left subtree +- Make E the root node of the right subtree +- Make F the child node of E +- Make B the left child node of A +- Make D the right child node of A + +``` + C(0) + / \ + A(0) E(1) + / \ \ +B(0) D(0) F(0) + +``` + + + + +##### Case D + +``` + A + / \ + B C + / \ + D E + / + F +``` + +1. Perform a single right rotation now we are in Case C +2. That means To Solve Case D I perform a double right-left rotation + +``` + A + / \ + B D + / \ + F C + \ + E +``` + + + + + -7. Heap +8. **Heap** - Special Tree Based DS - Binary Tree -- Patients Being Admitted to the Hospital - - Patients with life-threatning situation get taken care of first - - Patients that don't have threatening situation wait in line - Parent node makes a comparison with its child nodes and are arranged accordingly - Two Scenarios: - Key present at the root node is the greatest among all of its children and successors - Key present at the root node is the smallest among all of its children and successors +- Patients Being Admitted to the Hospital + - Patients with life-threatning situation get taken care of first + - Patients that don't have threatening situation wait in line -8. Graphs + +9. **Graphs** - Finite set of vertices, nodes and edges. The edges are what connect one vertex with another - Graphs are connected in a network form +- Vertex: Circle +- Edge: Arrow - Non-linear - Nodes are the vertices(i.e. endpoints) - Edges are the lines/arcs that connect one node with another node -- Two Types: - - Directed - - Undirected +- Types: + - **Directed**: no particular direction and two-way relation + - e.g. Friends on Facebook + - **Undirected**: Particular Direction and one-way relation + - e.g. who you're following on Twitter + - **Unweighted**: Every edge has no particular weight + - **Weighted**: Each edge has a respective value this is referred to as weight + - e.g. distance between cities +- **Note** A (directed/undirected )graph is independent of being weighted or not +- We can have: + - Direct Weighted Graphs + - Direct Unweighted Graphs + - Undirected Weighted Graphs + - Undirected Unweighted Graphs +## Important Algorithms +- Graph Algorithms: + - BFS + - DFS + - Dijkstra(Shortest Path) - Simple Graph: Each edge connects to two different vertices whereby no two edges connect to the same group of vertices -- Multigraph: An edge can connect to the same pair of vertices -- +- Multi-graph: An edge can connect to the same pair of vertices +- Google Maps Usage of Connecting Roads i.e. vertex therefore, I use an algo to determine the shortest path between vertex A & B -9. Queues +```java +//basic example -- FIFO DS -- Linear -- Pushes To The End -- Pops From The Front -- Part of the java.util.* package -- Part of the collection Interface -- Two Classes Implement the Queue Interface: - - Linked List - - Priority Queue -- Supports all the methods in the Collection Interface -- Element & Remove Method Throws NoSuchElementException if the queue is empty -- Poll Method removes the head of the queue and returns it - - if the queue is empty the poll method call returns null +import java.util.*; +class Graph { + private int V; // Number of vertices + private LinkedList[] adjList; // Array of adjacency lists + + // Constructor + public Graph(int V) { + this.V = V; + adjList = new LinkedList[V]; + + for (int i = 0; i < V; i++) { + adjList[i] = new LinkedList(); + } + } + + // Add an edge to the graph + public void addEdge(int src, int dest) { + adjList[src].add(dest); + adjList[dest].add(src); // Uncomment this line for undirected graph + } + + // Print the graph + public void printGraph() { + for (int i = 0; i < V; i++) { + System.out.print("Vertex " + i + " is connected to: "); + for (int neighbor : adjList[i]) { + System.out.print(neighbor + " "); + } + System.out.println(); + } + } +} -1. When the sample size increases of an Array what should you do? +public class Main { + public static void main(String[] args) { + // Create a graph with 5 vertices + Graph graph = new Graph(5); + + // Add edges + graph.addEdge(0, 1); + graph.addEdge(0, 4); + graph.addEdge(1, 2); + graph.addEdge(1, 3); + graph.addEdge(1, 4); + graph.addEdge(2, 3); + graph.addEdge(3, 4); + + // Print the graph + graph.printGraph(); + } +} + +``` + + +### Sorting +- Bubble Sort +- Bucket/Insertion Sort + - Runtime: O(n^2) ... ie terrible + - useful when paired with other more complex sorting algo + - i.e. Quicksort, Merge Sort + - good for ordering a small sample size + - Step 1: iterate from the 2nd array to the nth array over the array + - Step 2: compare the element which you are at with its parent/predecessor + - Step 3: if the key is less than its predecessor compare it to the preceding elements + - Step 4: Move the greater element up one spot to give space for the modified element +- Counting Sort +- Heap Sort +- Merge Sort +- Quick Sort +- Selection Sort + + + +
+ +## Search Algorithms + +1. Breath First Search[Graphs] +2. Depth First Search[Graphs] +3. Binary Search[Linear] +4. Linear Search + +**Other** +- Recursive Algorithms +- Hashing Algorithms +- Randomized Algorithms -- Use A Linked List DS because it increases performance and isn't slow as the sample size increases + + +1. When the sample size increases of an Array what should you do? + - Use A Linked List DS because it increases performance and isn't slow as the sample size increases 2. For Loop Runtime: O(n) where n is the size of the input 3. Function with 1 operation: O(1) 4. Say I have a print statement before a for loop and after what's the runtime: - -- Print statement: O(1) -- For Loop: O(n) -- Print statement: O(1) + - Print statement: O(1) + - For Loop: O(n) + - Print statement: O(1) Total: O(1+n+1)= O(n+2) @@ -213,6 +669,78 @@ But actually the runtime is O(n) because when we calculate runtime we drop the c - In the worst case scenario, if the number I am looking for is at the end of the array then I have to inspect one index at a time - The more items I have the longer the operation will take +```java +import java.util.*; + +public class LinSearch{ + + public static void main(String [] args){ + int [] myArr = {18, 34, 65, 92, 32, 94, 15, 10, 16, 8, 26}; + int elem,elemExistsTimes=0; + Scanner sc = new Scanner(System.in); + System.out.println("Enter The Element You Are Hunting For: "); + elem = sc.nextInt(); + + for(int x = 0; x<10; x++){ + if(myArr[x] == elem){ + elemExistsTimes= x + 1; + break; + } + + else{ + elemExistsTimes = 0; + } + } + + if(elemExistsTimes != 0) + { + System.out.println("I found the item at location: "+elemExistsTimes); + } + + else{ + System.out.println("Not Found Man"); + } + + } + +} +``` + +```java +public class Main{ + + public void logLn(Object o){ + System.out.println(o); + } + + public void log(Object o){ + System.out.print(o); + } + + public void printArr(int [] arr){ + logLn(arr[0]); //has one operation and takes constant time to run ===> O(1) + logLn(arr[0]); //has two operation but still O(1) + } + + /* + small small will run fast but as the sample size increase e.g. 1,000,000 items then you will have it running slowly + + cost of algo: linear and is directly proportional to the size of the input therefore the runtime complexity O(n) + */ + public void logging(int [] nums){ + for(int i=0; i; -//where E is the generic key type -//Integer keyword is the wrapper class around the native/primitive type int -``` -2. Vector: Grows by 100% of its size everytime I add sth to it... asynchronous aka multiple threads at a time - - -### LinkedList - -- We use a LL when wanting to store an object in sequential||7652626 order -- LinkedList are better than arrays because they can grow/shrink auto -- It consists of a group of nodes in seq order. Every node has two pieces of data: - 1. value - 2. address of the next node in the list -- AKA every node (points to)/references the next node in the list -- Node[0] = Head -- Node[n-1] = Tail - -#### Searching A LL value Time C - -- O(n) because the val we are searching for maybe stored in the last node aka n that is worst case. +/* + + 1. Compare the first two elements if the first is + bigger than the second swap + + 2. compare the rest and if the second is less than + the first move the second to the left of the first + + */ + + +public class BubbleSort{ + + public static void bubbleSort(int [] arr){ + int arrsize = arr.length; + for(int s=0;sarr[t+1]){ + int temporary = arr[t]; + arr[t]=arr[t+1]; + arr[t+1]= temporary; + } + } + } + } + public static void main(String [] args){ + int myarr[] ={3,60,35,2,45,320,5}; + System.out.println("Before Bubble Sort"); + for(int x=0; x -- O(n) because the val we are searching for maybe stored in the last node aka n that is worst case. #### Insertion Sort Implementation @@ -378,6 +887,182 @@ Space C: O(1) because I am adding a var */ ``` +
+ +#### Merge Sort Implementation + +```java +public class MergeSort +{ + // Merges two subarrays of arr[]. + // First subarray is arr[left half..middle index] + // Second subarray is arr[middle+1..right half] + void merge(int arr[], int l, int m, int r) + { + // Find sizes of two subarrays to be merged + int n1 = m - l + 1; + int n2 = r - m; + + /* Creating two temporary arrays */ + int L[] = new int [n1]; + int R[] = new int [n2]; + + /* + Copy the + info into + temporary arrays + */ + for (int i=0; i + + +#### Selection Sort Implementation + +```java +import java.util.*; + +public class Selectionso { + public static void Selectionso(int myArr[]) + { + /* + 0. take an unsorted num of elements within an array + 1. find the minimum and place it on its own + 2. find the second min and place it after the min in the other array + 3. repeat till you have one left(i.e. largest) and place it at the end of the array + */ + int arr_size = myArr.length; + for(int x=0;x + + #### Insertions at the End in a LL index Time C @@ -451,23 +1136,9 @@ O(n) - compare using .compareTo() method -### Important Algo - -#### Sorting -1. Merge Sort -2. Quick Sort -3. Bucket/Insertion Sort -4. Heap Sort -5. Selection Sort -6. Counting Sort -#### Searching - -1. Breath First Search[Graphs] -2. Depth First Search[Graphs] -3. Binary Search[Linear] #### Divide & Conquer @@ -492,4 +1163,4 @@ public class myclass{ //Total: O(1) + O(n) + O(n^2) ≈ O(n^2) } } -``` \ No newline at end of file +``` diff --git a/OOPClss/.idea/OOPClss.iml b/OOPClss/.idea/OOPClss.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/OOPClss/.idea/OOPClss.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/.idea/misc.xml b/OOPClss/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/OOPClss/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/.idea/modules.xml b/OOPClss/.idea/modules.xml new file mode 100644 index 0000000..0ef7a57 --- /dev/null +++ b/OOPClss/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/.idea/vcs.xml b/OOPClss/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/OOPClss/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/.idea/workspace.xml b/OOPClss/.idea/workspace.xml new file mode 100644 index 0000000..ba18005 --- /dev/null +++ b/OOPClss/.idea/workspace.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 3 +} + + + + { + "keyToString": { + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.git.unshallow": "true", + "git-widget-placeholder": "master", + "kotlin-language-version-configured": "true", + "last_opened_file_path": "C:/Users/OMAR/Java" + } +} + + + + + 1751049426267 + + + + \ No newline at end of file diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build.xml b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build.xml new file mode 100644 index 0000000..56ef3fa --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project JavaUserDefinedExceptionSampleApp. + + + diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/.netbeans_automatic_build b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/.netbeans_update_resources b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/tests/Authentication.class b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/tests/Authentication.class new file mode 100644 index 0000000..549aa2b Binary files /dev/null and b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/tests/Authentication.class differ diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/User.class b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/User.class new file mode 100644 index 0000000..c1a168b Binary files /dev/null and b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/User.class differ diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/UserCollection.class b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/UserCollection.class new file mode 100644 index 0000000..0daf7aa Binary files /dev/null and b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/UserCollection.class differ diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/UserNotFoundException.class b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/UserNotFoundException.class new file mode 100644 index 0000000..290f8f3 Binary files /dev/null and b/OOPClss/2_JavaUserDefinedExceptionSampleApp/build/classes/users/UserNotFoundException.class differ diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/manifest.mf b/OOPClss/2_JavaUserDefinedExceptionSampleApp/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/build-impl.xml b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/build-impl.xml new file mode 100644 index 0000000..c8bfd9a --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/build-impl.xml @@ -0,0 +1,1770 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/genfiles.properties b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/genfiles.properties new file mode 100644 index 0000000..e7337e3 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a03a820a +build.xml.script.CRC32=02ee4d09 +build.xml.stylesheet.CRC32=f85dc8f2@1.93.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a03a820a +nbproject/build-impl.xml.script.CRC32=92d6f372 +nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.93.0.48 diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/config.properties b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/private.properties b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/private.properties new file mode 100644 index 0000000..63106a1 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\SSE\\AppData\\Roaming\\NetBeans\\11.2\\build.properties diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/private.xml b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/private.xml new file mode 100644 index 0000000..4b5e3c2 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/private/private.xml @@ -0,0 +1,11 @@ + + + + + + + file:/D:/Course%20materials/Spring%2021/CSC2303/0_Units/unit%206_exceptions/group%20activity/skeletons/skeletons/2_JavaUserDefinedExceptionSampleApp/src/tests/Testing.java + file:/D:/Course%20materials/Spring%2021/CSC2303/0_Units/unit%206_exceptions/group%20activity/skeletons/skeletons/2_JavaUserDefinedExceptionSampleApp/src/users/UserCollection.java + + + diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/project.properties b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/project.properties new file mode 100644 index 0000000..e6bba81 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/project.properties @@ -0,0 +1,87 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=JavaUserDefinedExceptionSampleApp +application.vendor=mourhir +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/JavaUserDefinedExceptionSampleApp.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=true +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=users.ProcessLogin +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/project.xml b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/project.xml new file mode 100644 index 0000000..f8314ce --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + JavaUserDefinedExceptionSampleApp + + + + + + + + + diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/tests/Authentication.java b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/tests/Authentication.java new file mode 100644 index 0000000..6a07901 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/tests/Authentication.java @@ -0,0 +1,97 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package tests; + +import java.util.Scanner; +import users.User; +import users.UserCollection; + +import users.UserNotFoundException; + +/** + * + * @author Administrator + */ +public class Authentication { + + private static Scanner sc; + private static UserCollection coll; + + public static void main(String[] args) { + coll = new UserCollection(); + sc = new Scanner(System.in); + + loop: + while (true) { + System.out.print("To register type 1, to login type 2 : "); + int choice = sc.nextInt(); + switch (choice) { + //test the registration process + case 1: + registerNewUser(); + break; + + //test the process login + case 2: + processLogin(); + break; + default: + break loop; + } + + } + sc.close(); + } + + private static void registerNewUser() { + + while (true) { + //prompt the user + System.out.print("Please provide your first name: "); + String fname = sc.next(); + System.out.print("Please provide your last name: "); + String lanme = sc.next(); + System.out.print("Please choose a user name: "); + String uname = sc.next(); + System.out.print("Please provide a password: "); + String pass = sc.next(); + User u = new User(uname, pass, uname, uname); + + try{ + if(UserCollection.register(u)){ + System.out.println("User registered successfully"); + } + } + catch(UserExistsException e){ + System.out.println("Registration Failed Username"+e.getUsername()+": already exists in the system."); + } + + } + + } + + private static void processLogin() { + + //prompt the user + System.out.print("Please provide a user name : "); + String uname = sc.next(); + System.out.print("Please provide a password : "); + String pass = sc.next(); + + User u = new User(uname, pass, uname, uname); + try{ + if(UserCollection.login(u)){ + System.out.println("Successful"); + } + } + catch (UserNotFoundException e){ + System.out.println("Login fialed"+e.getMessage()); + } + + + } + +} diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/User.java b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/User.java new file mode 100644 index 0000000..52edcf9 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/User.java @@ -0,0 +1,98 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package users; + +/** + * + * @author mourhir + */ +public class User { + + private String uname; + private String pass; + + private String FN; + private String LN; + + public User( String FN, String LN,String uname, String pass) { + this.uname = uname; + this.pass = pass; + this.FN = FN; + this.LN = LN; + } + + public User(String uname) { + this.uname = uname; + } + + /** + * @return the uname + */ + public String getUname() { + return uname; + } + + /** + * @param uname the uname to set + */ + public void setUname(String uname) { + this.uname = uname; + } + + /** + * @return the pass + */ + public String getPass() { + return pass; + } + + /** + * @param pass the pass to set + */ + public void setPass(String pass) { + this.pass = pass; + } + + /** + * @return the FN + */ + public String getFN() { + return FN; + } + + /** + * @param FN the FN to set + */ + public void setFN(String FN) { + this.FN = FN; + } + + /** + * @return the LN + */ + public String getLN() { + return LN; + } + + /** + * @param LN the LN to set + */ + public void setLN(String LN) { + this.LN = LN; + } + + public boolean authenticate(String pass) { + return this.pass.equals(pass); + } + + @Override + public boolean equals(Object obj) {//inherited from java.lang.Object + return (obj != null + && obj instanceof User + && ((User) obj).getUname().equals(this.uname)); + + } + +} diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserCollection.java b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserCollection.java new file mode 100644 index 0000000..86e362b --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserCollection.java @@ -0,0 +1,51 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package users; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + + +/** + * + * @author Administrator + */ +public class UserCollection { + + public static ArrayList usersList; + + public UserCollection() { + usersList = new ArrayList(); + //hardcoded, should be removed later + usersList.add(new User("totoFN", "totoLN", "toto", "toto")); + usersList.add(new User("fooFN", "fooLN", "foo", "foo")); + + } + + public static boolean register() { + Scanner u = new Scanner(System.in); + + if(UserList.contains(u)){ + throw UserNotFoundException("User already registerd in the system."); + } + else{ + usersList.add(u); + return true; + } + } + + public static boolean login(User theUser) throws UserNotFoundException{ + for(User user: usersList){ + if(user.equals(theUser)){ + return user.authenticate(theUser.getPass()); + } + } + throw new UserNotFoundException(theUser.getUname()); + } + +} diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserExistsException.java b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserExistsException.java new file mode 100644 index 0000000..b9a71dd --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserExistsException.java @@ -0,0 +1,12 @@ +package users; + +public class UserExistsException extends Exception{ + private String username; + public UserExistsException(String username){ + this.username=username; + } + + public String getUsername(){ + return username; + } +} \ No newline at end of file diff --git a/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserNotFoundException.java b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserNotFoundException.java new file mode 100644 index 0000000..13ce1e0 --- /dev/null +++ b/OOPClss/2_JavaUserDefinedExceptionSampleApp/src/users/UserNotFoundException.java @@ -0,0 +1,25 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package users; + +import static users.UserCollection.usersList; + + +public class UserNotFoundException extends Exception { + + private String username; + + public UserNotFoundException(String username) { + super("The username :" + username + " does not exist."); + this.username = username; + } + + + public String getUname() { + return username; + } + + +} diff --git a/OOPClss/Book.java b/OOPClss/Book.java new file mode 100644 index 0000000..a7f5182 --- /dev/null +++ b/OOPClss/Book.java @@ -0,0 +1,22 @@ +import java.util.*; + + +public class Book{ + public String title; + public String author; + public String isbn; + + public Book(String title, String author, String isbn){ + this.title=title; + this.author=author; + this.isbn=isbn; + } + + public void getInfo(){ + System.out.println("The book has a title"+title+" and an author "+author+" with an ISBN number of: "+isbn) + } + + public String toString(){ + return "Book [Title: " + title + ", Author: " + author + " ,ISBN: " + "]"; + } +} \ No newline at end of file diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build.xml b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build.xml new file mode 100644 index 0000000..32f38ed --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project CollectionsSampleApplicationSkeleton. + + + diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/built-jar.properties b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/built-jar.properties new file mode 100644 index 0000000..07fa988 --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/built-jar.properties @@ -0,0 +1,4 @@ +#Fri, 08 Apr 2016 08:48:38 +0000 + + +D\:\\course\ Materials\\Spring16\\CSC2303\\2_Laboratories\\lab9_Collections\ lab\ skeleton\ application\\CollectionsSampleApplicationSkeleton= diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/LMS/StudentSystem.class b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/LMS/StudentSystem.class new file mode 100644 index 0000000..d91ac2a Binary files /dev/null and b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/LMS/StudentSystem.class differ diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/students/Student.class b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/students/Student.class new file mode 100644 index 0000000..7f1f0f6 Binary files /dev/null and b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/students/Student.class differ diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/students/StudentCollection.class b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/students/StudentCollection.class new file mode 100644 index 0000000..62ea560 Binary files /dev/null and b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/build/classes/students/StudentCollection.class differ diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/dist/CollectionsSampleApplicationSkeleton.jar b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/dist/CollectionsSampleApplicationSkeleton.jar new file mode 100644 index 0000000..54cd0ba Binary files /dev/null and b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/dist/CollectionsSampleApplicationSkeleton.jar differ diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/dist/README.TXT b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/dist/README.TXT new file mode 100644 index 0000000..fa93c8e --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "CollectionsSampleApplicationSkeleton.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/manifest.mf b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/build-impl.xml b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/build-impl.xml new file mode 100644 index 0000000..56e15f4 --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/build-impl.xml @@ -0,0 +1,1419 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/genfiles.properties b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/genfiles.properties new file mode 100644 index 0000000..ea0d743 --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b5adcbc2 +build.xml.script.CRC32=98bf525b +build.xml.stylesheet.CRC32=8064a381@1.79.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b5adcbc2 +nbproject/build-impl.xml.script.CRC32=8756d95a +nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/private/private.properties b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/private/private.properties new file mode 100644 index 0000000..18cf70f --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\Administrator\\AppData\\Roaming\\NetBeans\\8.1\\build.properties diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/private/private.xml b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/private/private.xml new file mode 100644 index 0000000..807fc81 --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/private/private.xml @@ -0,0 +1,12 @@ + + + + + + + file:/D:/course%20Materials/Spring16/CSC2303/2_Laboratories/lab9_Collections%20lab%20skeleton%20application/CollectionsSampleApplicationSkeleton/src/students/StudentCollection.java + file:/D:/course%20Materials/Spring16/CSC2303/2_Laboratories/lab9_Collections%20lab%20skeleton%20application/CollectionsSampleApplicationSkeleton/src/LMS/StudentSystem.java + file:/D:/course%20Materials/Spring16/CSC2303/2_Laboratories/lab9_Collections%20lab%20skeleton%20application/CollectionsSampleApplicationSkeleton/src/students/Student.java + + + diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/project.properties b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/project.properties new file mode 100644 index 0000000..32645da --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/CollectionsSampleApplicationSkeleton.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=hashtableimplementation.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/project.xml b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/project.xml new file mode 100644 index 0000000..ec61e7c --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/nbproject/project.xml @@ -0,0 +1,14 @@ + + org.netbeans.modules.java.j2seproject + + + CollectionsSampleApplicationSkeleton + + + + + + + + + diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/LMS/StudentSystem.java b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/LMS/StudentSystem.java new file mode 100644 index 0000000..fb04f72 --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/LMS/StudentSystem.java @@ -0,0 +1,46 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package LMS; + +import students.Student; +import students.StudentCollection; + + +/** + * + * @author mourhir + */ +public class StudentSystem { + + public static StudentCollection studentColl = new StudentCollection(); + + public static void main(String[] args) { + + //create more students and add to the collection + + // call the tostring + + + //modify the gpa of one of the students make it 3.5 + + + //call the tostring to double check the modifiation + + //find all students with gpa 4.0 and display them + + //sort alphabetically + + //call the tostring + + //sort based on GPA + + //call the tostring + + //remove one of the students added above + + //call the tostring + + } +} diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/students/Student.java b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/students/Student.java new file mode 100644 index 0000000..3cf095d --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/students/Student.java @@ -0,0 +1,54 @@ + +package students; + +public class Student { + + private String name; + private double gpa; + private int id; + + public Student(String name, double gpa, int id){ + this.gpa=gpa; + this.name=name; + this.id = id; + } + + + + public void setName(String name){ + this.name=name; + } + + public String getName(){ + return name; + } + + public void setGpa(double gpa){ + this.gpa=gpa; + } + + public double getGPA(){ + return gpa; + } + + public void setId(int id){ + this.id=id; + } + + public int getID(){ + return id; + } + + @Override + public String toString(){ + return("The student: "+this.name+"has an id of: "+this.id+" and has a gpa of: "+this.gpa); + } + + @Override + public boolean equals(String name, double gpa){ + if((this.name == name)&&(this.gpa==gpa)){ + return true; + } + return false; + } +} diff --git a/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/students/StudentCollection.java b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/students/StudentCollection.java new file mode 100644 index 0000000..1ee6ada --- /dev/null +++ b/OOPClss/CollectionsSampleApplicationSkeleton (extract.me)/CollectionsSampleApplicationSkeleton/src/students/StudentCollection.java @@ -0,0 +1,59 @@ + +package students; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.ListIterator; + +public class StudentCollection { + + List students; + + public StudentCollection(List students) { + students s1= new ArrayList<>(); + } + + public boolean addstudent(Student stud) { + students.add(stud); + } + + public boolean removeStudent(Student stud){ + students.remove(stud); + } + + public boolean searchStudent(Student stud){ + + } + + public void modifyStudent(Student search, Student newStud) { + + } + + public Student getStudentWithName(String name) { + return null; + } + + public void modifyStudent(String name, Student newStud) { + + } + + public ArrayList findStudentsWithGpa(double gpa){ + return null; + + } + + public void sortStudents(Comparator comp) { + + } + + public ListIterator getStudents() { + return null; + } + + @Override + public String toString(){ + return null; + + } +} diff --git a/OOPClss/DataStructures/Arrays.java b/OOPClss/DataStructures/Arrays.java new file mode 100644 index 0000000..0449fac --- /dev/null +++ b/OOPClss/DataStructures/Arrays.java @@ -0,0 +1,12 @@ +import java.util.*; + +public class Arrays{ + ArrayList names= new ArrayList<>(); + names.add("Alice"); + names.add("Bobby"); + + + public static void main(String [] args){ + + } +} \ No newline at end of file diff --git a/OOPClss/DataStructures/MyContainer.java b/OOPClss/DataStructures/MyContainer.java new file mode 100644 index 0000000..9d86af5 --- /dev/null +++ b/OOPClss/DataStructures/MyContainer.java @@ -0,0 +1,9 @@ +public class MyContainer{ + private ArrayListmyarr = new ArrayList<>(); + + public add(T item){ + myarr.add(item); + } + + +} \ No newline at end of file diff --git a/OOPClss/EcommerceApp/.gitignore b/OOPClss/EcommerceApp/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/EcommerceApp/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/EcommerceApp/.idea/.gitignore b/OOPClss/EcommerceApp/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/EcommerceApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/EcommerceApp/.idea/misc.xml b/OOPClss/EcommerceApp/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/EcommerceApp/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceApp/.idea/modules.xml b/OOPClss/EcommerceApp/.idea/modules.xml new file mode 100644 index 0000000..c3a2f9c --- /dev/null +++ b/OOPClss/EcommerceApp/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceApp/.idea/vcs.xml b/OOPClss/EcommerceApp/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/EcommerceApp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceApp/EcommerceApp.iml b/OOPClss/EcommerceApp/EcommerceApp.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/EcommerceApp/EcommerceApp.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceApp/src/Main.java b/OOPClss/EcommerceApp/src/Main.java new file mode 100644 index 0000000..d5238c9 --- /dev/null +++ b/OOPClss/EcommerceApp/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} \ No newline at end of file diff --git a/OOPClss/EcommerceApp/src/com/address/Address.java b/OOPClss/EcommerceApp/src/com/address/Address.java new file mode 100644 index 0000000..273b6d9 --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/address/Address.java @@ -0,0 +1,28 @@ +package com.address; + +public class Address { + private String address; + private String city; + private String state; + private String zipcode; + + public Address(String address, String city, String state, String zipcode) { + this.address = address; + this.city = city; + this.state = state; + this.zipcode = zipcode; + } + + + @Override + public String toString() { + return "Address{" + + "address='" + address + '\'' + + ", city='" + city + '\'' + + ", state='" + state + '\'' + + ", zipcode='" + zipcode + '\'' + + '}'; + } + + +} diff --git a/OOPClss/EcommerceApp/src/com/cart/Cart.java b/OOPClss/EcommerceApp/src/com/cart/Cart.java new file mode 100644 index 0000000..b16b04e --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/cart/Cart.java @@ -0,0 +1,32 @@ +package com.cart; +import com.cartItem.CartItem; +import com.customer.Customer; + +import java.util.ArrayList; + + +public class Cart { + private Customer customer; + private ArrayListitems = new ArrayList<>(); + + public Cart(Customer customer){ + this.customer=customer; + } + + + public void addItem(CartItem item){ + if(item != null){ + items.add(item); + } + } + + + @Override + public String toString() { + return "Cart{" + + "customer=" + customer + + ", items=" + items + + '}'; + } + +} diff --git a/OOPClss/EcommerceApp/src/com/cartItem/CartItem.java b/OOPClss/EcommerceApp/src/com/cartItem/CartItem.java new file mode 100644 index 0000000..c3b5268 --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/cartItem/CartItem.java @@ -0,0 +1,26 @@ +package com.cartItem; + + +import com.product.Product; + +public class CartItem { + private Product product; + private int quantity; + + + public CartItem(Product product, int quantity){ + this.product=product; + this.quantity=quantity; + } + + @Override + public String toString() { + return "CartItem{" + + "product=" + product + + ", quantity=" + quantity + + '}'; + } + + + +} diff --git a/OOPClss/EcommerceApp/src/com/customer/Customer.java b/OOPClss/EcommerceApp/src/com/customer/Customer.java new file mode 100644 index 0000000..3d5e93f --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/customer/Customer.java @@ -0,0 +1,59 @@ +package com.customer; +import com.address.Address; + +public class Customer { + private int id; + private String name; + private String email; + private Address billingAddress; + + + public Customer(int id, String name, String email, Address billingAddress){ + this.id=id; + this.name=name; + this.email=email; + this.billingAddress=billingAddress; + } + + public Address getBillingAddress(){ + return billingAddress; + } + + public void setBillingAddress(Address billingAddress){ + this.billingAddress=billingAddress; + } + + public int getId(){ + return id; + } + + public void setId(int id){ + this.id=id; + } + + public String getName(){ + return name; + } + + public void setName(String name){ + this.name=name; + } + + public String getEmail(){ + return email; + } + + public void setEmail(String email){ + this.email=email; + } + + @Override + public String toString() { + return "Customer{" + + "id=" + id + + ", name='" + name + '\'' + + ", email='" + email + '\'' + + ", billingAddress=" + billingAddress + + '}'; + } +} diff --git a/OOPClss/EcommerceApp/src/com/order/Order.java b/OOPClss/EcommerceApp/src/com/order/Order.java new file mode 100644 index 0000000..23341a0 --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/order/Order.java @@ -0,0 +1,50 @@ + package com.order; + import com.orderitem.OrderItem; + import com.customer.Customer; + + import java.time.LocalDate; + import java.util.ArrayList; + + public class Order { + private int orderId; + private LocalDate date; + private Customer customer; + private ArrayList items; + + public Order(int orderId, LocalDate date, Customer customer, ArrayList item){ + if (orderId <= 0) { + throw new IllegalArgumentException("Order ID must be positive"); + } + if (date == null) { + throw new IllegalArgumentException("Date cannot be null"); + } + if (customer == null) { + throw new IllegalArgumentException("Customer cannot be null"); + } + + this.orderId=orderId; + this.date=date; + this.customer=customer; + this.items=item; + } + + public Order(int orderId, Customer customer){ + this(orderId, LocalDate.now(), customer, new ArrayList<>()); + } + + public int getOrderId(){ + return orderId; + } + + public LocalDate getDate(){ + return date; + } + + public Customer getCustomer(){ + return customer; + } + + public ArrayList getItems(){ + return new ArrayList<>(items); + } + } diff --git a/OOPClss/EcommerceApp/src/com/orderitem/OrderItem.java b/OOPClss/EcommerceApp/src/com/orderitem/OrderItem.java new file mode 100644 index 0000000..d975b9c --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/orderitem/OrderItem.java @@ -0,0 +1,22 @@ +package com.orderitem; + +public class OrderItem { + private String productName; + private double price; + + public OrderItem(String productName, double price){ + this.productName=productName; + this.price=price; + } + + @Override + public String toString() { + return "OrderItem{" + + "productName='" + productName + '\'' + + ", price=" + price + + '}'; + } + +} + + diff --git a/OOPClss/EcommerceApp/src/com/payment/Payment.java b/OOPClss/EcommerceApp/src/com/payment/Payment.java new file mode 100644 index 0000000..b592880 --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/payment/Payment.java @@ -0,0 +1,31 @@ +package com.payment; + + +import java.time.LocalDate; +import com.paymentmethod.PaymentMethod; + + +public class Payment { + private int paymentId; + private double amount; + private LocalDate date; + private PaymentMethod method; + + public Payment(int paymentId, double amount, LocalDate date, PaymentMethod method){ + this.paymentId=paymentId; + this.amount=amount; + this.date=date; + this.method=method; + } + + @Override + public String toString() { + return "Payment{" + + "paymentId=" + paymentId + + ", amount=" + amount + + ", date=" + date + + ", method=" + method + + '}'; + } + +} diff --git a/OOPClss/EcommerceApp/src/com/paymentmethod/PaymentMethod.java b/OOPClss/EcommerceApp/src/com/paymentmethod/PaymentMethod.java new file mode 100644 index 0000000..fe7f8e3 --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/paymentmethod/PaymentMethod.java @@ -0,0 +1,34 @@ +package com.paymentmethod; + +import com.payment.Payment; + +public enum PaymentMethod { + CASH("Cash on delivery",0.00), + CREDIT_CARD("Credit Card Payment",2.5), + PAYPAL("Paypal Payment",3.0); + + private final String description; + private final double processingFeePercentage; + + PaymentMethod(String description,double processingFeePercentage){ + this.description=description; + this.processingFeePercentage=processingFeePercentage; + } + + public String getDescription(){ + return description; + } + + public double getProcessingFeePercentage(){ + return processingFeePercentage; + } + + + @Override + public String toString() { + return description +" (Fee: "+processingFeePercentage +"%)"; + } + + + +} diff --git a/OOPClss/EcommerceApp/src/com/product/Product.java b/OOPClss/EcommerceApp/src/com/product/Product.java new file mode 100644 index 0000000..4e103db --- /dev/null +++ b/OOPClss/EcommerceApp/src/com/product/Product.java @@ -0,0 +1,27 @@ +package com.product; + +public class Product { + private String sku; + private String name; + private double price; + private int quantityInStock; + + public Product(String sku, String name, double price, int quantityInStock){ + this.sku=sku; + this.name=name; + this.price=price; + this.quantityInStock=quantityInStock; + } + + @Override + public String toString() { + return "Product{" + + "sku='" + sku + '\'' + + ", name='" + name + '\'' + + ", price=" + price + + ", quantityInStock=" + quantityInStock + + '}'; + } + + +} diff --git a/OOPClss/EcommerceOrderSystem/.gitignore b/OOPClss/EcommerceOrderSystem/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/.idea/.gitignore b/OOPClss/EcommerceOrderSystem/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/EcommerceOrderSystem/.idea/misc.xml b/OOPClss/EcommerceOrderSystem/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/.idea/modules.xml b/OOPClss/EcommerceOrderSystem/.idea/modules.xml new file mode 100644 index 0000000..bb53f41 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/.idea/vcs.xml b/OOPClss/EcommerceOrderSystem/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/EcommerceOrderSystem.iml b/OOPClss/EcommerceOrderSystem/EcommerceOrderSystem.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/EcommerceOrderSystem.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/app/EcommerceApp.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/app/EcommerceApp.java new file mode 100644 index 0000000..34eee62 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/app/EcommerceApp.java @@ -0,0 +1,11 @@ +package com.ecommerce.app; + +import com.ecommerce.model.customer.Customer; +import com.ecommerce.model.address.Address; +import java.util.Scanner; + + + +public class EcommerceApp { + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/address/Address.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/address/Address.java new file mode 100644 index 0000000..cf77ee4 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/address/Address.java @@ -0,0 +1,26 @@ +package com.ecommerce.model.address; + + +public class Address{ + private String street; + private String city; + private String state; + private String zip; + + public Address(String street, String city, String state, String zip) { + this.street = street; + this.city = city; + this.state = state; + this.zip = zip; + } + + @Override + public String toString() { + return "Address{" + + "street='" + street + '\'' + + ", city='" + city + '\'' + + ", state='" + state + '\'' + + ", zip='" + zip + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/cart/Cart.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/cart/Cart.java new file mode 100644 index 0000000..e67857b --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/cart/Cart.java @@ -0,0 +1,26 @@ +package com.ecommerce.model.customer; +package com.ecommerce.model.cartItem; +package com.ecommerce.model.cart; + + +public class Cart{ + private Customer customer; + private CartItem items[]; + + public Cart(Customer customer){ + this.customer=customer; + } + + public void addItem(CartItem item){ + + } + @Override + public String toString() { + return "Cart{" + + "customer=" + customer + + ", items=" + java.util.Arrays.toString(items) + + '}'; + } + + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/cartItem/CartItem.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/cartItem/CartItem.java new file mode 100644 index 0000000..e78c2fc --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/cartItem/CartItem.java @@ -0,0 +1,25 @@ +package com.ecommerce.model.address; +package com.ecommerce.model.cart; +package com.ecommerce.model.orderItem; +package com.ecommerce.model.product; +package com.ecommerce.model.cartItem; + + +public class CartItem{ + private Product product; + private int quantity; + + public CartItem(Product product, int quantity){ + this.product=product; + this.quantity=quantity; + } + + @Override + public String toString() { + return "CartItem{" + + "product=" + product + + ", quantity=" + quantity + + '}'; + } + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/customer/Customer.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/customer/Customer.java new file mode 100644 index 0000000..30f61fc --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/customer/Customer.java @@ -0,0 +1,51 @@ +package com.ecommerce.model.address; +package com.ecommerce.model.customer; + + +public class Customer{ + int id; + String name; + String email; + Address billingAddress; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Address getBillingAddress() { + return billingAddress; + } + + public void setBillingAddress(Address billingAddress) { + this.billingAddress = billingAddress; + } + + public Customer(int id, String name, String email, Address billingAddress) { + this.id = id; + this.name = name; + this.email = email; + this.billingAddress = billingAddress; + } + + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/order/Order.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/order/Order.java new file mode 100644 index 0000000..8cdf5c5 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/order/Order.java @@ -0,0 +1,29 @@ +package com.ecommerce.model.order; +package com.ecommerce.model.customer; +package com.ecommerce.model.orderitem; + +public class Order{ + private int orderId; + private LocalDate date; + private Customer customer; + private Orderitem orderitem[]; + + + public Order(int orderId, Customer customer, Orderitem orderitem){ + this.orderId=orderId; + this.customer=customer; + this.orderitem=orderitem; + } + + @Override + public String toString() { + return "Order{" + + "orderId=" + orderId + + ", date=" + date + + ", customer=" + customer + + ", orderitem=" + java.util.Arrays.toString(orderitem) + + '}'; + } + + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/orderitem/Orderitem.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/orderitem/Orderitem.java new file mode 100644 index 0000000..a918157 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/orderitem/Orderitem.java @@ -0,0 +1,23 @@ +package com.ecommerce.model.orderitem; + +public class Orderitem{ + private Product product; + private int quantity; + private double lineTotal; + + public Orderitem(Product product, int quantity){ + this.product=product; + this.quantity=quantity + } + + @Override + public String toString() { + return "Orderitem{" + + "product=" + product + + ", quantity=" + quantity + + ", lineTotal=" + lineTotal + + '}'; + } + + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/payment/Payment.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/payment/Payment.java new file mode 100644 index 0000000..880206f --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/payment/Payment.java @@ -0,0 +1,32 @@ + +package com.ecommerce.model.payment; + +import java.time.LocalDate; +import com.ecommerce.model.paymentMethod.PaymentMethod; + + + +public class Payment{ + private int paymentId; + private double amount; + private LocalDate date; + private PaymentMethod method; + + public Payment(int paymentId, double amount, LocalDate date, PaymentMethod method){ + this.paymentId=paymentId; + this.amount=amount; + this.date=date; + this.method=method; + } + + @Override + public String toString() { + return "Payment{" + + "paymentId=" + paymentId + + ", amount=" + amount + + ", date=" + date + + ", method=" + method + + '}'; + } + +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/paymentMethod/PaymentMethod.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/paymentMethod/PaymentMethod.java new file mode 100644 index 0000000..a5470c3 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/paymentMethod/PaymentMethod.java @@ -0,0 +1,7 @@ +package com.ecommerce.model.paymentMethod; + +public enum PaymentMethod{ + CASH, + CREDIT_CARD, + PAYPAL +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/product/Product.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/product/Product.java new file mode 100644 index 0000000..fd1abb4 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/product/Product.java @@ -0,0 +1,25 @@ +package com.ecommerce.model.product; + +public class Product{ + private String sku; + private String name; + private double price; + private int quantityInStock; + + public Product(String sku, String name, double price, int quantityInStock){ + this.sku=sku; + this.name=name; + this.price=price; + this.quantityInStock=quantityInStock; + } + + @Override + public String toString(){ + return "Product{" + + "sku='" + sku + '\'' + + ", name='" + name + '\'' + + ", price=" + price + + ", quantityInStock=" + quantityInStock + + '}'; + } +} \ No newline at end of file diff --git a/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/shipment/Shipment.java b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/shipment/Shipment.java new file mode 100644 index 0000000..d53ae56 --- /dev/null +++ b/OOPClss/EcommerceOrderSystem/src/com/ecommerce/model/shipment/Shipment.java @@ -0,0 +1,32 @@ +package com.ecommerce.model.shipment; + +import java.time.LocalDate; +import com.ecommerce.model.order.Order; + + +public class Shipment{ + private int shipmentId; + private Order order; + private LocalDate shipDate; + private String carrier; + + + public Shipment(int shipmentId, Order order, LocalDate shipDate, String carrier){ + this.shipmentId=shipmentId; + this.order=order; + this.shipDate=shipDate; + this.carrier=carrier; + } + + @Override + public String toString() { + return "Shipment{" + + "shipmentId=" + shipmentId + + ", order=" + order + + ", shipDate=" + shipDate + + ", carrier='" + carrier + '\'' + + '}'; + } + + +} \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/.gitignore b/OOPClss/Enhancedglovoapp/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/.idea/.gitignore b/OOPClss/Enhancedglovoapp/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/Enhancedglovoapp/.idea/misc.xml b/OOPClss/Enhancedglovoapp/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/Enhancedglovoapp/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/.idea/modules.xml b/OOPClss/Enhancedglovoapp/.idea/modules.xml new file mode 100644 index 0000000..3b47df7 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/.idea/vcs.xml b/OOPClss/Enhancedglovoapp/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/Enhancedglovoapp.iml b/OOPClss/Enhancedglovoapp/Enhancedglovoapp.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/Enhancedglovoapp/Enhancedglovoapp.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/src/admin.java b/OOPClss/Enhancedglovoapp/src/admin.java new file mode 100644 index 0000000..db04f32 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/admin.java @@ -0,0 +1,24 @@ +import java.util.List; + +public class admin extends user implements manageable { + private int adminId; + private List permissions; + + @Override + public void manageOrder() { + + } + + @Override + public void manageProfile() { + + } + + public void handleDispute(){ + + } + + public void monitorOrder(){ + + } +} diff --git a/OOPClss/Enhancedglovoapp/src/customer.java b/OOPClss/Enhancedglovoapp/src/customer.java new file mode 100644 index 0000000..e353570 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/customer.java @@ -0,0 +1,58 @@ +public class customer extends user implements manageable { + private String address; + private String paymentInfo; + public order currentOrder; + + public String getAddress(){ + return address; + } + + public void setAddress(String address){ + this.address=address; + } + + public String getPaymentInfo(){ + return paymentInfo; + } + + public void setPaymentInfo(String paymentInfo){ + this.paymentInfo=paymentInfo; + } + + @Override + public String toString() { + return "Customer{" + + "address='" + address + '\'' + + ", paymentInfo='" + paymentInfo + '\'' + + '}'; + } + + @Override + public void manageOrder(){ + if(currentOrder != null ¤tOrder.getStatus()==orderStatus.PENDING) + { + currentOrder.setStatus(orderStatus.DELIVERED); + } + } + + @Override + public void manageProfile(){ + + } + + public void placeOrder(){ + + } + + public order getCurrentOrder(){ + return currentOrder; + } + + public void setCurrentOrder(order currentOrder){ + this.currentOrder= currentOrder; + } + + + + +} diff --git a/OOPClss/Enhancedglovoapp/src/deliveryPerson.java b/OOPClss/Enhancedglovoapp/src/deliveryPerson.java new file mode 100644 index 0000000..5dfa63f --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/deliveryPerson.java @@ -0,0 +1,93 @@ +import java.time.LocalDate; +import java.util.List; + +public class deliveryPerson extends user { + private String vehicleType; + private boolean availability; + private LocalDate deliveryTime; + + public deliveryPerson(String name, String phoneNumber, String email, String password, String vehicleType, boolean availability,LocalDate deliveryTime){ + super.setName(name); + super.setPhoneNumber(phoneNumber); + super.setEmail(email); + super.setPassword(password); + this.vehicleType=vehicleType; + this.availability=availability; + this.deliveryTime=deliveryTime; + } + + public void setVehicleType(String vehicleType){ + this.vehicleType=vehicleType; + } + + public String getVehicleType(){ + return vehicleType; + } + + public void setAvailability(boolean availability){ + this.availability=availability; + } + + public boolean getAvailability(){ + return availability; + } + + public void setDeliveryTime(LocalDate deliveryTime){ + this.deliveryTime=deliveryTime; + } + + public LocalDate getDeliveryTime(){ + return deliveryTime; + } + + @Override + public String toString() { + return "A Person is delivering your order with a: {" + + "vehicleType='" + vehicleType + '\'' + + ", availability=" + availability + + ", deliveryTime=" + deliveryTime + + '}'; + } + + + public List getOrders(){ + return orders; + } + + public void setOrders(List orders){ + this.orders=order; + } + + public void addOrder(order order) { + if (orders != null) { + orders.add(order); + } + } + + public void deliverOrder() { + if (availability && orders != null) { + for (order order : orders) { + if (order.getStatus() == orderStatus.PENDING) { + order.setStatus(orderStatus.DELIVERED); // Update status to DELIVERED + System.out.println("Order " + order.getOrderId() + " delivered."); + } + } + availability = false; // Mark as unavailable after delivery + } else { + System.out.println("Delivery person unavailable or no orders assigned."); + } + } + + @Override + public String toString() { + return "DeliveryPerson{" + + "name='" + getName() + '\'' + + ", vehicleType='" + vehicleType + '\'' + + ", availability=" + availability + + ", deliveryTime=" + deliveryTime + + ", orders=" + orders + + '}'; + } +} + + diff --git a/OOPClss/Enhancedglovoapp/src/main.java b/OOPClss/Enhancedglovoapp/src/main.java new file mode 100644 index 0000000..9a22436 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/main.java @@ -0,0 +1,5 @@ +public class main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} \ No newline at end of file diff --git a/OOPClss/Enhancedglovoapp/src/manageable.java b/OOPClss/Enhancedglovoapp/src/manageable.java new file mode 100644 index 0000000..77048d1 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/manageable.java @@ -0,0 +1,4 @@ +public interface manageable { + public void manageOrder(); + public void manageProfile(); +} diff --git a/OOPClss/Enhancedglovoapp/src/order.java b/OOPClss/Enhancedglovoapp/src/order.java new file mode 100644 index 0000000..ad8846b --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/order.java @@ -0,0 +1,62 @@ +import java.time.LocalDate; + +public class order { + private int orderId; + private LocalDate orderDate; + private String deliveryAddress; + private orderStatus status; + + public order(int orderId, LocalDate orderDate, String deliveryAddress, orderStatus status){ + this.orderId=orderId; + this.orderDate=orderDate; + this.deliveryAddress=deliveryAddress; + this.status=status; + } + + @Override + public String toString() { + return "order{" + + "orderId=" + orderId + + ", orderDate=" + orderDate + + ", deliveryAddress='" + deliveryAddress + '\'' + + ", status=" + status + + '}'; + } + + + public int getOrderId(){ + return orderId; + } + + public void setOrderId(int orderId){ + this.orderId=orderId; + } + + public LocalDate getOrderDate(){ + return orderDate; + } + + public void setOrderDate(LocalDate orderDate){ + this.orderDate=orderDate; + } + + public String getDeliveryAddress(){ + return deliveryAddress; + } + + public void setDeliveryAddress(String deliveryAddress){ + this.deliveryAddress=deliveryAddress; + } + + public orderStatus getStatus(){ + return status; + } + + public void setStatus(orderStatus status){ + this.status=status; + } + + + + +} diff --git a/OOPClss/Enhancedglovoapp/src/orderItem.java b/OOPClss/Enhancedglovoapp/src/orderItem.java new file mode 100644 index 0000000..b8ad577 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/orderItem.java @@ -0,0 +1,46 @@ +import java.time.LocalDate; + +public class orderItem extends order { + private int itemId; + private int quantity; + private double price; + + public orderItem(int itemId, int quantity, double price){ + super(orderId,orderDate,deliveryAddress, status) + this.itemId=itemId; + this.quantity=quantity; + this.price=price; + } + + public void setItemId(int itemId){ + this.itemId=itemId; + } + + public int getItemId(){ + return itemId; + } + + public int getQuantity(){ + return quantity; + } + + public void setQuantity(int quantity){ + this.quantity=quantity; + } + + public double getPrice(){ + return price; + } + + public void setPrice(double price){ + this.price=price; + } + + + public double getTotalPrice(double price, int quantity){ + return((quantity)*price); + } + public String toString(){ + return("An order has been place with an item id of:"+this.itemId+"and a price of: "+this.price+" and "+this.quantity+" number of items of this have been ordered"); + } +} diff --git a/OOPClss/Enhancedglovoapp/src/orderStatus.java b/OOPClss/Enhancedglovoapp/src/orderStatus.java new file mode 100644 index 0000000..cff44c6 --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/orderStatus.java @@ -0,0 +1,3 @@ +public enum orderStatus { + PENDING, DISPATCHED, DELIVERED; +} diff --git a/OOPClss/Enhancedglovoapp/src/restaurantOwner.java b/OOPClss/Enhancedglovoapp/src/restaurantOwner.java new file mode 100644 index 0000000..030139a --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/restaurantOwner.java @@ -0,0 +1,39 @@ +import java.util.List; + +public class restaurantOwner extends user implements manageable { + private List menu; + private double rating; + private String address; + + public double getRating(){ + return rating; + } + + public void setRating(double rating) { + this.rating = rating; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public restaurantOwner(String address, double rating, List menu){ + this.address=address; + this.rating = rating; + this.menu=menu; + } + + @Override + public void manageOrder() { + + } + + @Override + public void manageProfile() { + + } +} diff --git a/OOPClss/Enhancedglovoapp/src/user.java b/OOPClss/Enhancedglovoapp/src/user.java new file mode 100644 index 0000000..0d99baa --- /dev/null +++ b/OOPClss/Enhancedglovoapp/src/user.java @@ -0,0 +1,57 @@ +public class user { + private String name; + private String phoneNumber; + private String email; + private String password; + + @Override + public String toString() { + return "User{" + + "name='" + name + '\'' + + ", phoneNumber='" + phoneNumber + '\'' + + ", email='" + email + '\'' + + ", password='" + password + '\'' + + '}'; + } + + public String getName(){ + return name; + } + + public void setName(String name){ + this.name = name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void login(){ + + } + + public void logout(){ + + } + +} diff --git a/OOPClss/Eventful/.gitignore b/OOPClss/Eventful/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/Eventful/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/Eventful/.idea/.gitignore b/OOPClss/Eventful/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/Eventful/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/Eventful/.idea/misc.xml b/OOPClss/Eventful/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/Eventful/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/Eventful/.idea/modules.xml b/OOPClss/Eventful/.idea/modules.xml new file mode 100644 index 0000000..ee6c8eb --- /dev/null +++ b/OOPClss/Eventful/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/Eventful/.idea/vcs.xml b/OOPClss/Eventful/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/Eventful/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/Eventful/Eventful.iml b/OOPClss/Eventful/Eventful.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/Eventful/Eventful.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/Eventful/src/com/eventful/Eventful.java b/OOPClss/Eventful/src/com/eventful/Eventful.java new file mode 100644 index 0000000..bb7dfb0 --- /dev/null +++ b/OOPClss/Eventful/src/com/eventful/Eventful.java @@ -0,0 +1,67 @@ +package com.eventful; + +import java.util.GregorianCalendar; +import java.text.SimpleDateFormat; + + + +public class Eventful { + private String title; + private Category category; + private GregorianCalendar time; + private Performer performer; + + public Eventful(String title, Category category, GregorianCalendar time, Performer performer){ + this.title=title; + this.category=category; + this.time=time; + this.performer=performer; + } + + public Event(String title, Category category, Performer performer){ + this(title,category, new GregorianCalendar(),performer); + } + + public getTitle(){ + return title; + } + + public void setTitle(String title) { + this.title=title; + } + + + public Category getCategory(){ + return category; + } + + public void setCategory(Category category){ + this.category=category; + } + + + public GregorianCalendar getTime() { + return time; + } + + public void setTime(GregorianCalendar time){ + this.time=time; + } + + public Performer getPerformer() { + return performer; + } + + public void setPerformer(Performer performer){ + this.performer=performer; + } + + @Override + public String toString(){ + SimpleDateFormat fmt= new SimpleDateFormat("dd/mm/yyyy"); + String dateStr = fmt.format(time.getTime()); + + return String.format("Event[title=%s, category=%s, date=%s, performance=%s]",title,categoryy,date,performance); + + } +} \ No newline at end of file diff --git a/OOPClss/Eventful/src/com/eventful/app/Main.java b/OOPClss/Eventful/src/com/eventful/app/Main.java new file mode 100644 index 0000000..00ab79e --- /dev/null +++ b/OOPClss/Eventful/src/com/eventful/app/Main.java @@ -0,0 +1,7 @@ +package com.eventful.app; +public class Main { + public static void main(String[] args) + { + System.out.println("Hello, World!"); + } +} \ No newline at end of file diff --git a/OOPClss/Eventful/src/com/eventful/model/Category.java b/OOPClss/Eventful/src/com/eventful/model/Category.java new file mode 100644 index 0000000..d91df2c --- /dev/null +++ b/OOPClss/Eventful/src/com/eventful/model/Category.java @@ -0,0 +1,9 @@ +package com.eventful.model.category; + +public enum Category{ + MUSIC, + THEATER, + SPORTS, + CONFERENCE, + OTHER +} \ No newline at end of file diff --git a/OOPClss/Eventful/src/com/eventful/model/Performer.java b/OOPClss/Eventful/src/com/eventful/model/Performer.java new file mode 100644 index 0000000..e87b72a --- /dev/null +++ b/OOPClss/Eventful/src/com/eventful/model/Performer.java @@ -0,0 +1,47 @@ +package com.eventful.model.Performer; + +public class Performer { + private String name; + private char gender; + private int num_performances; + private int age; + private List performances; + + public Performer(String name, char gender, int num_performances, int age, List performances){ + this.name=name; + this.gender=gender; + this.num_performances=num_performances; + this.age=age; + this.performances=performances; + } + + public String getName(){ + return name; + } + + public void setName(String name){ + this.name=name; + } + + public char getGender(){ + return gender; + } + + public void setGender(char gender){ + this.gender=gender + } + + public int getNum_performances(){ + return num_performances; + } + + public void setPerformances(List performances){ + this.performance=performances; + } + + + @Override + public String toString(){ + return("Performer{name=%s, gender=%c, age=%d, performances=%d", name,gender,age,performances); + } +} \ No newline at end of file diff --git a/OOPClss/Exercises.class b/OOPClss/Exercises.class new file mode 100644 index 0000000..c77dc57 Binary files /dev/null and b/OOPClss/Exercises.class differ diff --git a/OOPClss/Exercises.java b/OOPClss/Exercises.java new file mode 100644 index 0000000..aecc43f --- /dev/null +++ b/OOPClss/Exercises.java @@ -0,0 +1,102 @@ +public class Exercises{ + public static void ex1(){ + int num=1; + while(num<=10){ + System.out.println(num); + num++; + } + + } + + public static void ex2(){ + int num1=0; + do{ + System.out.println(num1); + num1++; + }while(num1<=10); + + } + public static int evenNumberSum(int limit){ + int sum=0; + for(int num=0;num<=limit;num++){ + sum+=num; + } + return sum; + } + + public static int averageOfArr(int arr[]){ + int sum=0; + int count=0; + for(int i : arr){ + sum+=i; + } + return sum/arr.length; + } + + public static void minorOrNot(int age){ + if(age<18){ + System.out.println("Minor"); + } + else if(age>=18 && age<=65){ + System.out.println("Adult"); + } + else{ + System.out.println("Senior Citizen"); + } + } + public static void findNumber(int myArr[], int toSearch){ + for(int i=0;ib && a>c){ + largest=a; + } + if(b>a && b>c){ + largest=b; + } + else{ + largest=c; + } + return largest; + } + + public static int factorial(int num){ + if(num==0){ + return 1; + } + else{ + return num*factorial(num-1); + } + } + + public static int evenOdd(int num){ + if((num%2)==0) + { + return 1; //even + } + else{ + return 2; //odd + } + } + + public static boolean leapYear(int year){ + if((year % 400)==0){ + return true; + } + else if((year % 100)==0){ + return false; + } + else if((year % 4)==0){ + return true; + } + return false; + } + + public static void posnegzero(int num){ + if(num<0){ + System.out.println("negative"); + } + else if(num>0){ + System.out.println("Positive"); + } + else{ + System.out.println("Zero"); + } + } + + public static int absofNum(int num){ + if(num<0){ + return (-1)*num; + } + else{ + return num; + } + } + public static int minoftwonums(int a, int b){ + int toReturn = (athis.balance){ + throw new IllegalArgumentException("You cannot withdraw more than the money you have"); + } + this.balance-=amount; + } + + public double getBalance(){ + return balance; + } + + @Override + public String toString(){ + return String.format("Bank Acoount{owner=%s, balance=%.2f, accountNumber=%d}",name, balance,accountNum); + } +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/BankAccount/Main.class b/OOPClss/ExercisesSummer2025/ProblemSets/BankAccount/Main.class new file mode 100644 index 0000000..5671236 Binary files /dev/null and b/OOPClss/ExercisesSummer2025/ProblemSets/BankAccount/Main.class differ diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/BankAccount/Main.java b/OOPClss/ExercisesSummer2025/ProblemSets/BankAccount/Main.java new file mode 100644 index 0000000..095e84d --- /dev/null +++ b/OOPClss/ExercisesSummer2025/ProblemSets/BankAccount/Main.java @@ -0,0 +1,10 @@ +public class Main{ + public static void main(String [] args){ + BankAccount bankacc1 = new BankAccount("Youssef Tahiri", 56555.32, "123 Main St., Austin, TX, 78701", 'M',24,8547562); + System.out.println(bankacc1); + bankacc1.deposit(25520); + System.out.println(bankacc1.getBalance()); + bankacc1.withdraw(1552); + System.out.println(bankacc1); + } +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/Book.class b/OOPClss/ExercisesSummer2025/ProblemSets/Book.class new file mode 100644 index 0000000..7518fc5 Binary files /dev/null and b/OOPClss/ExercisesSummer2025/ProblemSets/Book.class differ diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/Book.java b/OOPClss/ExercisesSummer2025/ProblemSets/Book.java new file mode 100644 index 0000000..7ab83c8 --- /dev/null +++ b/OOPClss/ExercisesSummer2025/ProblemSets/Book.java @@ -0,0 +1,18 @@ +import java.util.*; + +public class Book { + private String title; + private String author; + private String ISBN; + + public Book(String title, String author, String ISBN) { + this.title = title; + this.author = author; + this.ISBN = ISBN; + } + + @Override + public String toString(){ + return String.format("Book: {title='%s', author='%s', ISBN='%s'}",title, author,ISBN); + } +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/Main.class b/OOPClss/ExercisesSummer2025/ProblemSets/Main.class new file mode 100644 index 0000000..a767600 Binary files /dev/null and b/OOPClss/ExercisesSummer2025/ProblemSets/Main.class differ diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/Main.java b/OOPClss/ExercisesSummer2025/ProblemSets/Main.java new file mode 100644 index 0000000..307b90e --- /dev/null +++ b/OOPClss/ExercisesSummer2025/ProblemSets/Main.java @@ -0,0 +1,6 @@ +public class Main{ + public static void main(String [] args){ + Book myBook = new Book("Great Expectations", "Charles Dickens", "111-9598-98569-95"); + System.out.println(myBook); + } +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Person.class b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Person.class new file mode 100644 index 0000000..5abc541 Binary files /dev/null and b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Person.class differ diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Person.java b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Person.java new file mode 100644 index 0000000..c840e9e --- /dev/null +++ b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Person.java @@ -0,0 +1,36 @@ +import java.util.*; + + +public class Person{ + private String name; + private int age; + + public Person(String name,int age){ + this.name=name; + this.age=age; + } + + public String getName(){ + return name; + } + + public int getAge(){ + return age; + } + + @Override + public String toString(){ + return String.format("Person{name='%s',age=%d}",name,age); + } + + + public static void main(String [] args){ + Person p = new Person("Alice Walton", 29); + Student s = new Student("Bob", 20, 1001); + Teacher t = new Teacher("Carol", 42, "Physics II", 55_000.00); + List indivs = Arrays.asList(p,s,t); + for(Person person: indivs){ + System.out.println(indivs); + } + } +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Student.class b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Student.class new file mode 100644 index 0000000..759b1ff Binary files /dev/null and b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Student.class differ diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Student.java b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Student.java new file mode 100644 index 0000000..a5e69cd --- /dev/null +++ b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Student.java @@ -0,0 +1,8 @@ +public class Student extends Person{ + private int studentId; + public Student(String name, int age,int studentId){ + super(name,age); + this.studentId=studentId; + } + +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Teacher.class b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Teacher.class new file mode 100644 index 0000000..b8d1cb7 Binary files /dev/null and b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Teacher.class differ diff --git a/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Teacher.java b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Teacher.java new file mode 100644 index 0000000..b4d6cc2 --- /dev/null +++ b/OOPClss/ExercisesSummer2025/ProblemSets/PersonInheritanc/Teacher.java @@ -0,0 +1,23 @@ +public class Teacher extends Person{ + private String subject; + private double salary; + + public Teacher(String name, int age, String subject, double salary){ + super(name, age); + this.subject=subject; + this.salary=salary; + } + + public String getSubject(){ + return subject; + } + + public double getSalary(){ + return salary; + } + + @Override + public String toString(){ + return String.format("Teacher{%s, subject='%s',salary=%.2f}",super.toString(), subject,salary); + } +} \ No newline at end of file diff --git a/OOPClss/ExercisesSummer2025/daysOfWeek.class b/OOPClss/ExercisesSummer2025/daysOfWeek.class new file mode 100644 index 0000000..d873d4c Binary files /dev/null and b/OOPClss/ExercisesSummer2025/daysOfWeek.class differ diff --git a/OOPClss/ExercisesSummer2025/daysOfWeek.java b/OOPClss/ExercisesSummer2025/daysOfWeek.java new file mode 100644 index 0000000..eb4f45a --- /dev/null +++ b/OOPClss/ExercisesSummer2025/daysOfWeek.java @@ -0,0 +1 @@ +public enum daysOfWeek{SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY} diff --git a/OOPClss/Generics/Car.class b/OOPClss/Generics/Car.class new file mode 100644 index 0000000..c4156b6 Binary files /dev/null and b/OOPClss/Generics/Car.class differ diff --git a/OOPClss/Generics/Car.java b/OOPClss/Generics/Car.java new file mode 100644 index 0000000..9d9ff4c --- /dev/null +++ b/OOPClss/Generics/Car.java @@ -0,0 +1,52 @@ +public class Car { + private int year; + private String make; + private String model; + private String color; + + public Car(int year, String make,String model,String color) + { + this.year=year; + this.make=make; + this.model=model; + this.color=color; + } + + public int getYear(){ + return year; + } + + public void setYear(int year){ + this.year=year; + } + + public String getMake(){ + return make; + } + + public void setMake(String make){ + this.make=make; + } + public String getModel(){ + return model; + } + + public void setModel(String model){ + this.model=model; + } + + + public String getColor(){ + return color; + } + + public void setColor(String color){ + this.color=color; + } + + @Override + public String toString() { + return year + " " + make + " " + model + " (" + color + ")"; + } + +} \ No newline at end of file diff --git a/OOPClss/Generics/GenericsP1.class b/OOPClss/Generics/GenericsP1.class new file mode 100644 index 0000000..bc832c7 Binary files /dev/null and b/OOPClss/Generics/GenericsP1.class differ diff --git a/OOPClss/Generics/GenericsP1.java b/OOPClss/Generics/GenericsP1.java new file mode 100644 index 0000000..dff5d46 --- /dev/null +++ b/OOPClss/Generics/GenericsP1.java @@ -0,0 +1,75 @@ +import java.util.List; +import java.util.ArrayList; + +public class GenericsP1{ + private final List items; + private static final int DEFAULT_CAPACITY=5; + private final int capacity; + + + public GenericsP1(){ + this(DEFAULT_CAPACITY); + } + + + public GenericsP1(int capacity){ + if(capacity<0) { + throw new IllegalArgumentException("capacity must be > 0"); + } + this.capacity=capacity; + this.items=new ArrayList<>(capacity); + } + + + public void add(T item){ + if(items.size() >= capacity){ + throw new IllegalArgumentException("full"); + } + items.add(item); + } + + public T get(int index){ + if (index < 0 || index > items.size()){ + throw new IndexOutOfBoundsException("index: "+index+", size: "+items.size()); + } + return items.get(index); + } + + public int getSize(){ + return items.size(); + } + + public int getCapacity(){ + return capacity; + } + + public boolean isFull(){ + return items.size()==capacity; + } + + @Override + public String toString() { + return "GenericsP1(capacity=" + capacity + ", items=" + items + ")"; + } + + public static void main(String [] args){ + GenericsP1 cont1 = new GenericsP1<>(3); + cont1.add("hello"); + cont1.add("bye"); + cont1.add("today"); + + GenericsP1 cont2 = new GenericsP1<>(3); + cont2.add(2); + cont2.add(44); + cont2.add(444); + + GenericsP1 cont3 = new GenericsP1<>(); + Car logan = new Car(2013,"Dacia","Logan","Red"); + cont3.add(logan); + + System.out.println("Container 1: "+cont1); + System.out.println("Container 2: "+cont2); + System.out.println("Container 3: "+cont3); + } + +} \ No newline at end of file diff --git a/OOPClss/GlovoApp/.idea/.gitignore b/OOPClss/GlovoApp/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/GlovoApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/GlovoApp/.idea/misc.xml b/OOPClss/GlovoApp/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/GlovoApp/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoApp/.idea/modules.xml b/OOPClss/GlovoApp/.idea/modules.xml new file mode 100644 index 0000000..832b34d --- /dev/null +++ b/OOPClss/GlovoApp/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoApp/.idea/vcs.xml b/OOPClss/GlovoApp/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/GlovoApp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoApp/GlovoApp.iml b/OOPClss/GlovoApp/GlovoApp.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/GlovoApp/GlovoApp.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoApp/src/com/glovo/app/GlovoApp.java b/OOPClss/GlovoApp/src/com/glovo/app/GlovoApp.java new file mode 100644 index 0000000..cce7081 --- /dev/null +++ b/OOPClss/GlovoApp/src/com/glovo/app/GlovoApp.java @@ -0,0 +1,42 @@ +package com.glovo.app; +import com.glovo.model.Courrier; +import com.glovo.model.Customer; +import com.glovo.model.Order; +import com.glovo.model.OrderStatus; +import com.glovo.model.Restaurant; + + + +import java.util.*; + +public class GlovoApp { + public static void main(String [] args){ + Scanner sc = new Scanner(System.in); + System.out.println("Customer Name"); + String custName = sc.nextLine(); + + System.out.println("Customer Phone Number"); + String custPhone = sc.nextLine(); + + System.out.println("Customer Address"); + String custAddress = sc.nextLine(); + Customer customer = new Customer(custName,custPhone,custAddress); + + System.out.println("Restaurant Name"); + String restName = sc.nextLine(); + + System.out.println("Restaurant Address"); + String restAddress = sc.nextLine(); + + System.out.println("Restaurant Rating"); + double rating = Double.parseDouble(sc.nextLine()); + + Restaurant restaurant = new Restaurant(restName,restAddress,rating); + + Courrier cour1 = new Courrier("Mustapha", "061752525", "Van"); + + + + + } +} \ No newline at end of file diff --git a/OOPClss/GlovoApp/src/com/glovo/model/Courrier.java b/OOPClss/GlovoApp/src/com/glovo/model/Courrier.java new file mode 100644 index 0000000..a5db79b --- /dev/null +++ b/OOPClss/GlovoApp/src/com/glovo/model/Courrier.java @@ -0,0 +1,77 @@ +package com.glovo.model; +import java.time.LocalDate; + +//for getter setter select the field right click===> refactor==>encapsulate fields==>select fields + +public class Courrier{ + private String name; + private String phoneNumber; + private String vehicleType; + private boolean availability; + private LocalDate deliveryTime; + + public Courrier(String name, String phoneNumber, String vehicleType, boolean availability, LocalDate deliveryTime){ + this.name=name; + this.phoneNumber=phoneNumber; + this.vehicleType=vehicleType; + this.availability=availability; + this.setDeliveryTime(deliveryTime); + } + + public Courrier(String name, String phoneNumber, String vehicleType) + { + this(name,phoneNumber,vehicleType,true,LocalDate.now()); + } + + public void setName(String name){ + this.name=name; + } + + public String getName() + { + return name; + } + + public String getPhoneNumber() + { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber){ + this.phoneNumber=phoneNumber; + } + + public LocalDate getDeliveryTime() { + return deliveryTime; + } + + public void setDeliveryTime(LocalDate deliveryTime) { + this.deliveryTime = deliveryTime; + } + + public String getVehicleType(){ + return vehicleType; + } + + public void setVehicleType(String vehicleType){ + this.vehicleType=vehicleType; + } + + public boolean isAvailable(){ + return availability; + } + + public void setAvailability(boolean availability) + { + this.availability=availability; + } + + + + @Override + public String toString(){ + return String.format("The courrier assigned to this order is:%s and his phone number is: %s and is driving a %s and he/she is currently(not/is) %s available: and will be delivering the order at %s", name, phoneNumber, vehicleType, availability, deliveryTime); + } + + +} \ No newline at end of file diff --git a/OOPClss/GlovoApp/src/com/glovo/model/Customer.java b/OOPClss/GlovoApp/src/com/glovo/model/Customer.java new file mode 100644 index 0000000..4ed5d3b --- /dev/null +++ b/OOPClss/GlovoApp/src/com/glovo/model/Customer.java @@ -0,0 +1,43 @@ +package com.glovo.model; + +public class Customer { + private String name; + private String phoneNumber; + private String address; + + + public Customer(String name, String phoneNumber, String address) { + this.name = name; + this.phoneNumber = phoneNumber; + this.address = address; + } + + public String getName() { + return name; + } + + public String getPhoneNum() { + return phoneNumber; + } + + public void setPhoneNum(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + return String.format( + "Customer Name: %s, Phone Number: %s, Address: %s", + name, phoneNumber, address + ); + + } +} \ No newline at end of file diff --git a/OOPClss/GlovoApp/src/com/glovo/model/Order.java b/OOPClss/GlovoApp/src/com/glovo/model/Order.java new file mode 100644 index 0000000..b1afd2d --- /dev/null +++ b/OOPClss/GlovoApp/src/com/glovo/model/Order.java @@ -0,0 +1,69 @@ +package com.glovo.model; + +import java.time.LocalDate; + + +public class Order{ + private int orderId; + private LocalDate orderDate; + private String deliveryAddress; + private OrderStatus status; + private Customer customer; + private Courrier courrier; + private Restaurant restaurant; + + public Order(int orderId, String deliveryAddress, Customer customer, Courrier courrier, Restaurant restaurant) { + this(orderId, LocalDate.now(), deliveryAddress, OrderStatus.PENDING, customer, courrier, restaurant); + } + + public Order(int orderId, String deliveryAddress, Customer customer, Courrier courrier, Restaurant restaurant) { + this(orderId, LocalDate.now(), deliveryAddress, OrderStatus.PENDING, customer, courrier, restaurant); + } + + public Order(int orderId, LocalDate orderDate, String deliveryAddress, OrderStatus status, Customer customer, Courrier courrier, Restaurant restaurant) + { + this.orderId = orderId; + this.orderDate = orderDate; + this.deliveryAddress = deliveryAddress; + this.status = status; + this.customer = customer; + this.courrier = courrier; + this.restaurant = restaurant; + } + public int getOrderId(){ + return orderId; + } + + public LocalDate getOrderDate() { + return orderDate; + } + + public String getDeliveryAddress(){ + return deliveryAddress; + } + + public OrderStatus getStatus(){ + return status; + } + + public void setStatus(OrderStatus status){ + this.status=status; + } + + public Customer getCustomer(){ + return customer; + } + + public Courrier getCourrier(){ + return courrier; + } + + public Restaurant getRestaurant() { + return restaurant; + } + + @Override + public String toString(){ + return String.format("Order id: %d, Date: %s, Status: %s, Delivery Address: %s, Customer: %s, Courrier: %s, Restaurant: %s",orderId, orderDate,status,deliveryAddress,customer,courrier,restaurant); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoApp/src/com/glovo/model/OrderStatus.java b/OOPClss/GlovoApp/src/com/glovo/model/OrderStatus.java new file mode 100644 index 0000000..42956fc --- /dev/null +++ b/OOPClss/GlovoApp/src/com/glovo/model/OrderStatus.java @@ -0,0 +1,8 @@ +package com.glovo.model; + + +public enum OrderStatus{ + PENDING, + DISPATCHED, + DELIVERED +} \ No newline at end of file diff --git a/OOPClss/GlovoApp/src/com/glovo/model/Restaurant.java b/OOPClss/GlovoApp/src/com/glovo/model/Restaurant.java new file mode 100644 index 0000000..de3145a --- /dev/null +++ b/OOPClss/GlovoApp/src/com/glovo/model/Restaurant.java @@ -0,0 +1,41 @@ +package com.glovo.model; + +public class Restaurant{ + private String name; + private String address; + private double rating; + + public Restaurant(String name, String address, double rating){ + this.name=name; + this.address=address; + this.rating=rating; + } + + public String getName(){ + return name; + } + + public String getAddress(){ + return address; + } + + public double getRating(){ + return rating; + } + + public void setRating(double rating){ + this.rating=rating; + } + + @Override + public String toString() { + return String.format( + "Restaurant: %s, Address: %s, Rating: %.1f", + name, + address, + rating + ); + } + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppOmarBelkady.zip b/OOPClss/GlovoAppOmarBelkady.zip new file mode 100644 index 0000000..b448893 Binary files /dev/null and b/OOPClss/GlovoAppOmarBelkady.zip differ diff --git a/OOPClss/GlovoAppPartIII/.idea/.gitignore b/OOPClss/GlovoAppPartIII/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/GlovoAppPartIII/.idea/misc.xml b/OOPClss/GlovoAppPartIII/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/GlovoAppPartIII/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/.idea/modules.xml b/OOPClss/GlovoAppPartIII/.idea/modules.xml new file mode 100644 index 0000000..832b34d --- /dev/null +++ b/OOPClss/GlovoAppPartIII/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/.idea/vcs.xml b/OOPClss/GlovoAppPartIII/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/GlovoApp.iml b/OOPClss/GlovoAppPartIII/GlovoApp.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/GlovoAppPartIII/GlovoApp.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/app/GlovoApp.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/app/GlovoApp.class new file mode 100644 index 0000000..f050893 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/app/GlovoApp.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/manageable/Manageable.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/manageable/Manageable.class new file mode 100644 index 0000000..71af24f Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/manageable/Manageable.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Admin.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Admin.class new file mode 100644 index 0000000..c590ed3 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Admin.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Customer.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Customer.class new file mode 100644 index 0000000..cc51228 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Customer.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/DeliveryPerson.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/DeliveryPerson.class new file mode 100644 index 0000000..ec72843 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/DeliveryPerson.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Permissions.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Permissions.class new file mode 100644 index 0000000..ccd2024 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/Permissions.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/RestaurantOwner.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/RestaurantOwner.class new file mode 100644 index 0000000..c468778 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/RestaurantOwner.class differ diff --git a/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/User.class b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/User.class new file mode 100644 index 0000000..7ea5974 Binary files /dev/null and b/OOPClss/GlovoAppPartIII/src/bin/com/glovo/model/User.class differ diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/app/GlovoApp.java b/OOPClss/GlovoAppPartIII/src/com/glovo/app/GlovoApp.java new file mode 100644 index 0000000..1ba57fd --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/app/GlovoApp.java @@ -0,0 +1,41 @@ +package com.glovo.app; + +import com.glovo.manageable.Manageable; +import com.glovo.model.Customer; +import com.glovo.model.RestaurantOwner; +import com.glovo.model.DeliveryPerson; +import com.glovo.model.Admin; +import com.glovo.model.Permissions; +import com.glovo.model.User; + +import java.util.List; + + + + +import java.util.*; +import java.time.LocalDate; + + +public class GlovoApp { + public static void main(String [] args){ + List actors = List.of( + new Customer("Younes", "0623558955", "yo.d@ex@gmail.com", "pw", "Rabat", "Visa ****3952"), + new RestaurantOwner("Johnson", "0654225236", "a@rest.com", "pw","Marrakech",4.5,List.of("Pizza","Salad")), + new DeliveryPerson("Bobby", "0622258548", "bobby212@gmail.com", "pw","Scooter",LocalDate.now()), + new Admin("Victoria", "0625588556", "c@customer.com", "pw",1,List.of(Permissions.MANAGE_USERS, Permissions.VIEW_REPORTS)) + ); + + for(Manageable manag : actors){ + User k = (User)manag; + k.login(k.getEmail(), k.getPassword()); + manag.manageOrder(); + manag.manageProfile(); + k.logout(k.getEmail(),k.getPassword()); + + + } + + + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/manageable/Manageable.java b/OOPClss/GlovoAppPartIII/src/com/glovo/manageable/Manageable.java new file mode 100644 index 0000000..4b5e248 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/manageable/Manageable.java @@ -0,0 +1,6 @@ +package com.glovo.manageable; + +public interface Manageable{ + void manageOrder(); + public void manageProfile(); +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/Admin.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Admin.java new file mode 100644 index 0000000..120d18c --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Admin.java @@ -0,0 +1,56 @@ +package com.glovo.model; +import com.glovo.model.Permissions; +import com.glovo.manageable.Manageable; +import java.util.List; + + +public class Admin extends User implements Manageable{ + private List permissionsList; + private int adminId; + public Admin(String name, String phoneNumber, String email, String password, int adminId, Listperms){ + super(name,phoneNumber,email,password); + this.adminId=adminId; + this.permissionsList=perms; + } + + public int getAdminId() { + return adminId; + } + + public void setAdminId(int adminId) { + this.adminId = adminId; + } + + public List getPermissionsList() { + return permissionsList; + } + + public void setPermissionsList(List permissionsList) { + this.permissionsList = permissionsList; + } + + + + public void monitorOrder(){ + System.out.println("Admin " + getName() + " monitoring orders"); + } + + public void handleDispute(){ + System.out.println("Admin " + getName() + " handling dispute"); + } + + @Override + public void manageOrder(){ + monitorOrder(); + } + + @Override + public void manageProfile(){ + System.out.println("Admin " + getName() + " updating profile"); + } + + @Override + public String toString(){ + return(super.toString() + ", adminId=" + adminId + ", permissions=" + permissionsList); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/Customer.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Customer.java new file mode 100644 index 0000000..e2f5a25 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Customer.java @@ -0,0 +1,40 @@ +package com.glovo.model; +import com.glovo.manageable.Manageable; + +public class Customer extends User implements Manageable{ + + private String address; + private String paymentInfo; + + + public Customer(String name, String phoneNumber, String email, String password, String address,String paymentInfo) { + super(name,phoneNumber,email,password); + this.address = address; + this.paymentInfo=paymentInfo; + } + + @Override + public void manageOrder(){ + System.out.println("Customer " + getName() + " viewing orders"); + } + + @Override + public void manageProfile(){ + System.out.println("Customer " + getName() + " viewing Profile"); + } + + + + public String getAddress() { + return address; + } + + + public String getPaymentInfo() { + return paymentInfo; + } + @Override + public String toString() { + return(super.toString() + " and its address: "+this.address+" and his payment info is: "+this.paymentInfo); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/DeliveryPerson.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/DeliveryPerson.java new file mode 100644 index 0000000..0cb646a --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/DeliveryPerson.java @@ -0,0 +1,85 @@ +package com.glovo.model; +import java.time.LocalDate; +import com.glovo.manageable.Manageable; + +//for getter setter select the field right click===> refactor==>encapsulate fields==>select fields + +public class DeliveryPerson extends User implements Manageable{ + private String vehicleType; + private boolean availability; + private LocalDate deliveryTime; + + public DeliveryPerson(String name, String phoneNumber, String email, String password, String vehicleType, LocalDate deliveryTime) { + super(name, phoneNumber, email, password); + this.vehicleType=vehicleType; + this.deliveryTime=deliveryTime; + this.availability=true; + } + + public DeliveryPerson(String name, String phoneNumber, String email, String password, String vehicleType) { + this(name, phoneNumber, email, password, vehicleType, LocalDate.now()); + } + + + public void setName(String name) + { + super.setName(name); + } + + public String getName() + { + return super.getName(); + } + + public String getPhoneNumber() + { + return super.getPhoneNumber(); + } + + public void setPhoneNumber(String phoneNumber){ + super.setPhoneNumber(phoneNumber); + } + + public LocalDate getDeliveryTime() { + return deliveryTime; + } + + public void setDeliveryTime(LocalDate deliveryTime) { + this.deliveryTime = deliveryTime; + } + + public String getVehicleType(){ + return vehicleType; + } + + public void setVehicleType(String vehicleType){ + this.vehicleType=vehicleType; + } + + public boolean isAvailable(){ + return availability; + } + + public void setAvailability(boolean availability) + { + this.availability=availability; + } + + + + @Override + public void manageOrder(){ + System.out.println("This person: "+getName()+" is delivering your order"); + } + + @Override + public void manageProfile(){ + System.out.println("This person: "+getName()+" is updating vehicle info"); + } + + + @Override + public String toString(){ + return(super.toString()+" and its vehicle is: "+vehicleType+" and his availability: "+ availability+" and will be delivering it at: "+deliveryTime); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/Order.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Order.java new file mode 100644 index 0000000..fa5306d --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Order.java @@ -0,0 +1,88 @@ +package com.glovo.model; + +import java.time.LocalDate; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + + + +public class Order{ + + private int orderId; + private LocalDate orderDate; + private String deliveryAddress; + private OrderStatus status; + private Customer customer; + private Courrier courrier; + private Restaurant restaurant; + private List items = new ArrayList<>(); + + + + + + public Order(int orderId, String deliveryAddress, Customer customer, DeliverPerson courrier, Restaurant restaurant) { + this(orderId, LocalDate.now(), deliveryAddress, OrderStatus.PENDING, customer, courrier, restaurant); + } + + public Order(int orderId, LocalDate orderDate, String deliveryAddress, OrderStatus status, Customer customer, Courrier courrier, Restaurant restaurant) + { + this.orderId = orderId; + this.orderDate = orderDate; + this.deliveryAddress = deliveryAddress; + this.status = status; + this.customer = customer; + this.courrier = courrier; + this.restaurant = restaurant; + } + public int getOrderId(){ + return orderId; + } + + public LocalDate getOrderDate() { + return orderDate; + } + + public String getDeliveryAddress(){ + return deliveryAddress; + } + + public OrderStatus getStatus(){ + return status; + } + + public void setStatus(OrderStatus status){ + this.status=status; + } + + public Customer getCustomer(){ + return customer; + } + + public Courrier getCourrier(){ + return courrier; + } + + public Restaurant getRestaurant() { + return restaurant; + } + + @Override + public String toString(){ + return String.format("Order id: %d, Date: %s, Status: %s, Delivery Address: %s, Customer: %s, Courrier: %s, Restaurant: %s",orderId, orderDate,status,deliveryAddress,customer,courrier,restaurant); + } + + public void addItem(OrderItem i){ + items.add(i); + } + + public List getItems() { + return Collections.unmodifiableList(items); + } + + public double getTotal(){ + return items.stream().mapToDouble(OrderItem::getTotalPrice).sum(); + } + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/OrderItem.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/OrderItem.java new file mode 100644 index 0000000..0a260dd --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/OrderItem.java @@ -0,0 +1,56 @@ +package com.glovo.model; +import java.util.Collections; +import java.util.List; +import java.util.ArrayList; + +public class OrderItem { + private int itemId; + private int quantity; + private double price; + + public OrderItem(int itemId, int quantity, double price){ + this.itemId=itemId; + this.price=price; + this.quantity=quantity; + + } + + public void setStatus(OrderStatus status){ + this.status=status; + } + + public OrderStatus getStatus() { + return status; + } + + public double getPrice(){ + return price; + } + + public void setPrice(double price){ + this.price=price; + } + + public int getQuantity(){ + return quantity; + } + + public void setQuantity(int quantity){ + this.quantity=quantity; + } + + public int getItemId(){ + return itemId; + } + + public void setItemId(int itemId){ + this.itemId=itemId; + } + + public double getTotalPrice() { + return quantity * price; + } + + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/OrderStatus.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/OrderStatus.java new file mode 100644 index 0000000..c63ece0 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/OrderStatus.java @@ -0,0 +1,10 @@ +package com.glovo.model; + + +public enum OrderStatus{ + PENDING, + DISPATCHED, + DELIVERED, + CANCELLED, + ASSIGNED +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/Permissions.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Permissions.java new file mode 100644 index 0000000..162afc6 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Permissions.java @@ -0,0 +1,7 @@ +package com.glovo.model; + +public enum Permissions { + MANAGE_USERS, + VIEW_REPORTS, + HANDLE_DISPUTES +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/Restaurant.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Restaurant.java new file mode 100644 index 0000000..de3145a --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/Restaurant.java @@ -0,0 +1,41 @@ +package com.glovo.model; + +public class Restaurant{ + private String name; + private String address; + private double rating; + + public Restaurant(String name, String address, double rating){ + this.name=name; + this.address=address; + this.rating=rating; + } + + public String getName(){ + return name; + } + + public String getAddress(){ + return address; + } + + public double getRating(){ + return rating; + } + + public void setRating(double rating){ + this.rating=rating; + } + + @Override + public String toString() { + return String.format( + "Restaurant: %s, Address: %s, Rating: %.1f", + name, + address, + rating + ); + } + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/RestaurantOwner.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/RestaurantOwner.java new file mode 100644 index 0000000..6d03572 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/RestaurantOwner.java @@ -0,0 +1,59 @@ +package com.glovo.model; + +import java.util.List; +import com.glovo.manageable.Manageable; + +public class RestaurantOwner extends User implements Manageable{ + private String address; + private double rating; + private List menu; + + public RestaurantOwner(String name, String phoneNumber, String email, String password, String address, double rating, Listmenu){ + super(name,phoneNumber,email,password); + this.address=address; + this.rating=rating; + this.menu=menu; + } + + public void setRating(double rating){ + this.rating=rating; + } + + public double getRating() { + return rating; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getMenu() { + return menu; + } + + public void setMenu(List menu) { + this.menu = menu; + } + + @Override + public void manageOrder(){ + System.out.println("Restaurant Owner managing: "+getName()+"'s orders"); + } + + @Override + public void manageProfile(){ + System.out.println("Restaurant Owner managing: "+getName()+"'s profile"); + } + + @Override + public String toString(){ + return super.toString()+", address: "+address+" rating: "+rating+", menu: "+menu; + } + + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIII/src/com/glovo/model/User.java b/OOPClss/GlovoAppPartIII/src/com/glovo/model/User.java new file mode 100644 index 0000000..d86baf7 --- /dev/null +++ b/OOPClss/GlovoAppPartIII/src/com/glovo/model/User.java @@ -0,0 +1,65 @@ +package com.glovo.model; + + +public class User{ + private String name; + private String phoneNumber; + private String email; + private String password; + + public User(String name, String phoneNumber, String email, String password){ + this.name=name; + this.phoneNumber=phoneNumber; + this.email=email; + this.password=password; + } + + + public void setName(String name){ + this.name=name; + } + + public String getName(){ + return name; + } + + public void setPhoneNumber(String phoneNumber){ + this.phoneNumber=phoneNumber; + } + + public String getPhoneNumber(){ + return phoneNumber; + } + + public void setEmail(String email){ + this.email=email; + } + + public String getEmail(){ + return email; + } + + public void setPassword(String password){ + this.password=password; + } + + public String getPassword(){ + return password; + } + + @Override + public String toString() + { + return("User: "+this.name+" has a phone Number of : "+this.phoneNumber+" and an email of: "+this.email+" and a password: "+this.password); + } + + public void login(String email, String password){ + System.out.println(name + " logged in with " + email); + } + + public void logout(String email, String password){ + System.out.println(name + " logged out"); + } + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII.zip b/OOPClss/GlovoAppPartIIII.zip new file mode 100644 index 0000000..aa4aabf Binary files /dev/null and b/OOPClss/GlovoAppPartIIII.zip differ diff --git a/OOPClss/GlovoAppPartIIII/.idea/.gitignore b/OOPClss/GlovoAppPartIIII/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/GlovoAppPartIIII/.idea/misc.xml b/OOPClss/GlovoAppPartIIII/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/.idea/modules.xml b/OOPClss/GlovoAppPartIIII/.idea/modules.xml new file mode 100644 index 0000000..832b34d --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/.idea/vcs.xml b/OOPClss/GlovoAppPartIIII/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/GlovoApp.iml b/OOPClss/GlovoAppPartIIII/GlovoApp.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/GlovoApp.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/app/GlovoApp.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/app/GlovoApp.class new file mode 100644 index 0000000..f050893 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/app/GlovoApp.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/manageable/Manageable.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/manageable/Manageable.class new file mode 100644 index 0000000..71af24f Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/manageable/Manageable.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Admin.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Admin.class new file mode 100644 index 0000000..c590ed3 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Admin.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Customer.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Customer.class new file mode 100644 index 0000000..cc51228 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Customer.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/DeliveryPerson.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/DeliveryPerson.class new file mode 100644 index 0000000..ec72843 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/DeliveryPerson.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Permissions.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Permissions.class new file mode 100644 index 0000000..ccd2024 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/Permissions.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/RestaurantOwner.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/RestaurantOwner.class new file mode 100644 index 0000000..c468778 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/RestaurantOwner.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/User.class b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/User.class new file mode 100644 index 0000000..7ea5974 Binary files /dev/null and b/OOPClss/GlovoAppPartIIII/src/bin/com/glovo/model/User.class differ diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/app/GlovoApp.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/app/GlovoApp.java new file mode 100644 index 0000000..9ae3ac7 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/app/GlovoApp.java @@ -0,0 +1,112 @@ +package com.glovo.app; + +import com.glovo.model.*; +import com.glovo.exception.EmptyOrderException; + + +import java.util.*; +import java.io.*; + + +public class GlovoApp { + public static void main(String [] args){ + Scanner sc = new Scanner(System.in); + OrderManager manager = new OrderManager(); + + while(true){ + System.out.println("\n--- Glovo Order Manager Menu ----"); + System.out.println("1. Add An Order"); + System.out.println("2. Remove An Order"); + System.out.println("3. View Order"); + System.out.println("4. Search Orders By Status"); + System.out.println("5. Sort Orders By Date"); + System.out.println("6. Save Order"); + System.out.println("7. Load Order"); + System.out.println("0. Quit"); + System.out.println("Please make an option: "); + try{ + int choice = Integer.parseInt(sc.nextLine()); + + switch(choice){ + case 1: + System.out.print("Order ID: "); + int id = Integer.parseInt(sc.nextLine()); + System.out.print("Delivery Address: "); + String address = sc.nextLine(); + Customer customer = new Customer("Younes", "0600000000", "Rabat"); + Restaurant restaurant = new Restaurant("PizzaHut", "Agdal", 4.6); + DeliveryPerson courier = new DeliveryPerson("Ali", "0655544444", "Bike"); + Order order = new Order(id, address, customer, courier, restaurant); + manager.addOrder(order); + System.out.println("Order added."); + break; + case 2: + if(manager.getAllOrders().isEmpty()){ + throw new EmptyOrderException("No Orders To Remove"); + } + System.out.println("Enter index of order to delete"); + int index = Integer.parseInt(sc.nextLine()); + manager.removeOrder(manager.getAllOrders.get(index)); + System.out.println("Order has been removed successfully"); + break; + + case 3: + if(manager.getAllOrders().isEmpty()){ + throw new EmptyOrderException("No Orders To Display"); + } + for(Order ord: manager.getAllOrders()){ + System.out.println(ord); + + } + break; + + case 4: + System.out.println("Status (PENDING, DISPATCHED, DELIVERED): "); + OrderStatus status = OrderStatus.valueOf(sc.nextLine.toUpperCase()); + List results = manager.searchByStatus(status); + + if(results.isEmpty()){ + System.out.println("No Orders to show"); + } + else{ + for(Order o: results){ + System.out.println(o); + } + } + break; + + case 5: + manager.sortByDate(); + System.out.println("Orders Arranged By Date"); + break; + + case 6: + manager.saveToFile("data/glovo/orders.ser"); + System.out.println("Orders saved."); + break; + case 7: + manager.loadFromFile("data/glovo/orders.ser"); + System.out.println("Orders loaded successfully"); + break; + + case 0: + System.out.println("Leave"); + return; + + default: + System.out.println(" Incorrect option"); + } + } + catch (EmptyOrderListException e) { + System.out.println(" " + e.getMessage()); + System.out.println(e.recoverySuggestion()); + } + + catch (Exception e) { + System.out.println("💥 Error: " + e.getMessage()); + } + } + } +} + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/exception/EmptyOrderException.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/exception/EmptyOrderException.java new file mode 100644 index 0000000..095dd78 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/exception/EmptyOrderException.java @@ -0,0 +1,11 @@ +package com.glovo.exception; + +public class EmptyOrderException extends Exception{ + public EmptyOrderException(String message){ + super(message); + } + + public String recoverFromException(){ + return("Please add at least one order before performing this operation: "); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/manageable/Manageable.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/manageable/Manageable.java new file mode 100644 index 0000000..4b5e248 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/manageable/Manageable.java @@ -0,0 +1,6 @@ +package com.glovo.manageable; + +public interface Manageable{ + void manageOrder(); + public void manageProfile(); +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Admin.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Admin.java new file mode 100644 index 0000000..120d18c --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Admin.java @@ -0,0 +1,56 @@ +package com.glovo.model; +import com.glovo.model.Permissions; +import com.glovo.manageable.Manageable; +import java.util.List; + + +public class Admin extends User implements Manageable{ + private List permissionsList; + private int adminId; + public Admin(String name, String phoneNumber, String email, String password, int adminId, Listperms){ + super(name,phoneNumber,email,password); + this.adminId=adminId; + this.permissionsList=perms; + } + + public int getAdminId() { + return adminId; + } + + public void setAdminId(int adminId) { + this.adminId = adminId; + } + + public List getPermissionsList() { + return permissionsList; + } + + public void setPermissionsList(List permissionsList) { + this.permissionsList = permissionsList; + } + + + + public void monitorOrder(){ + System.out.println("Admin " + getName() + " monitoring orders"); + } + + public void handleDispute(){ + System.out.println("Admin " + getName() + " handling dispute"); + } + + @Override + public void manageOrder(){ + monitorOrder(); + } + + @Override + public void manageProfile(){ + System.out.println("Admin " + getName() + " updating profile"); + } + + @Override + public String toString(){ + return(super.toString() + ", adminId=" + adminId + ", permissions=" + permissionsList); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Customer.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Customer.java new file mode 100644 index 0000000..e2f5a25 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Customer.java @@ -0,0 +1,40 @@ +package com.glovo.model; +import com.glovo.manageable.Manageable; + +public class Customer extends User implements Manageable{ + + private String address; + private String paymentInfo; + + + public Customer(String name, String phoneNumber, String email, String password, String address,String paymentInfo) { + super(name,phoneNumber,email,password); + this.address = address; + this.paymentInfo=paymentInfo; + } + + @Override + public void manageOrder(){ + System.out.println("Customer " + getName() + " viewing orders"); + } + + @Override + public void manageProfile(){ + System.out.println("Customer " + getName() + " viewing Profile"); + } + + + + public String getAddress() { + return address; + } + + + public String getPaymentInfo() { + return paymentInfo; + } + @Override + public String toString() { + return(super.toString() + " and its address: "+this.address+" and his payment info is: "+this.paymentInfo); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/DeliveryPerson.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/DeliveryPerson.java new file mode 100644 index 0000000..0cb646a --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/DeliveryPerson.java @@ -0,0 +1,85 @@ +package com.glovo.model; +import java.time.LocalDate; +import com.glovo.manageable.Manageable; + +//for getter setter select the field right click===> refactor==>encapsulate fields==>select fields + +public class DeliveryPerson extends User implements Manageable{ + private String vehicleType; + private boolean availability; + private LocalDate deliveryTime; + + public DeliveryPerson(String name, String phoneNumber, String email, String password, String vehicleType, LocalDate deliveryTime) { + super(name, phoneNumber, email, password); + this.vehicleType=vehicleType; + this.deliveryTime=deliveryTime; + this.availability=true; + } + + public DeliveryPerson(String name, String phoneNumber, String email, String password, String vehicleType) { + this(name, phoneNumber, email, password, vehicleType, LocalDate.now()); + } + + + public void setName(String name) + { + super.setName(name); + } + + public String getName() + { + return super.getName(); + } + + public String getPhoneNumber() + { + return super.getPhoneNumber(); + } + + public void setPhoneNumber(String phoneNumber){ + super.setPhoneNumber(phoneNumber); + } + + public LocalDate getDeliveryTime() { + return deliveryTime; + } + + public void setDeliveryTime(LocalDate deliveryTime) { + this.deliveryTime = deliveryTime; + } + + public String getVehicleType(){ + return vehicleType; + } + + public void setVehicleType(String vehicleType){ + this.vehicleType=vehicleType; + } + + public boolean isAvailable(){ + return availability; + } + + public void setAvailability(boolean availability) + { + this.availability=availability; + } + + + + @Override + public void manageOrder(){ + System.out.println("This person: "+getName()+" is delivering your order"); + } + + @Override + public void manageProfile(){ + System.out.println("This person: "+getName()+" is updating vehicle info"); + } + + + @Override + public String toString(){ + return(super.toString()+" and its vehicle is: "+vehicleType+" and his availability: "+ availability+" and will be delivering it at: "+deliveryTime); + } +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Order.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Order.java new file mode 100644 index 0000000..fa5306d --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Order.java @@ -0,0 +1,88 @@ +package com.glovo.model; + +import java.time.LocalDate; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + + + +public class Order{ + + private int orderId; + private LocalDate orderDate; + private String deliveryAddress; + private OrderStatus status; + private Customer customer; + private Courrier courrier; + private Restaurant restaurant; + private List items = new ArrayList<>(); + + + + + + public Order(int orderId, String deliveryAddress, Customer customer, DeliverPerson courrier, Restaurant restaurant) { + this(orderId, LocalDate.now(), deliveryAddress, OrderStatus.PENDING, customer, courrier, restaurant); + } + + public Order(int orderId, LocalDate orderDate, String deliveryAddress, OrderStatus status, Customer customer, Courrier courrier, Restaurant restaurant) + { + this.orderId = orderId; + this.orderDate = orderDate; + this.deliveryAddress = deliveryAddress; + this.status = status; + this.customer = customer; + this.courrier = courrier; + this.restaurant = restaurant; + } + public int getOrderId(){ + return orderId; + } + + public LocalDate getOrderDate() { + return orderDate; + } + + public String getDeliveryAddress(){ + return deliveryAddress; + } + + public OrderStatus getStatus(){ + return status; + } + + public void setStatus(OrderStatus status){ + this.status=status; + } + + public Customer getCustomer(){ + return customer; + } + + public Courrier getCourrier(){ + return courrier; + } + + public Restaurant getRestaurant() { + return restaurant; + } + + @Override + public String toString(){ + return String.format("Order id: %d, Date: %s, Status: %s, Delivery Address: %s, Customer: %s, Courrier: %s, Restaurant: %s",orderId, orderDate,status,deliveryAddress,customer,courrier,restaurant); + } + + public void addItem(OrderItem i){ + items.add(i); + } + + public List getItems() { + return Collections.unmodifiableList(items); + } + + public double getTotal(){ + return items.stream().mapToDouble(OrderItem::getTotalPrice).sum(); + } + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderItem.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderItem.java new file mode 100644 index 0000000..0a260dd --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderItem.java @@ -0,0 +1,56 @@ +package com.glovo.model; +import java.util.Collections; +import java.util.List; +import java.util.ArrayList; + +public class OrderItem { + private int itemId; + private int quantity; + private double price; + + public OrderItem(int itemId, int quantity, double price){ + this.itemId=itemId; + this.price=price; + this.quantity=quantity; + + } + + public void setStatus(OrderStatus status){ + this.status=status; + } + + public OrderStatus getStatus() { + return status; + } + + public double getPrice(){ + return price; + } + + public void setPrice(double price){ + this.price=price; + } + + public int getQuantity(){ + return quantity; + } + + public void setQuantity(int quantity){ + this.quantity=quantity; + } + + public int getItemId(){ + return itemId; + } + + public void setItemId(int itemId){ + this.itemId=itemId; + } + + public double getTotalPrice() { + return quantity * price; + } + + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderManager.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderManager.java new file mode 100644 index 0000000..c54dfb8 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderManager.java @@ -0,0 +1,58 @@ +package com.glovo.model; +import java.io.*; +import java.util.*; +import com.glovo.model.Owner; +import com.glovo.model.OrderStatus; + +public class OrderManager implements Serializable { + public List orders; + + public OrderManager(){ + this.orders=new ArrayList<>(); + } + + public void addOrder(Order o){ + orders.add(o); + } + + public void removeOrder(Order o){ + orders.remove(o); + } + + public void editOrder(int index, Order newOrder){ + if(index>=0 && indexSearchByStatus(OrderStatus status){ + List results = new ArrayList<>(); + for(Order o:orders){ + if(o.getStatus()==status){ + results.add(o) + } + } + return results; + } + + public void sortByDate(){ + orders.sort(Comparator.comparing(Order::getOrderDate)); + } + + public List getAllOrders(){ + return orders; + } + + public void saveToFile(String filePath) throws IOException{ + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filePath)); + oos.writeObject(orders); + oos.close(); + } + + public void loadFromFile(String filePath){ + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path)); + orders=(List)ois.readObject(); + ois.close(); + } + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderStatus.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderStatus.java new file mode 100644 index 0000000..c63ece0 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/OrderStatus.java @@ -0,0 +1,10 @@ +package com.glovo.model; + + +public enum OrderStatus{ + PENDING, + DISPATCHED, + DELIVERED, + CANCELLED, + ASSIGNED +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Permissions.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Permissions.java new file mode 100644 index 0000000..162afc6 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Permissions.java @@ -0,0 +1,7 @@ +package com.glovo.model; + +public enum Permissions { + MANAGE_USERS, + VIEW_REPORTS, + HANDLE_DISPUTES +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Restaurant.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Restaurant.java new file mode 100644 index 0000000..de3145a --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/Restaurant.java @@ -0,0 +1,41 @@ +package com.glovo.model; + +public class Restaurant{ + private String name; + private String address; + private double rating; + + public Restaurant(String name, String address, double rating){ + this.name=name; + this.address=address; + this.rating=rating; + } + + public String getName(){ + return name; + } + + public String getAddress(){ + return address; + } + + public double getRating(){ + return rating; + } + + public void setRating(double rating){ + this.rating=rating; + } + + @Override + public String toString() { + return String.format( + "Restaurant: %s, Address: %s, Rating: %.1f", + name, + address, + rating + ); + } + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/RestaurantOwner.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/RestaurantOwner.java new file mode 100644 index 0000000..6d03572 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/RestaurantOwner.java @@ -0,0 +1,59 @@ +package com.glovo.model; + +import java.util.List; +import com.glovo.manageable.Manageable; + +public class RestaurantOwner extends User implements Manageable{ + private String address; + private double rating; + private List menu; + + public RestaurantOwner(String name, String phoneNumber, String email, String password, String address, double rating, Listmenu){ + super(name,phoneNumber,email,password); + this.address=address; + this.rating=rating; + this.menu=menu; + } + + public void setRating(double rating){ + this.rating=rating; + } + + public double getRating() { + return rating; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getMenu() { + return menu; + } + + public void setMenu(List menu) { + this.menu = menu; + } + + @Override + public void manageOrder(){ + System.out.println("Restaurant Owner managing: "+getName()+"'s orders"); + } + + @Override + public void manageProfile(){ + System.out.println("Restaurant Owner managing: "+getName()+"'s profile"); + } + + @Override + public String toString(){ + return super.toString()+", address: "+address+" rating: "+rating+", menu: "+menu; + } + + + +} \ No newline at end of file diff --git a/OOPClss/GlovoAppPartIIII/src/com/glovo/model/User.java b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/User.java new file mode 100644 index 0000000..d86baf7 --- /dev/null +++ b/OOPClss/GlovoAppPartIIII/src/com/glovo/model/User.java @@ -0,0 +1,65 @@ +package com.glovo.model; + + +public class User{ + private String name; + private String phoneNumber; + private String email; + private String password; + + public User(String name, String phoneNumber, String email, String password){ + this.name=name; + this.phoneNumber=phoneNumber; + this.email=email; + this.password=password; + } + + + public void setName(String name){ + this.name=name; + } + + public String getName(){ + return name; + } + + public void setPhoneNumber(String phoneNumber){ + this.phoneNumber=phoneNumber; + } + + public String getPhoneNumber(){ + return phoneNumber; + } + + public void setEmail(String email){ + this.email=email; + } + + public String getEmail(){ + return email; + } + + public void setPassword(String password){ + this.password=password; + } + + public String getPassword(){ + return password; + } + + @Override + public String toString() + { + return("User: "+this.name+" has a phone Number of : "+this.phoneNumber+" and an email of: "+this.email+" and a password: "+this.password); + } + + public void login(String email, String password){ + System.out.println(name + " logged in with " + email); + } + + public void logout(String email, String password){ + System.out.println(name + " logged out"); + } + + +} \ No newline at end of file diff --git a/OOPClss/Library.java b/OOPClss/Library.java new file mode 100644 index 0000000..65ea50c --- /dev/null +++ b/OOPClss/Library.java @@ -0,0 +1,9 @@ +public class Library{ + List myBooks; + List membersOfLib; + + public Library(){ + myBooks = new ArrayList<>(); + membersOfLib = new ArrayList<>(); + } +} \ No newline at end of file diff --git a/OOPClss/LibraryApp/.gitignore b/OOPClss/LibraryApp/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/LibraryApp/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/LibraryApp/.idea/.gitignore b/OOPClss/LibraryApp/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/LibraryApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/LibraryApp/.idea/misc.xml b/OOPClss/LibraryApp/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/LibraryApp/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/LibraryApp/.idea/modules.xml b/OOPClss/LibraryApp/.idea/modules.xml new file mode 100644 index 0000000..26f9df2 --- /dev/null +++ b/OOPClss/LibraryApp/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/LibraryApp/.idea/vcs.xml b/OOPClss/LibraryApp/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/LibraryApp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/LibraryApp/Library.iml b/OOPClss/LibraryApp/Library.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/LibraryApp/Library.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/LibraryApp/src/com/library/app/LibraryApp.class b/OOPClss/LibraryApp/src/com/library/app/LibraryApp.class new file mode 100644 index 0000000..b19c075 Binary files /dev/null and b/OOPClss/LibraryApp/src/com/library/app/LibraryApp.class differ diff --git a/OOPClss/LibraryApp/src/com/library/app/LibraryApp.java b/OOPClss/LibraryApp/src/com/library/app/LibraryApp.java new file mode 100644 index 0000000..56dac18 --- /dev/null +++ b/OOPClss/LibraryApp/src/com/library/app/LibraryApp.java @@ -0,0 +1,52 @@ +package com.library.app; +import com.library.librarian.Librarian; +import com.library.member.Member; +import com.library.loan.Loan; +import com.library.book.Book; +import com.library.loanstatus.LoanStatus; +import java.time.LocalDate; +import java.util.*; + + + +public class LibraryApp { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + + //Member; + System.out.print("Member id: "); + int mid = Integer.parseInt(sc.nextLine()); + System.out.print("Member name"); + String mname = sc.nextLine(); + System.out.println("Member address"); + String maddress = sc.nextLine(); + Member member = new Member(mid,mname,maddress); + + //Book + System.out.println("Book ISBN: "); + String isbn = sc.nextLine(); + System.out.println("Book Title"); + String title = sc.nextLine(); + System.out.println("Book author"); + String author = sc.nextLine(); + Book book = new Book(isbn,title,author); + + + //Librarian + System.out.println("Librarian ID: "); + int lid = Integer.parseInt(sc.nextLine()); + System.out.println("Librarian Name: "); + String lname = sc.nextLine(); + Librarian librarian = new Librarian(lname, lid); + + + Loan loan = new Loan(1001,member, book); + System.out.println("\n records of the library"); + System.out.println(member); + System.out.println(book); + System.out.println(librarian); + System.out.println(loan); + + } +} \ No newline at end of file diff --git a/OOPClss/LibraryApp/src/com/library/book/Book.class b/OOPClss/LibraryApp/src/com/library/book/Book.class new file mode 100644 index 0000000..5aea8b8 Binary files /dev/null and b/OOPClss/LibraryApp/src/com/library/book/Book.class differ diff --git a/OOPClss/LibraryApp/src/com/library/book/Book.java b/OOPClss/LibraryApp/src/com/library/book/Book.java new file mode 100644 index 0000000..0d7d0e4 --- /dev/null +++ b/OOPClss/LibraryApp/src/com/library/book/Book.java @@ -0,0 +1,57 @@ +package com.library.book; + +public class Book{ + private String isbn; + private String title; + private String author; + private boolean available; + + public Book(String isbn, String title, String author) { + this.isbn = isbn; + this.title = title; + this.author = author; + } + + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public boolean isAvailable() { + return available; + } + + public void setAvailable(boolean available) { + this.available = available; + } + + @Override + public String toString() { + return "Book{" + + "isbn='" + isbn + '\'' + + ", title='" + title + '\'' + + ", author='" + author + '\'' + + ", available=" + available + + '}'; + } +} \ No newline at end of file diff --git a/OOPClss/LibraryApp/src/com/library/librarian/Librarian.class b/OOPClss/LibraryApp/src/com/library/librarian/Librarian.class new file mode 100644 index 0000000..60b6408 Binary files /dev/null and b/OOPClss/LibraryApp/src/com/library/librarian/Librarian.class differ diff --git a/OOPClss/LibraryApp/src/com/library/librarian/Librarian.java b/OOPClss/LibraryApp/src/com/library/librarian/Librarian.java new file mode 100644 index 0000000..5d31ea9 --- /dev/null +++ b/OOPClss/LibraryApp/src/com/library/librarian/Librarian.java @@ -0,0 +1,38 @@ +package com.library.librarian; + +public class Librarian { + private int employeeId; + private String name; + + public Librarian(String name, int employeeId) { + this.name = name; + this.employeeId = employeeId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getEmployeeId() { + return employeeId; + } + + public void setEmployeeId(int employeeId) { + this.employeeId = employeeId; + } + + @Override + public String toString() { + return String.format( + "Librarian[id=%d, name=%s]", + employeeId, name + ); + } + + + +} diff --git a/OOPClss/LibraryApp/src/com/library/loan/Loan.class b/OOPClss/LibraryApp/src/com/library/loan/Loan.class new file mode 100644 index 0000000..95318fc Binary files /dev/null and b/OOPClss/LibraryApp/src/com/library/loan/Loan.class differ diff --git a/OOPClss/LibraryApp/src/com/library/loan/Loan.java b/OOPClss/LibraryApp/src/com/library/loan/Loan.java new file mode 100644 index 0000000..584403f --- /dev/null +++ b/OOPClss/LibraryApp/src/com/library/loan/Loan.java @@ -0,0 +1,97 @@ +package com.library.loan; + +import com.library.book.Book; +import com.library.loanstatus.LoanStatus; +import com.library.member.Member; + +import java.time.LocalDate; + +public class Loan { + private int loanId; + private LocalDate loanDate; + private LocalDate dueDate; + private LoanStatus status; + private Member member; + private Book book; + + public Loan(int loanId, Member member, Book book) { + this(loanId,LocalDate.now(),LocalDate.now().plusWeeks(2),LoanStatus.BORROWED,member,book); + } + + public Loan(int loanId,LocalDate loanDate, LocalDate dueDate, LoanStatus status, Member member, Book book){ + this.loanId=loanId; + this.loanDate=loanDate; + this.dueDate=dueDate; + this.status=status; + this.member=member; + this.book=book; + } + + + + + + public int getLoanId() { + return loanId; + } + + public void setLoanId(int loanId) { + this.loanId = loanId; + } + + public LocalDate getLoanDate() { + return loanDate; + } + + public void setLoanDate(LocalDate loanDate) { + this.loanDate = loanDate; + } + + public LocalDate getDueDate() { + return dueDate; + } + + public void setDueDate(LocalDate dueDate) { + this.dueDate = dueDate; + } + + public LoanStatus getStatus() { + return status; + } + + public void setStatus(LoanStatus status) { + this.status = status; + } + + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } + + public Book getBook() { + return book; + } + + public void setBook(Book book) { + this.book = book; + } + + @Override + public String toString() { + return "Loan{" + + "loanId=" + loanId + + ", loanDate=" + loanDate + + ", dueDate=" + dueDate + + ", status=" + status + + ", member=" + member + + ", book=" + book + + '}'; + } + + + + +} diff --git a/OOPClss/LibraryApp/src/com/library/loanstatus/LoanStatus.class b/OOPClss/LibraryApp/src/com/library/loanstatus/LoanStatus.class new file mode 100644 index 0000000..d6e0c8d Binary files /dev/null and b/OOPClss/LibraryApp/src/com/library/loanstatus/LoanStatus.class differ diff --git a/OOPClss/LibraryApp/src/com/library/loanstatus/LoanStatus.java b/OOPClss/LibraryApp/src/com/library/loanstatus/LoanStatus.java new file mode 100644 index 0000000..b974e9a --- /dev/null +++ b/OOPClss/LibraryApp/src/com/library/loanstatus/LoanStatus.java @@ -0,0 +1,5 @@ +package com.library.loanstatus; + +public enum LoanStatus { + BORROWED,RETURNED,OVERDUE; +} diff --git a/OOPClss/LibraryApp/src/com/library/member/Member.class b/OOPClss/LibraryApp/src/com/library/member/Member.class new file mode 100644 index 0000000..666c369 Binary files /dev/null and b/OOPClss/LibraryApp/src/com/library/member/Member.class differ diff --git a/OOPClss/LibraryApp/src/com/library/member/Member.java b/OOPClss/LibraryApp/src/com/library/member/Member.java new file mode 100644 index 0000000..ef4bceb --- /dev/null +++ b/OOPClss/LibraryApp/src/com/library/member/Member.java @@ -0,0 +1,48 @@ +package com.library.member; + +public class Member { + private int memberId; + private String name; + private String address; + + public Member(int memberId, String name, String address) { + this.memberId = memberId; + this.name = name; + this.address = address; + } + + public int getMemberId() { + return memberId; + } + + public void setMemberId(int memberId) { + this.memberId = memberId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + return "Member{" + + "memberId=" + memberId + + ", name='" + name + '\'' + + ", address='" + address + '\'' + + '}'; + } + +} diff --git a/OOPClss/Member.java b/OOPClss/Member.java new file mode 100644 index 0000000..b4e825f --- /dev/null +++ b/OOPClss/Member.java @@ -0,0 +1,9 @@ +public class Member{ + public String name; + public int member_id; + + public void borrow(Book book){ + System.out.println("You borrowed the following: "+book+" today!"); + } + +} \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/.gitignore b/OOPClss/PayrollApp/untitled/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/PayrollApp/untitled/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/.idea/.gitignore b/OOPClss/PayrollApp/untitled/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/PayrollApp/untitled/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/PayrollApp/untitled/.idea/misc.xml b/OOPClss/PayrollApp/untitled/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/PayrollApp/untitled/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/.idea/modules.xml b/OOPClss/PayrollApp/untitled/.idea/modules.xml new file mode 100644 index 0000000..3007dae --- /dev/null +++ b/OOPClss/PayrollApp/untitled/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/.idea/vcs.xml b/OOPClss/PayrollApp/untitled/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/OOPClss/PayrollApp/untitled/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/src/Main.class b/OOPClss/PayrollApp/untitled/src/Main.class new file mode 100644 index 0000000..c588c17 Binary files /dev/null and b/OOPClss/PayrollApp/untitled/src/Main.class differ diff --git a/OOPClss/PayrollApp/untitled/src/Main.java b/OOPClss/PayrollApp/untitled/src/Main.java new file mode 100644 index 0000000..715833a --- /dev/null +++ b/OOPClss/PayrollApp/untitled/src/Main.java @@ -0,0 +1,12 @@ + + +import com.payroll.employee.Employee; + +public class Main { + public static void main(String[] args) + { + System.out.println("Hello, World!"); + Employee e1= new Employee("Mohammed", 525168, 5874.2, "financial", 5515886); + System.out.println(e1); + } +} \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/src/com/payroll/employee/Employee.class b/OOPClss/PayrollApp/untitled/src/com/payroll/employee/Employee.class new file mode 100644 index 0000000..178c18b Binary files /dev/null and b/OOPClss/PayrollApp/untitled/src/com/payroll/employee/Employee.class differ diff --git a/OOPClss/PayrollApp/untitled/src/com/payroll/employee/Employee.java b/OOPClss/PayrollApp/untitled/src/com/payroll/employee/Employee.java new file mode 100644 index 0000000..b729f02 --- /dev/null +++ b/OOPClss/PayrollApp/untitled/src/com/payroll/employee/Employee.java @@ -0,0 +1,23 @@ +package com.payroll.employee; + +public class Employee{ + private String name; + private int emp_id; + private double salary; + private String department; + private int SSN; + + public Employee(String name, int emp_id, double salary, String department, int SSN){ + this.name=name; + this.emp_id=emp_id; + this.salary=salary; + this.department=department; + this.SSN=SSN; + } + + @Override + public String toString(){ + return(name+" is an employee with id: "+emp_id+" and has a salary of "+salary+" and works in the "+department+" department and has a SSN: "+SSN+"."); + } + +} \ No newline at end of file diff --git a/OOPClss/PayrollApp/untitled/untitled.iml b/OOPClss/PayrollApp/untitled/untitled.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/PayrollApp/untitled/untitled.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/RideSharingApp/.gitignore b/OOPClss/RideSharingApp/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOPClss/RideSharingApp/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOPClss/RideSharingApp/.idea/.gitignore b/OOPClss/RideSharingApp/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOPClss/RideSharingApp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOPClss/RideSharingApp/.idea/misc.xml b/OOPClss/RideSharingApp/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/OOPClss/RideSharingApp/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/RideSharingApp/.idea/modules.xml b/OOPClss/RideSharingApp/.idea/modules.xml new file mode 100644 index 0000000..7471a67 --- /dev/null +++ b/OOPClss/RideSharingApp/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOPClss/RideSharingApp/.idea/vcs.xml b/OOPClss/RideSharingApp/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/OOPClss/RideSharingApp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOPClss/RideSharingApp/RideSharingApp.iml b/OOPClss/RideSharingApp/RideSharingApp.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOPClss/RideSharingApp/RideSharingApp.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/driver/Driver.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/driver/Driver.java new file mode 100644 index 0000000..99aa702 --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/driver/Driver.java @@ -0,0 +1,53 @@ +package com.ridesharingapp.entities.driver; + +public class Driver { + private String name; + private String phoneNum; + private Boolean isAvailable; + + public Driver(String name, String phoneNum, Boolean isAvailable){ + this.name=name; + this.phoneNum=phoneNum; + this.isAvailable=isAvailable; + } + + public Driver(String name,String phoneNum){ + this.name=name; + this.phoneNum=phoneNum; + this.isAvailable=false; + } + + public String getName(){ + return name; + } + + public void setName(String name){ + this.name= name; + } + + public String getPhoneNum(){ + return phoneNum; + } + + public void setPhoneNum(String phoneNum){ + this.phoneNum=phoneNum; + } + + public void setAvailable(Boolean available) { + isAvailable = available; + } + + public Boolean isAvailable(){ + return isAvailable; + } + @Override + public String toString() { + return "Driver{" + + "name='" + name + '\'' + + ", phoneNum='" + phoneNum + '\'' + + ", isAvailable=" + isAvailable + + '}'; + } + + +} diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/rider/Rider.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/rider/Rider.java new file mode 100644 index 0000000..9e2fa2f --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/rider/Rider.java @@ -0,0 +1,52 @@ +package com.ridesharingapp.entities.rider; + +public class Rider { + private String name; + private String location; + private String email; + private String phoneNum; + + + public Rider(String name, String location, String email){ + this.name=name; + this.location=location; + this.phoneNum="N/A"; + this.email=email; + } + + public Rider(String name,String location,String email,String phoneNum){ + this.name=name; + this.location=location; + this.email=email; + this.phoneNum=phoneNum; + } + + public String getName(){ + return name; + } + + public void setName(String name){ + this.name=name; + } + + public String getLocation(){ + return location; + } + + public void setLocation(String location){ + this.location=location; + } + + public String getPhoneNum(){ + return phoneNum; + } + + public void setPhoneNum(String phoneNum){ + this.phoneNum=phoneNum; + } + + @Override + public String toString(){ + return("A new Rider has been created who's name is: "+this.name+" and lives at "+this.location+" and can be reached at: "+this.phoneNum+" and his email is: "+this.email); + } +} diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/trip/Trip.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/trip/Trip.java new file mode 100644 index 0000000..5d20307 --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/trip/Trip.java @@ -0,0 +1,93 @@ +package com.ridesharingapp.entities.trip; + +import com.ridesharingapp.entities.driver.Driver; +import com.ridesharingapp.entities.rider.Rider; +import com.ridesharingapp.entities.vehicle.Vehicle; +import com.ridesharingapp.entities.tripstatus.TripStatus; +import java.time.LocalDateTime; + +public class Trip { + private int tripId; + private Rider rider; + private Driver driver; + private Vehicle vehicle; + private LocalDateTime startTime; + private TripStatus status; + + public Trip(int tripId, Rider rider, Driver driver, Vehicle vehicle, LocalDateTime startTime, TripStatus status) { + this.tripId = tripId; + this.rider = rider; + this.driver = driver; + this.vehicle = vehicle; + this.startTime = startTime; + this.status = status; + } + + // Unassigned trip + public Trip(int tripId, Rider rider, LocalDateTime startTime, TripStatus status) { + this.tripId = tripId; + this.rider = rider; + this.driver = null; + this.vehicle = null; + this.startTime = startTime; + this.status = status; + } + + public int getTripId() { + return tripId; + } + + public void setTripId(int tripId) { + this.tripId = tripId; + } + + public Rider getRider() { + return rider; + } + + public void setRider(Rider rider) { + this.rider = rider; + } + + public Driver getDriver() { + return driver; + } + + public void setDriver(Driver driver) { + this.driver = driver; + } + + public Vehicle getVehicle() { + return vehicle; + } + + public void setVehicle(Vehicle vehicle) { + this.vehicle = vehicle; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + + public TripStatus getStatus() { + return status; + } + + public void setStatus(TripStatus status) { + this.status = status; + } + + @Override + public String toString() { + return "Trip{tripId=" + tripId + + ", rider=" + (rider != null ? rider.getName() : "None") + + ", driver=" + (driver != null ? driver.getName() : "None") + + ", vehicle=" + (vehicle != null ? vehicle.getModel() : "None") + + ", startTime=" + startTime + + ", status=" + status + "}"; + } +} \ No newline at end of file diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/tripstatus/TripStatus.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/tripstatus/TripStatus.java new file mode 100644 index 0000000..49ab1df --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/tripstatus/TripStatus.java @@ -0,0 +1,18 @@ +package com.ridesharingapp.entities.tripstatus; + +public enum TripStatus { + REQUESTED("Trip requested by driver"), + ASSIGNED("Trip assigned to driver"), + IN_PROGRESS("Trip in progress"), + COMPLETED("Trip completed"); + + public final String description; + + TripStatus(String description){ + this.description=description; + } + + public String getDescription(){ + return description; + } +} diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/vehicle/Vehicle.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/vehicle/Vehicle.java new file mode 100644 index 0000000..13d3ba3 --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/entities/vehicle/Vehicle.java @@ -0,0 +1,49 @@ +package com.ridesharingapp.entities.vehicle; + +public class Vehicle { + private String model; + private String licensePlate; + private String color; + + public Vehicle(String model, String licensePlate, String color) + { + this.model=model; + this.licensePlate=licensePlate; + this.color=color; + } + + @Override + public String toString() { + return "Vehicle{" + + "model='" + model + '\'' + + ", licensePlate='" + licensePlate + '\'' + + ", color='" + color + '\'' + + '}'; + } + + public void setModel(String model){ + this.model=model; + } + + public String getModel(){ + return model; + } + + public String getLicensePlate(){ + return licensePlate; + } + + public void setLicensePlate(String licensePlate){ + this.licensePlate=licensePlate; + } + + public String getColor(){ + return color; + } + + public void setColor(String color){ + this.color=color; + } + + +} diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/main/Menu.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/main/Menu.java new file mode 100644 index 0000000..f260d21 --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/main/Menu.java @@ -0,0 +1,111 @@ +package com.ridesharingapp.main; + + +import com.ridesharingapp.entities.rider.Rider; +import com.ridesharingapp.entities.driver.Driver; +import com.ridesharingapp.entities.vehicle.Vehicle; +import com.ridesharingapp.entities.trip.Trip; +import com.ridesharingapp.entities.tripstatus.TripStatus; +import java.util.Scanner; +import java.time.LocalDateTime; + +public class Menu { + private Trip currentTrip; + private Scanner scanner; + + public Menu(Trip initialTrip) { + this.currentTrip = null; + } + + public void run() { + while (true) { + System.out.println("\nRideSharingApp Menu:"); + System.out.println("1. Create a new trip"); + System.out.println("2. Assign a driver and vehicle to a trip"); + System.out.println("3. Update trip status"); + System.out.println("4. Exit"); + System.out.print("Choose an option: "); + + int choice; + try { + choice = scanner.nextInt(); + scanner.nextLine(); // Consume newline + } catch (Exception e) { + System.out.println("Invalid input. Please enter a number."); + scanner.nextLine(); + continue; + } + + if (choice == 1) { + System.out.print("Enter trip ID: "); + int tripId; + try { + tripId = scanner.nextInt(); + scanner.nextLine(); + } catch (Exception e) { + System.out.println("Invalid trip ID. Please enter a number."); + scanner.nextLine(); + continue; + } + System.out.print("Enter rider name: "); + String riderName = scanner.nextLine(); + System.out.print("Enter rider location: "); + String riderLocation = scanner.nextLine(); + System.out.print("Enter rider email: "); + String riderEmail = scanner.nextLine(); + + Rider newRider = new Rider(riderName, riderLocation, riderEmail); + currentTrip = new Trip(tripId, newRider, null, null, LocalDateTime.now(), TripStatus.REQUESTED); + System.out.println("New trip created: " + currentTrip.toString()); + + } else if (choice == 2) { + System.out.print("Enter driver name: "); + String driverName = scanner.nextLine(); + System.out.print("Enter driver phone: "); + String driverPhone = scanner.nextLine(); + System.out.print("Is driver available (true/false): "); + boolean isAvailable; + try { + isAvailable = scanner.nextBoolean(); + scanner.nextLine(); + } catch (Exception e) { + System.out.println("Invalid input. Please enter true or false."); + scanner.nextLine(); + continue; + } + System.out.print("Enter vehicle model: "); + String vehicleModel = scanner.nextLine(); + System.out.print("Enter vehicle license plate: "); + String licensePlate = scanner.nextLine(); + System.out.print("Enter vehicle color: "); + String vehicleColor = scanner.nextLine(); + + Driver newDriver = new Driver(driverName, driverPhone, isAvailable); + Vehicle newVehicle = new Vehicle(vehicleModel, licensePlate, vehicleColor); + currentTrip.setDriver(newDriver); + currentTrip.setVehicle(newVehicle); + currentTrip.setStatus(TripStatus.ASSIGNED); + System.out.println("Driver and vehicle assigned to trip: " + currentTrip.toString()); + + } else if (choice == 3) { + System.out.println("Available statuses: REQUESTED, ASSIGNED, IN_PROGRESS, COMPLETED"); + System.out.print("Enter new status for the current trip: "); + String statusInput = scanner.nextLine().toUpperCase(); + try { + TripStatus newStatus = TripStatus.valueOf(statusInput); + currentTrip.setStatus(newStatus); + System.out.println("Updated trip: " + currentTrip.toString()); + } catch (IllegalArgumentException e) { + System.out.println("Invalid status entered. Please use REQUESTED, ASSIGNED, IN_PROGRESS, or COMPLETED."); + } + + } else if (choice == 4) { + System.out.println("Exiting RideSharingApp."); + scanner.close(); + break; + } else { + System.out.println("Invalid option. Please try again."); + } + } + } +} \ No newline at end of file diff --git a/OOPClss/RideSharingApp/src/com/ridesharingapp/main/RideSharingApp.java b/OOPClss/RideSharingApp/src/com/ridesharingapp/main/RideSharingApp.java new file mode 100644 index 0000000..544b239 --- /dev/null +++ b/OOPClss/RideSharingApp/src/com/ridesharingapp/main/RideSharingApp.java @@ -0,0 +1,40 @@ +package com.ridesharingapp.main; + +import com.ridesharingapp.entities.rider.Rider; +import com.ridesharingapp.entities.driver.Driver; +import com.ridesharingapp.entities.vehicle.Vehicle; +import com.ridesharingapp.entities.trip.Trip; +import com.ridesharingapp.entities.tripstatus.TripStatus; + + +import java.time.LocalDateTime; + +public class RideSharingApp { + public static void main(String[] args) { + // Create sample objects + Rider rider1 = new Rider("Alice Brown", "123 Elm St", "alice@example.com"); + Rider rider2 = new Rider("Bob Wilson", "456 Pine Rd", "bob@example.com", "555-1234"); + + Driver driver1 = new Driver("Charlie Davis", "555-5678", true); + Driver driver2 = new Driver("Diana Evans", "555-9012"); + + Vehicle vehicle1 = new Vehicle("Toyota Camry", "XYZ-123", "Blue"); + Vehicle vehicle2 = new Vehicle("Honda Accord", "ABC-456", "Blue"); + + Trip trip1 = new Trip(1, rider1, null, null, LocalDateTime.now(), TripStatus.REQUESTED); + + // Display initial object states + System.out.println("\nInitial Object States:"); + System.out.println(rider1.toString()); + System.out.println(rider2.toString()); + System.out.println(driver1.toString()); + System.out.println(driver2.toString()); + System.out.println(vehicle1.toString()); + System.out.println(vehicle2.toString()); + System.out.println(trip1.toString()); + + // Start the menu + Menu menu = new Menu(trip1); + menu.run(); + } +} \ No newline at end of file diff --git a/OOPClss/SimpleOrderRegistry/.idea/workspace.xml b/OOPClss/SimpleOrderRegistry/.idea/workspace.xml new file mode 100644 index 0000000..e6f747a --- /dev/null +++ b/OOPClss/SimpleOrderRegistry/.idea/workspace.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1751044964396 + + + + \ No newline at end of file diff --git a/OOPClss/StudentApp/StudentApp/pom.xml b/OOPClss/StudentApp/StudentApp/pom.xml new file mode 100644 index 0000000..031ecd7 --- /dev/null +++ b/OOPClss/StudentApp/StudentApp/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + aui.students + StudentApp + 1.0-SNAPSHOT + jar + + UTF-8 + 23 + aui.students.studentapp.StudentApp + + \ No newline at end of file diff --git a/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/AcademicStatus.java b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/AcademicStatus.java new file mode 100644 index 0000000..d9a9a1e --- /dev/null +++ b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/AcademicStatus.java @@ -0,0 +1,10 @@ + +package aui.students.studentapp; + + +public enum AcademicStatus { + FRESHMAN, + SOPHOMORE, + JUNIOR, + SENIOR; +} diff --git a/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/Address.java b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/Address.java new file mode 100644 index 0000000..78bcfc5 --- /dev/null +++ b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/Address.java @@ -0,0 +1,90 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package aui.students.studentapp; + + +public class Address { + private int street_num; + private String street_name; + private String city; + private String country; + private int zip_code; + + public Address(int street_num, String street_name, String city, String country, int zip_code) { + this.street_num = street_num; + this.street_name = street_name; + this.city = city; + this.country = country; + this.zip_code = zip_code; + } + + + + + public int getStreet_num() { + return street_num; + } + + + public void setStreet_num(int street_num) { + this.street_num = street_num; + } + + + public String getStreet_name() + { + return street_name; + } + + + public void setStreet_name(String street_name) + { + this.street_name = street_name; + } + + + public String getCity() + { + return city; + } + + + public void setCity(String city) + { + this.city = city; + } + + + public String getCountry() + { + return country; + } + + + public void setCountry(String country) + { + this.country = country; + } + + + public int getZip_code() + { + return zip_code; + } + + + public void setZip_code(int zip_code) + { + this.zip_code = zip_code; + } + + @Override + public String toString() + { + return " "+street_num+", "+street_name+" "+city+" "+country+" "+zip_code; + } + + +} diff --git a/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/Student.java b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/Student.java new file mode 100644 index 0000000..d103940 --- /dev/null +++ b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/Student.java @@ -0,0 +1,100 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package aui.students.studentapp; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * + * @author Oumaima Hourrane + */ +public class Student { + //Fields + private String name; + private double gpa; + private int credits; + private LocalDate date; + private Address adds; //association (0..1) + private AcademicStatus status; //association + + //constructors + public Student(String name, double gpa, int credits ){ + this.name = name; + this.credits = credits; + this.gpa = gpa; + } + + public Student(String name, double gpa, int credits, String date, Address adds) { + this(name, gpa, credits); //always call the base constructor + setDate(date); + this.adds = adds; + } + + public Student(String name, double gpa, int credits, String status) { + this(name, gpa, credits); //always call the base constructor + this.status = AcademicStatus.valueOf(status.toUpperCase()); + } + + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public double getGpa() { + return gpa; + } + + /** + * @param gpa the gpa to set + */ + public void setGpa(double gpa) { + this.gpa = gpa; + } + + + public int getCredits() { + return credits; + } + + + public void setCredits(int credits) { + this.credits = credits; + } + + + + public LocalDate getDate() { + return date; + } + + public void setDate(String date) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + this.date = LocalDate.parse(date, formatter); + } + + + @Override + public String toString() + { + String str = "Student "+name+", has credits: "+credits+", and gpa "+gpa; + if (date != null) { + str += ". Student's birthday is "+date.format(DateTimeFormatter.ofPattern("MM/dd/yyyy")); + } + if (adds!=null){ + str += ". Student's address:"+adds.toString(); + } + if (status != null) { + str += ". Academic status: " + status.name(); + } + return str; + } +} diff --git a/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/StudentApp.java b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/StudentApp.java new file mode 100644 index 0000000..b3658d8 --- /dev/null +++ b/OOPClss/StudentApp/StudentApp/src/main/java/aui/students/studentapp/StudentApp.java @@ -0,0 +1,105 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package aui.students.studentapp; + +import java.util.Scanner; + + + +public class StudentApp { + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + + // Prompt for student 1 (without birthdate and address) + System.out.println("Enter details for student 1:"); + System.out.print("Name: "); + String name1 = scanner.nextLine(); + + System.out.print("GPA: "); + double gpa1 = scanner.nextDouble(); + + System.out.print("Credits: "); + int credits1 = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + Student stud1 = new Student(name1, gpa1, credits1); + System.out.println(stud1); // Print student 1 info + + + + // Prompt for student 2 (with birthdate and address) + System.out.println("\n Enter details for student 2:"); + + System.out.print("Name: "); + String name2 = scanner.nextLine(); //gets + + //for character next char + + System.out.print("GPA: "); + double gpa2 = scanner.nextDouble(); + + System.out.print("Credits: "); + int credits2 = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + System.out.print("Birthdate (MM/dd/yyyy): "); + String birthDate2 = scanner.nextLine(); + + // Prompt for address + System.out.println("\n Enter address details for student 2:"); + + System.out.print("Street Number: "); + int streetNumber = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + System.out.print("Street Name: "); + String streetName = scanner.nextLine(); + + System.out.print("City: "); + String city = scanner.nextLine(); + + System.out.print("Country: "); + String country = scanner.nextLine(); + + System.out.print("Postal Code: "); + int postalCode = scanner.nextInt(); + + // Create address object + Address address = new Address(streetNumber, streetName, city, country, postalCode); + + // Create student 2 object + Student stud2 = new Student(name2, gpa2, credits2, birthDate2, address); + System.out.println(stud2); // Print student 2 info + + + // Prompt for student 3 (with academic status) + System.out.println("\n Enter details for student 3:"); + + System.out.print("Name: "); + scanner.nextLine(); // Clear the newline before the next input + String name3 = scanner.nextLine(); + + System.out.print("GPA: "); + double gpa3 = scanner.nextDouble(); + + System.out.print("Credits: "); + int credits3 = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + // Prompt for academic status + System.out.println("Academic Status (FRESHMAN, SOPHOMORE, JUNIOR, SENIOR): "); + String status3 = scanner.nextLine().toUpperCase(); + + // Create student 3 object + Student stud3 = new Student(name3, gpa3, credits3, status3); + System.out.println(stud3); // Print student 3 info + + // Close scanner + scanner.close(); + + } +} diff --git a/OOPClss/genericsexample/StudentApp (1)/StudentApp/pom.xml b/OOPClss/genericsexample/StudentApp (1)/StudentApp/pom.xml new file mode 100644 index 0000000..031ecd7 --- /dev/null +++ b/OOPClss/genericsexample/StudentApp (1)/StudentApp/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + aui.students + StudentApp + 1.0-SNAPSHOT + jar + + UTF-8 + 23 + aui.students.studentapp.StudentApp + + \ No newline at end of file diff --git a/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/PrintingUsingOverloadedMethods.java b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/PrintingUsingOverloadedMethods.java new file mode 100644 index 0000000..1282a92 --- /dev/null +++ b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/PrintingUsingOverloadedMethods.java @@ -0,0 +1,23 @@ + +package genericsexample; + +import java.aui.students.studentapp.Student; +import java.aui.students.studentapp.Address; + + +public class PrintingUsingOverloadedMethods { + + + public static StringBuilder printArray(T[] array){ + StringBuilder result = new StringBuilder(); + for(T element: array){ + result.append(element).append(" "); + } + return result.toString().trim(); + } + + public static void main(String[] args) { + Student [] studentArray = { new Student("Alice",3.5,40), new Student("Bob",3.5,85)}; + printArray(studentArray); + } +} diff --git a/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/AcademicStatus.java b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/AcademicStatus.java new file mode 100644 index 0000000..778679e --- /dev/null +++ b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/AcademicStatus.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package aui.students.studentapp; + +/** + * + * @author Oumaima Hourrane + */ +public enum AcademicStatus { + FRESHMAN, + SOPHOMORE, + JUNIOR, + SENIOR; +} diff --git a/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/Address.java b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/Address.java new file mode 100644 index 0000000..c5a4c06 --- /dev/null +++ b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/Address.java @@ -0,0 +1,104 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package aui.students.studentapp; + +/** + * + * @author Oumaima Hourrane + */ +public class Address { + private int street_num; + private String street_name; + private String city; + private String country; + private int zip_code; + + public Address(int street_num, String street_name, String city, String country, int zip_code) { + this.street_num = street_num; + this.street_name = street_name; + this.city = city; + this.country = country; + this.zip_code = zip_code; + } + + + + /** + * @return the street_num + */ + public int getStreet_num() { + return street_num; + } + + /** + * @param street_num the street_num to set + */ + public void setStreet_num(int street_num) { + this.street_num = street_num; + } + + /** + * @return the street_name + */ + public String getStreet_name() { + return street_name; + } + + /** + * @param street_name the street_name to set + */ + public void setStreet_name(String street_name) { + this.street_name = street_name; + } + + /** + * @return the city + */ + public String getCity() { + return city; + } + + /** + * @param city the city to set + */ + public void setCity(String city) { + this.city = city; + } + + /** + * @return the country + */ + public String getCountry() { + return country; + } + + /** + * @param country the country to set + */ + public void setCountry(String country) { + this.country = country; + } + + /** + * @return the zip_code + */ + public int getZip_code() { + return zip_code; + } + + /** + * @param zip_code the zip_code to set + */ + public void setZip_code(int zip_code) { + this.zip_code = zip_code; + } + + @Override + public String toString() { + return " "+street_num+", "+street_name+" "+city+" "+country+" "+zip_code; // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody + } + + +} diff --git a/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/Student.java b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/Student.java new file mode 100644 index 0000000..03510a4 --- /dev/null +++ b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/Student.java @@ -0,0 +1,119 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package aui.students.studentapp; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * + * @author Oumaima Hourrane + */ + + +public class Student implements Printable{ + //Fields + private String name; + private double gpa; + private int credits; + private LocalDate date; + private Address adds; //association (0..1) + private AcademicStatus status; //association + + //constructors + public Student(String name, double gpa, int credits ){ + this.name = name; + this.credits = credits; + this.gpa = gpa; + } + + public Student(String name, double gpa, int credits, String date, Address adds) { + this (name, gpa, credits); + setDate(date); + this.adds = adds; + } + + public Student(String name, double gpa, int credits, String status) { + this (name, gpa, credits); + this.status = AcademicStatus.valueOf(status.toUpperCase()); + } + + + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the gpa + */ + public double getGpa() { + return gpa; + } + + /** + * @param gpa the gpa to set + */ + public void setGpa(double gpa) { + this.gpa = gpa; + } + + /** + * @return the credits + */ + public int getCredits() { + return credits; + } + + /** + * @param credits the credits to set + */ + public void setCredits(int credits) { + this.credits = credits; + } + + /** + * @return the date + */ + public LocalDate getDate() { + return date; + } + + /** + * @param date the date to set + */ + public void setDate(String date) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + this.date = LocalDate.parse(date, formatter); + } + + @Override + public String toString() { + String str = "Student "+name+", has credits: "+credits+", and gpa "+gpa; + + if (date != null) { + str += ". Student's birthday is "+date.format(DateTimeFormatter.ofPattern("MM/dd/yyyy")); + } + + if (adds!=null){ + str += ". Student's address:"+adds.toString(); + } + if (status != null) { + str += ". Academic status: " + status.name(); + } + + + return str; + } +} diff --git a/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/StudentApp.java b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/StudentApp.java new file mode 100644 index 0000000..c6303b3 --- /dev/null +++ b/OOPClss/genericsexample/StudentApp (1)/StudentApp/src/main/java/aui/students/studentapp/StudentApp.java @@ -0,0 +1,104 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package aui.students.studentapp; + +import java.util.Scanner; + + +/** + * + * @author Oumaima Hourrane + */ +public class StudentApp { + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + + // Prompt for student 1 (without birthdate and address) + System.out.println("Enter details for student 1:"); + System.out.print("Name: "); + String name1 = scanner.nextLine(); + + System.out.print("GPA: "); + double gpa1 = scanner.nextDouble(); + + System.out.print("Credits: "); + int credits1 = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + Student stud1 = new Student(name1, gpa1, credits1); + System.out.println(stud1); // Print student 1 info + + // Prompt for student 2 (with birthdate and address) + System.out.println("\n Enter details for student 2:"); + + System.out.print("Name: "); + String name2 = scanner.nextLine(); + + System.out.print("GPA: "); + double gpa2 = scanner.nextDouble(); + + System.out.print("Credits: "); + int credits2 = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + System.out.print("Birthdate (MM/dd/yyyy): "); + String birthDate2 = scanner.nextLine(); + + // Prompt for address + System.out.println("\n Enter address details for student 2:"); + + System.out.print("Street Number: "); + int streetNumber = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + System.out.print("Street Name: "); + String streetName = scanner.nextLine(); + + System.out.print("City: "); + String city = scanner.nextLine(); + + System.out.print("Country: "); + String country = scanner.nextLine(); + + System.out.print("Postal Code: "); + int postalCode = scanner.nextInt(); + + // Create address object + Address address = new Address(streetNumber, streetName, city, country, postalCode); + + // Create student 2 object + Student stud2 = new Student(name2, gpa2, credits2, birthDate2, address); + System.out.println(stud2); // Print student 2 info + + + // Prompt for student 3 (with academic status) + System.out.println("\n Enter details for student 3:"); + + System.out.print("Name: "); + scanner.nextLine(); // Clear the newline before the next input + String name3 = scanner.nextLine(); + + System.out.print("GPA: "); + double gpa3 = scanner.nextDouble(); + + System.out.print("Credits: "); + int credits3 = scanner.nextInt(); + scanner.nextLine(); // consume the newline + + // Prompt for academic status + System.out.println("Academic Status (FRESHMAN, SOPHOMORE, JUNIOR, SENIOR): "); + String status3 = scanner.nextLine().toUpperCase(); + + // Create student 3 object + Student stud3 = new Student(name3, gpa3, credits3, status3); + System.out.println(stud3); // Print student 3 info + + // Close scanner + scanner.close(); + + } +} diff --git a/README.md b/README.md index 04e7a6a..6e9f0c8 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ 6. UI: How We Present the data +### == vs .equals() + +- ==: compares content and reference +- .equals(): compares just the content + ## Class Naming is Pascal Case The case name is = to 2526 fav programming language and fav screen color: ```java class PascalCase{} @@ -26,9 +31,9 @@ ## Method Naming is Camel Case: ```java public void theBestMethod() -{ - logln("2526: 727225, 27736259, 27429, 27375, 746867 ARE THE BEST THINGS EVER and 557 AKA LLP Prog is also my fav!!!"); -} + { + logln("2526: 727225, 27736259, 27429, 27375, 746867 ARE THE BEST THINGS EVER and 557 AKA LLP Prog is also my fav!!!"); + } ``` ## Data Structures @@ -36,18 +41,19 @@ public void theBestMethod() #### Primitive DS: 1. Integer 2. Float -3. Char` +3. Char 4. Pointers + #### Non-Primitive DS: 1. Arrays 2. List - - Linear: - - Stacks - - Queues - - Non-Linear: - - Graphs - - Trees + - Linear: + - Stacks + - Queues + - Non-Linear: + - Graphs + - Trees @@ -71,16 +77,16 @@ $~ java callingProgram.java MethodProgram.java ## What is the "this" keyword in Java and why do we use it ```java class NelanLvsBDAndCSunAndFTN{ - int cobolfb = 2626532; - int pascalfb= 72722532; - - public void setVals(int cobolfb, int pascalfb){ + int cobolfb = 2626532; + int pascalfb= 72722532; + + public void setVals(int cobolfb, int pascalfb){ /*here is where the this keyword comes to play to tell java that I want to use the parameter of my function aka local variables and not the instance variables(up top) */ - this.cobolfb = cobolfb; - this.pascalfb = pascalfb; - } + this.cobolfb = cobolfb; + this.pascalfb = pascalfb; + } } ``` @@ -92,14 +98,14 @@ class NelanLvsBDAndCSunAndFTN{ Raised when you try to call an undeclared variable ```java public class Omar{ - public static void main(String [] args) - { - int a = 1; - int b= 2; - int c= 3; - mean = (a+b+c)/2; - System.out.println(mean); - } + public static void main(String [] args) + { + int a = 1; + int b= 2; + int c= 3; + mean = (a+b+c)/2; + System.out.println(mean); + } } ``` @@ -107,30 +113,30 @@ In line 8 we try to print to the console mean we have set the value of mean but To solve we do this ```java public class Omar{ - public static void main(String [] args) - { - int a = 1; - int b= 2; - int c= 3; - double mean = (a+b+c)/2; - System.out.println(mean); - } + public static void main(String [] args) + { + int a = 1; + int b= 2; + int c= 3; + double mean = (a+b+c)/2; + System.out.println(mean); + } } ``` ### 2- cannot find symbol PART 2 Raised when you try to call an undeclared variable ```java public class Great{ - public static void main(String [] args) - { - the_best_method; - } - - public static void the_best_method() - { + public static void main(String [] args) + { + the_best_method; + } + + public static void the_best_method() + { System.out.println("This is the best method in the world"); - } - + } + } ``` @@ -138,41 +144,41 @@ In line 4 we are incorrectly calling the_best_method but we forget the parenthes ```java public class Great{ - public static void main(String [] args) - { - the_best_method(); - } - - public static void the_best_method() - { + public static void main(String [] args) + { + the_best_method(); + } + + public static void the_best_method() + { System.out.println("This is the best method in the world"); - } - + } + } ``` -### 3- cannot find symbol : -### symbol: class Scanner +### 3- cannot find symbol : +### symbol: class Scanner ### location: class Great Raised when you are using the scanner ```java public class Great{ - public static void main(String [] args) - { - Scanner useInput= new Scanner(); // scanner is not imported - int l = useInput.nextInt(); - } + public static void main(String [] args) + { + Scanner useInput= new Scanner(); // scanner is not imported + int l = useInput.nextInt(); + } } ``` -In line 4 we are using the scanner but we never imported the library that enables us to use it +In line 4 we are using the scanner but we never imported the library that enables us to use it ```java import java.util.Scanner; public class Great{ - public static void main(String [] args) - { - Scanner useInput= new Scanner(); // scanner has no default constructor - int l = useInput.nextInt(); - } + public static void main(String [] args) + { + Scanner useInput= new Scanner(); // scanner has no default constructor + int l = useInput.nextInt(); + } } ``` @@ -181,10 +187,10 @@ public class Great{ ```java public class Thebest -{ - public static void main(String[] args) { - System.out.println("Hello, world!"); - } +{ + public static void main(String[] args) { + System.out.println("Hello, world!"); + } } ``` ## SOOO, I save the file and I name it Lemon.java well, it will error because our class is Thebest so that means our file name should be Thebest.java @@ -195,22 +201,22 @@ This error is raised when I try to write code outside of a method which is unint ```java public class Test { System.out.println("Hello!"); - - public static void main(String[] args) { - System.out.println("World!"); - } - } + + public static void main(String[] args) { + System.out.println("World!"); + } +} ``` - + To fix I just place the print Statement of hello inside of main ```java - public class Test { - public static void main(String[] args) { - System.out.println("Hello!"); - System.out.println("World!"); - } - } + public class Test { + public static void main(String[] args) { + System.out.println("Hello!"); + System.out.println("World!"); + } +} ``` ### 6- illegal start of expression @@ -218,29 +224,29 @@ To fix I just place the print Statement of hello inside of main An "illegal start of expression" error occurs when the compiler when we start a expression before closing the previous one. ```java public class Test { - public static void main(String[] args) { - my_method(); - - - public static void my_method() { - System.out.println("Hello, world!"); - } - } + public static void main(String[] args) { + my_method(); + + + public static void my_method() { + System.out.println("Hello, world!"); + } + } ``` To fix this piece of code, I simply add a closing curly brace for the main method. To know we are doing the right thing, just look at the lines of code before the error, there may be a missing closing paranthesis or a missing closing curly brace. This would give us what the error is. ```java public class Test { - public static void main(String[] args) - { - my_method(); - } - - public static void my_method() - { - System.out.println("Hello, EVERYONEEEE!"); - } + public static void main(String[] args) + { + my_method(); + } + + public static void my_method() + { + System.out.println("Hello, EVERYONEEEE!"); + } } ``` @@ -248,12 +254,12 @@ public class Test The incompatible types error is raised when we are facing with data type errors. We can overcome this, by converting say a char to an int. We can convert a double to an integer with typecasting. BUt WE CANNOT convert between primitive types and objects. A primitive type is say a: null, undefined, boolean, number, string or char. However objects can be: Arrays, Maps, Sets, Functions, Regular Expression or Date.. ```java -public class Test +public class Test { - public static void main(String[] args) - { - int num = "Hello, world!"; - } + public static void main(String[] args) + { + int num = "Hello, world!"; + } } ``` The above code is an error because we are assigning the string Hello World to the variable num of type int. @@ -262,24 +268,24 @@ Step 1: Change the String value from Hello, world! to 500 ```java public class Test { - public static void main(String[] args) - { - int num = "500"; - } + public static void main(String[] args) + { + int num = "500"; + } } ``` - + Step 2: Use parsing to convert the string to an integer ```java public class Test { - public static void main(String[] args) - { - int num = Integer.parseInt("500"); - } + public static void main(String[] args) + { + int num = Integer.parseInt("500"); + } } ``` - + ### 8- invalid method declaration; return type required @@ -289,16 +295,16 @@ When a method declaration does not contain a return type, this error will occur: ```java public class Test { - public static void main(String[] args) - { - int x = getValue(); - System.out.println(x); - } - - public static getValue() - { - return 10; - } + public static void main(String[] args) + { + int x = getValue(); + System.out.println(x); + } + + public static getValue() + { + return 10; + } } @@ -307,48 +313,48 @@ To fix this, simply insert the appropriate return type in the method signature a ```java -public class Test +public class Test { - public static void main(String[] args) - { - int x = getValue(); - System.out.println(x); - } - - public static int getValue() - { - return 10; - } + public static void main(String[] args) + { + int x = getValue(); + System.out.println(x); + } + + public static int getValue() + { + return 10; + } } ``` ### 9-java.lang.ArrayIndexOutOfBoundsException: -An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an index in an array that is not valid. This means that say an array has 8 elements and we know that the number of elements in index is 7. We start counting at 0. So, if I enter a value of 8 or greater to access, this will raise an error. +An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an index in an array that is not valid. This means that say an array has 8 elements and we know that the number of elements in index is 7. We start counting at 0. So, if I enter a value of 8 or greater to access, this will raise an error. ```java public class Test { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - for (int i = 0; i <= arr.length; i++) { - System.out.println(arr[i]); - } - } - } + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + for (int i = 0; i <= arr.length; i++) { + System.out.println(arr[i]); + } + } +} ``` The code above errored due to the for loop iteration settings. The first element is index 0 which is fine however, the function's output of arr.length of our array named arr of type int is 3. However, we are using the comparison operator of <=. This means less than or equal to. If, we change it to < it will not error. The equal means it will try to access index 3 which is the 4th item in the array which we do not have. ```java public class Test { - public static void main(String[] args) { - int[] arr = {1, 2, 3}; - for (int i = 0; i < arr.length; i++) { - System.out.println(arr[i]); - } - } + public static void main(String[] args) { + int[] arr = {1, 2, 3}; + for (int i = 0; i < arr.length; i++) { + System.out.println(arr[i]); + } + } } ``` -### 10- StringIndexOutOfBoundsException -The exception StringIndexOutOfBoundsException is thrown to the console when an attempt is made to access an index in +### 10- StringIndexOutOfBoundsException +The exception StringIndexOutOfBoundsException is thrown to the console when an attempt is made to access an index in the String that is not valid. The only valid index of the String we can access is from 0 to the (length of the String-1). This means that if the array 8 elements. The biggest number I can access is 7 not 8. If we enter any number greater than 7 for access will throws an outofBoundsException. This is an error in runtime not compile-time. It is accepted by the compiler because it is a logical error ``` java @@ -370,16 +376,16 @@ To fix this I simply change the String a declaration in line 7 from index -1 to Therefore the bottom code is bug free ```java -public class Test +public class Test { - public static void main(String[] args) - { - String str = "Hello, world!"; + public static void main(String[] args) + { + String str = "Hello, world!"; - String a = str.substring(1, 3); - char b = str.charAt((str.length())-1); - String c = str.substring(0, 6); - } + String a = str.substring(1, 3); + char b = str.charAt((str.length())-1); + String c = str.substring(0, 6); + } } ``` @@ -401,178 +407,178 @@ public class Test This errors because I have called the methods with the specified data types in the wrong order. I must call it in the right order ```java -public class Omar -{ - public static void main(String[] args) { - omarMethod(1.0,"YOLO!", 2); - } - - public static void omarMethod(double a, String b, int c) { - System.out.println(a + " " + b + " " + c); - } +public class Omar +{ + public static void main(String[] args) { + omarMethod(1.0,"YOLO!", 2); + } + + public static void omarMethod(double a, String b, int c) { + System.out.println(a + " " + b + " " + c); + } } ``` ### 12- Left out return statement ```java - public class Omar + public class Omar { - public static void main(String[] args) - { - int x = doubleMyNum(5); - System.out.println(x); - } + public static void main(String[] args) + { + int x = doubleMyNum(5); + System.out.println(x); + } - public static int doubleMyNum(int m) - { - int value = 2 * m; - } - } + public static int doubleMyNum(int m) + { + int value = 2 * m; + } +} ``` -The above code errors because I have made the function behave like a void but my 3rd keyword indicates my return type should +The above code errors because I have made the function behave like a void but my 3rd keyword indicates my return type should be of type int. To fix this, after storing the computation in a variable. I use the return keyword to return to the console. The output of the computation performed by the method. ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int x = doubleMyNum(5); - System.out.println(x); - } + public static void main(String[] args) + { + int x = doubleMyNum(5); + System.out.println(x); + } - public static int doubleMyNum(int m) - { - int value = 2 * m; - return value; - } - } + public static int doubleMyNum(int m) + { + int value = 2 * m; + return value; + } +} ``` ### - Left out return statement in CASE#2 ```java - public class Omar + public class Omar { - public static void main(String[] args) - { - int x = myAwesomeAbsVal(-5); - System.out.println(x); - } - - public static int myAwesomeAbsVal(int m) - { - if(m<0) - { - return -m; - } + public static void main(String[] args) + { + int x = myAwesomeAbsVal(-5); + System.out.println(x); + } - if(m>0) - { - return m; - } - } - } + public static int myAwesomeAbsVal(int m) + { + if(m<0) + { + return -m; + } + + if(m>0) + { + return m; + } + } +} ``` The above lines of code have an error in logic. We should switch the code to this: ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int x = myAwesomeAbsVal(-5); - System.out.println(x); - } - - public static int myAwesomeAbsVal(int m) - { - if(m<0) - { - return -m; - } + public static void main(String[] args) + { + int x = myAwesomeAbsVal(-5); + System.out.println(x); + } - else - { - return m; - } - } + public static int myAwesomeAbsVal(int m) + { + if(m<0) + { + return -m; + } + + else + { + return m; + } + } } ``` ### 13 - possible loss of precision ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int theAwesomePi = 3.14159; - System.out.println("The value of pi is: " + theAwesomePi); - } - } + public static void main(String[] args) + { + int theAwesomePi = 3.14159; + System.out.println("The value of pi is: " + theAwesomePi); + } +} ``` There is an error above being raised being we are store double in an integer. An integer can only store 4 4 bytes in main memory. The value we are storing in it is a double which has a memory size of 8 bytes. The way to solve this issue. We will explictly cast the variable theAwesomePi to an int. ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int theAwesomePi = (int)3.14159; - System.out.println("The value of pi is: " + theAwesomePi); - } - } + public static void main(String[] args) + { + int theAwesomePi = (int)3.14159; + System.out.println("The value of pi is: " + theAwesomePi); + } +} ``` ### 14 - Reached end of file while parsing ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - myWonderfulMethod(); - } - - public static void myWonderfulMethod() - { - System.out.println("How Awesome do you think my Method is?"); - } + public static void main(String[] args) + { + myWonderfulMethod(); + } + + public static void myWonderfulMethod() + { + System.out.println("How Awesome do you think my Method is?"); + } ``` There is an error above being raised being we are not properly closing our class. To solve this issue we add a closing curly brace. After, the closing curly brace of my method. ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - myWonderfulMethod(); - } - - public static void myWonderfulMethod() - { - System.out.println("How Awesome do you think my Method is?"); - } + public static void main(String[] args) + { + myWonderfulMethod(); + } + + public static void myWonderfulMethod() + { + System.out.println("How Awesome do you think my Method is?"); + } } ``` ### 15 - unreachable statement -An "unreachable statement" error takes place when the compiler sees that it is impossible to reacha a certain statement. This is caused by the following code. +An "unreachable statement" error takes place when the compiler sees that it is impossible to reacha a certain statement. This is caused by the following code. ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int theAwesomeNum = doubleMe(5); - System.out.println(theAwesomeNum); - } - - public static int doubleMe(int a) - { - int doubleMe = 2 * a; - return doubleMe; - System.out.println("Returning " + doubleMe); - } + public static void main(String[] args) + { + int theAwesomeNum = doubleMe(5); + System.out.println(theAwesomeNum); + } + + public static int doubleMe(int a) + { + int doubleMe = 2 * a; + return doubleMe; + System.out.println("Returning " + doubleMe); + } } ``` @@ -580,47 +586,47 @@ The compiler will generate a number of errors. The first one to be listed is tha This is because whenever we create a method and use the keyword return the compiler says you are done with the method therefore, we can exit out of the method and execute the next line of code. To fix this error I simply reverse the order of the print statement and the return statement. ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int theAwesomeNum = doubleMe(5); - System.out.println(theAwesomeNum); - } + public static void main(String[] args) + { + int theAwesomeNum = doubleMe(5); + System.out.println(theAwesomeNum); + } - public static int doubleMe(int a) - { - int doubleMe = 2 * a; - System.out.println("Returning " + doubleMe); - return doubleMe; - } + public static int doubleMe(int a) + { + int doubleMe = 2 * a; + System.out.println("Returning " + doubleMe); + return doubleMe; + } } ``` -### 16 - Variable might not have been initialized +### 16 - Variable might not have been initialized An variable might not have been initialized error is triggered when we declare a variable and specify its type but never give it an initial value; ```java - public class Omar - { - public static void main(String[] args) { - int myNum = 16; - int myNum2; - System.out.println(myNum + myNum2); - } - } + public class Omar +{ + public static void main(String[] args) { + int myNum = 16; + int myNum2; + System.out.println(myNum + myNum2); + } +} ``` The compiler will generate the error variable myNum2 might not have been initialized because we declared it with the specified data type but never gave it an initial value. To solve this, I simply give it an initial value. ```java -public class Omar +public class Omar { - public static void main(String[] args) - { - int myNum = 16; - int myNum2=3; - System.out.println(myNum + myNum2); - } + public static void main(String[] args) + { + int myNum = 16; + int myNum2=3; + System.out.println(myNum + myNum2); + } } ``` ### 17 - constructor X in class X cannot be applied to given types @@ -630,34 +636,34 @@ super() ### 18 - Cannot make a static reference to the non-static method logLn(object) from the type Omar ```java -public class Omar +public class Omar { - public void logLn(object o){ - System.out.println(o); - } + public void logLn(object o){ + System.out.println(o); + } - public static void main(String[] args) - { - int myNum = 16; - int myNum2=3; - logLn(myNum + myNum2); - } + public static void main(String[] args) + { + int myNum = 16; + int myNum2=3; + logLn(myNum + myNum2); + } } ``` I am getting this error because logLn should me a static method ```java -public class Omar +public class Omar { - public static void logLn(object o){ - System.out.println(o); - } + public static void logLn(object o){ + System.out.println(o); + } - public static void main(String[] args) - { - int myNum = 16; - int myNum2=3; - logLn(myNum + myNum2); - } + public static void main(String[] args) + { + int myNum = 16; + int myNum2=3; + logLn(myNum + myNum2); + } } ``` @@ -698,8 +704,8 @@ public void setLuckyNum(int luckyNum) { this.luckyNum = luckyNum; } */ -@Getter -@Setter +@Getter +@Setter private int luckyNum = 3532; ``` @@ -713,7 +719,7 @@ public class Example ### Equals And Hash Code Annotation ```java @EqualsAndHashCode( - exclude={"id1", "id2"}) + exclude={"id1", "id2"}) public class Example { } ``` \ No newline at end of file diff --git a/STATIC/README.md b/STATIC/README.md new file mode 100644 index 0000000..dc38e49 --- /dev/null +++ b/STATIC/README.md @@ -0,0 +1,75 @@ +## Static Keyword In Java + + +- SUPER IMPORTANT +- Anything I label static means the class can access it directly + +- Instead of: + - Creating An Object + - THEN ACCESSING IT + +- I can: + - Create a variable to store data + - Create a static method + +```java +import java.util.*; + +public class User{ + private String _name; + private String _membership; + public static List administrators; +} +``` + +### Main Class + +```java +import java.util.*; + +public class Main{ + + public static void main(String [] args){ + User.administrators = new ArrayList(); + User.administrators.add(new User("Abraham")); + User.administrators.add(new User("DJ32")); + } +} +``` + + +
+ +### Static Methods + + + +- I access data members directly on the User class + +- System.out.println where **out** is a static data member of the System class + +- e.g. Whenever you want to read Data from a file You can associate it to a user + - Instead of creating a function I create a static method return a list + +- Example: + +```java +public class User{ + public static List administrators; + + public static void print_the_admins(){ + + /* + since List and print_the_admins are both static + I can omit User.administrators + + */ + //for(User j: User.administrators) + for(User j: administrators){ + + System.out.println(j.get_The_Names()) + } + } +} + +``` \ No newline at end of file diff --git a/StudentApp/untitled/.gitignore b/StudentApp/untitled/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/StudentApp/untitled/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/StudentApp/untitled/.idea/.gitignore b/StudentApp/untitled/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/StudentApp/untitled/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/StudentApp/untitled/.idea/misc.xml b/StudentApp/untitled/.idea/misc.xml new file mode 100644 index 0000000..454992c --- /dev/null +++ b/StudentApp/untitled/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/StudentApp/untitled/.idea/modules.xml b/StudentApp/untitled/.idea/modules.xml new file mode 100644 index 0000000..3007dae --- /dev/null +++ b/StudentApp/untitled/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/StudentApp/untitled/.idea/vcs.xml b/StudentApp/untitled/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/StudentApp/untitled/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/StudentApp/untitled/src/Main.java b/StudentApp/untitled/src/Main.java new file mode 100644 index 0000000..d5238c9 --- /dev/null +++ b/StudentApp/untitled/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} \ No newline at end of file diff --git a/StudentApp/untitled/src/aui/students/Students.java b/StudentApp/untitled/src/aui/students/Students.java new file mode 100644 index 0000000..ca7bff5 --- /dev/null +++ b/StudentApp/untitled/src/aui/students/Students.java @@ -0,0 +1,21 @@ +package aui.students; +import java.util.Date; + +public class Students { + private String name; + private int age; + private int id; + private String dateOfBirth; + private String address; + + public Students(String name, int age, int id, String dateOfBirth, String address){ + this.name=name; + this.age=age; + this.id=id; + this.dateOfBirth=dateOfBirth; + this.address=address; + } + + + +} diff --git a/StudentApp/untitled/untitled.iml b/StudentApp/untitled/untitled.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/StudentApp/untitled/untitled.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/UML/Library/Book.java b/UML/Library/Book.java new file mode 100644 index 0000000..27213b8 --- /dev/null +++ b/UML/Library/Book.java @@ -0,0 +1,19 @@ +public class Book{ + private String ISBN; + private String title; + private boolean isAvailable; + + public Book(String ISBN, String title, boolean isAvailable){ + this.ISBN=ISBN; + this.title=title; + this.isAvailable=true; + } + + public boolean isAvailable(){ + return isAvailable; + } + + public void setAvailable(boolean available){ + isAvailable=available + } +} \ No newline at end of file diff --git a/UML/Library/Librarian.java b/UML/Library/Librarian.java new file mode 100644 index 0000000..969c2a5 --- /dev/null +++ b/UML/Library/Librarian.java @@ -0,0 +1,8 @@ +public class Librarian extends User{ + void addBook(){ + + } + void removeBook(){ + + } +} \ No newline at end of file diff --git a/UML/Library/Loan.java b/UML/Library/Loan.java new file mode 100644 index 0000000..1805fb4 --- /dev/null +++ b/UML/Library/Loan.java @@ -0,0 +1,14 @@ +public class Loan { + private String dueDate; + private String dateReturned; + private Book book; + private Member member; + + public Loan(Book book, Member member, String dueDate){ + this.dueDate=dueDate; + this.book=book; + this.member=member; + this.dateReturned=null; + this.book.setAvailability(false); + } +} \ No newline at end of file diff --git a/UML/Library/Member.java b/UML/Library/Member.java new file mode 100644 index 0000000..bde156d --- /dev/null +++ b/UML/Library/Member.java @@ -0,0 +1,20 @@ +import java.util.*; + + +public Member extends User{ + private List loans = new ArrayList<>(); + + public void borrowBook(Book book, String dueDate){ + Loan loan = new Loan(book, this, dueDate); + loans.add(loan); + } + + public void returnBook(Book book){ + for(Loan loan: loans){ + if(loan.getBook()==book && loan.getDateReturned() == null) + loan.setDateReturned("2025-04-25"); + book.setAvailable(true); + break; + } + } +} \ No newline at end of file diff --git a/UML/Library/User.java b/UML/Library/User.java new file mode 100644 index 0000000..caab61c --- /dev/null +++ b/UML/Library/User.java @@ -0,0 +1,6 @@ +import java.util.*; + +public class User{ + private int id; + private String name; +} \ No newline at end of file