diff --git a/Ahmad/.gitignore b/Ahmad/.gitignore
index e10e727..22df333 100644
--- a/Ahmad/.gitignore
+++ b/Ahmad/.gitignore
@@ -1 +1,4 @@
/.metadata/
+
+
+../Buchalka/
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/.gitignore b/Ahmad/2_puzzles/.gitignore
new file mode 100644
index 0000000..e10e727
--- /dev/null
+++ b/Ahmad/2_puzzles/.gitignore
@@ -0,0 +1 @@
+/.metadata/
diff --git a/Ahmad/2_puzzles/.project b/Ahmad/2_puzzles/.project
new file mode 100644
index 0000000..84e37cf
--- /dev/null
+++ b/Ahmad/2_puzzles/.project
@@ -0,0 +1,11 @@
+
+
+ puzzles_2
+
+
+
+
+
+
+
+
diff --git a/Ahmad/prereq-practice/.classpath b/Ahmad/2_puzzles/assignment_01/.classpath
similarity index 71%
rename from Ahmad/prereq-practice/.classpath
rename to Ahmad/2_puzzles/assignment_01/.classpath
index 51a8bba..57bca72 100644
--- a/Ahmad/prereq-practice/.classpath
+++ b/Ahmad/2_puzzles/assignment_01/.classpath
@@ -1,6 +1,10 @@
-
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_01/.gitignore b/Ahmad/2_puzzles/assignment_01/.gitignore
new file mode 100644
index 0000000..09e3bc9
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_01/.gitignore
@@ -0,0 +1,2 @@
+/bin/
+/target/
diff --git a/Ahmad/assignment_01/.project b/Ahmad/2_puzzles/assignment_01/.project
similarity index 100%
rename from Ahmad/assignment_01/.project
rename to Ahmad/2_puzzles/assignment_01/.project
diff --git a/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.m2e.core.prefs b/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/Ahmad/2_puzzles/assignment_01/pom.xml b/Ahmad/2_puzzles/assignment_01/pom.xml
new file mode 100644
index 0000000..1f0562f
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_01/pom.xml
@@ -0,0 +1,36 @@
+
+ 4.0.0
+ spring-demo-one
+ spring-demo-one
+ 0.0.1-SNAPSHOT
+
+ src
+
+
+ src
+
+ **/*.java
+
+
+
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+
+ org.springframework
+ spring
+ 5.2.7.RELEASE
+ pom
+
+
+
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_01/src/beanScope-applicationContext.xml b/Ahmad/2_puzzles/assignment_01/src/beanScope-applicationContext.xml
new file mode 100644
index 0000000..d5075e1
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_01/src/beanScope-applicationContext.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_01/src/com/luv2code/springdemo/BeanScopeDemoApp.java b/Ahmad/2_puzzles/assignment_01/src/com/luv2code/springdemo/BeanScopeDemoApp.java
new file mode 100644
index 0000000..f15ba2a
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_01/src/com/luv2code/springdemo/BeanScopeDemoApp.java
@@ -0,0 +1,34 @@
+package com.luv2code.springdemo;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+public class BeanScopeDemoApp {
+
+ public static void main(String[] args) {
+
+ // load the spring configuration file
+ ClassPathXmlApplicationContext context =
+ new ClassPathXmlApplicationContext("beanScope-applicationContext.xml");
+
+
+ // retrieve bean from spring container
+ Coach theCoach = context.getBean("myCoach", Coach.class);
+
+ Coach alphaCoach = context.getBean("myCoach", Coach.class);
+
+ // check if they are the same
+ boolean result = (theCoach == alphaCoach);
+
+ // print out the results
+ System.out.println("\nPointing to the same object: " + result);
+
+ System.out.println("\nMemory location for theCoach: " + theCoach);
+
+ System.out.println("\nMemort location for alphaCoach: " + alphaCoach + "\n");
+
+ //close the context
+ context.close();
+ }
+
+}
diff --git a/Ahmad/2_puzzles/assignment_01/src/com/luv2code/springdemo/RandomFortuneService.java b/Ahmad/2_puzzles/assignment_01/src/com/luv2code/springdemo/RandomFortuneService.java
new file mode 100644
index 0000000..594fb1e
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_01/src/com/luv2code/springdemo/RandomFortuneService.java
@@ -0,0 +1,30 @@
+package com.luv2code.springdemo;
+
+import java.util.Random;
+
+public class RandomFortuneService implements FortuneService {
+
+ // create an array of strings
+ private String[] data = {
+ "Beware of the wolf in sheep's clothing",
+ "Diligence is the mother of good luck",
+ "The journey is the reward"
+ };
+
+ // create a random number generator
+ private Random myRandom = new Random();
+
+ @Override
+ public String getFortune() {
+ // pick a random string from the array
+ int index = myRandom.nextInt(data.length);
+ System.out.println(index);
+
+ String theFortune = data[index];
+
+ return theFortune;
+ }
+
+}
+
+
diff --git a/Ahmad/assignment_01/src/assignment_01/.classpath b/Ahmad/2_puzzles/assignment_02/.classpath
similarity index 71%
rename from Ahmad/assignment_01/src/assignment_01/.classpath
rename to Ahmad/2_puzzles/assignment_02/.classpath
index fb565a5..57bca72 100644
--- a/Ahmad/assignment_01/src/assignment_01/.classpath
+++ b/Ahmad/2_puzzles/assignment_02/.classpath
@@ -1,6 +1,10 @@
+
+
+
+
+
-
diff --git a/Ahmad/assigment_01/.gitignore b/Ahmad/2_puzzles/assignment_02/.gitignore
similarity index 100%
rename from Ahmad/assigment_01/.gitignore
rename to Ahmad/2_puzzles/assignment_02/.gitignore
diff --git a/Ahmad/assignment_01/src/assignment_01/.project b/Ahmad/2_puzzles/assignment_02/.project
similarity index 92%
rename from Ahmad/assignment_01/src/assignment_01/.project
rename to Ahmad/2_puzzles/assignment_02/.project
index d85502a..721d129 100644
--- a/Ahmad/assignment_01/src/assignment_01/.project
+++ b/Ahmad/2_puzzles/assignment_02/.project
@@ -1,6 +1,6 @@
- assignment_01
+ assignment_02
diff --git a/Ahmad/2_puzzles/assignment_02/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_02/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_02/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/assigment_01/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_02/.settings/org.eclipse.jdt.core.prefs
similarity index 57%
rename from Ahmad/assigment_01/.settings/org.eclipse.jdt.core.prefs
rename to Ahmad/2_puzzles/assignment_02/.settings/org.eclipse.jdt.core.prefs
index 3a21537..8c9943d 100644
--- a/Ahmad/assigment_01/.settings/org.eclipse.jdt.core.prefs
+++ b/Ahmad/2_puzzles/assignment_02/.settings/org.eclipse.jdt.core.prefs
@@ -1,11 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/assignment_01/src/assignment_02/App.java b/Ahmad/2_puzzles/assignment_02/src/assignment_02/App.java
similarity index 79%
rename from Ahmad/assignment_01/src/assignment_02/App.java
rename to Ahmad/2_puzzles/assignment_02/src/assignment_02/App.java
index f051c74..13acb2b 100644
--- a/Ahmad/assignment_01/src/assignment_02/App.java
+++ b/Ahmad/2_puzzles/assignment_02/src/assignment_02/App.java
@@ -21,8 +21,24 @@ public class App {
*/
public static int speedingFine(int speed, boolean isHoliday) {
- return 0;
-
+
+ int min = 60;
+ int max = 80;
+ int fine = 0;
+
+ if (isHoliday == true) {
+ min += 5;
+ max += 5;
+ }
+
+ if (speed > max){
+ fine = 200;
+ }
+ if(speed > min && speed <= max) {
+ fine = 100;
+ }
+
+ return fine;
}
diff --git a/Ahmad/assignment_01/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_02/src/ignore/TestingUtils.java
similarity index 100%
rename from Ahmad/assignment_01/src/ignore/TestingUtils.java
rename to Ahmad/2_puzzles/assignment_02/src/ignore/TestingUtils.java
diff --git a/Ahmad/assignment_01/.classpath b/Ahmad/2_puzzles/assignment_03/.classpath
similarity index 71%
rename from Ahmad/assignment_01/.classpath
rename to Ahmad/2_puzzles/assignment_03/.classpath
index 51a8bba..57bca72 100644
--- a/Ahmad/assignment_01/.classpath
+++ b/Ahmad/2_puzzles/assignment_03/.classpath
@@ -1,6 +1,10 @@
-
+
+
+
+
+
diff --git a/Ahmad/assignment_01/.gitignore b/Ahmad/2_puzzles/assignment_03/.gitignore
similarity index 100%
rename from Ahmad/assignment_01/.gitignore
rename to Ahmad/2_puzzles/assignment_03/.gitignore
diff --git a/Ahmad/prereq-practice/.project b/Ahmad/2_puzzles/assignment_03/.project
similarity index 91%
rename from Ahmad/prereq-practice/.project
rename to Ahmad/2_puzzles/assignment_03/.project
index e3e0bf3..7b70b77 100644
--- a/Ahmad/prereq-practice/.project
+++ b/Ahmad/2_puzzles/assignment_03/.project
@@ -1,6 +1,6 @@
- prereq-practice
+ assignment_03
diff --git a/Ahmad/2_puzzles/assignment_03/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_03/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_03/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/prereq-practice/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_03/.settings/org.eclipse.jdt.core.prefs
similarity index 57%
rename from Ahmad/prereq-practice/.settings/org.eclipse.jdt.core.prefs
rename to Ahmad/2_puzzles/assignment_03/.settings/org.eclipse.jdt.core.prefs
index 3a21537..8c9943d 100644
--- a/Ahmad/prereq-practice/.settings/org.eclipse.jdt.core.prefs
+++ b/Ahmad/2_puzzles/assignment_03/.settings/org.eclipse.jdt.core.prefs
@@ -1,11 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_03/src/assignment_03/App.java b/Ahmad/2_puzzles/assignment_03/src/assignment_03/App.java
new file mode 100644
index 0000000..c595390
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_03/src/assignment_03/App.java
@@ -0,0 +1,39 @@
+package assignment_03;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ * Given three ints, a b c, return true if it is possible to add two of
+ * the ints to get the third. There should only be a single line of code in the method body.
+ *
+ *
+ * EXPECTATIONS:
+ twoSumOne(1, 2, 3) ---> true
+ twoSumOne(3, 1, 2) ---> true
+ twoSumOne(3, 2, 2) ---> false
+ */
+ public static boolean twoSumOne(int a, int b, int c) {
+
+ return (a + b == c) || (b + c == a) || (a + c == b);
+
+ }
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+ }
+
+
+}
diff --git a/Ahmad/2_puzzles/assignment_03/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_03/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..095c61b
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_03/src/ignore/TestingUtils.java
@@ -0,0 +1,39 @@
+package ignore;
+
+import assignment_03.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 1, 3, 3, 2, 5, 5, 2, 9, 9, 5, 3, 3 };
+
+ int[] params2 = { 2, 1, 2, 3, 3, 3, 5, 5, 4, 4, 3, 3 };
+
+ int[] params3 = { 3, 2, 2, 1, -2, -3, 3, 5, 5, 9, 0, 2 };
+
+ boolean[] expected = { true, true, false, true, true, false, true, false, true, true, true, false };
+
+ for(int i=0; i < params1.length; i++){
+ boolean result = App.twoSumOne(params1[i], params2[i], params3[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], params3[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], params3[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object params3, Object expected, Object result){
+ return "PASS: twoSumOne("+ params1.toString()+ ", "+ params2.toString()+ ", "+ params3.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object params3, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: twoSumOne("+ params1.toString()+ ", "+ params2.toString()+", "+ params3.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_04/.classpath b/Ahmad/2_puzzles/assignment_04/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_04/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/prereq-practice/.gitignore b/Ahmad/2_puzzles/assignment_04/.gitignore
similarity index 100%
rename from Ahmad/prereq-practice/.gitignore
rename to Ahmad/2_puzzles/assignment_04/.gitignore
diff --git a/Ahmad/2_puzzles/assignment_04/.project b/Ahmad/2_puzzles/assignment_04/.project
new file mode 100644
index 0000000..05868e0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_04/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_04
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_04/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_04/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_04/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_04/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_04/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_04/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_04/src/assignment_04/App.java b/Ahmad/2_puzzles/assignment_04/src/assignment_04/App.java
new file mode 100644
index 0000000..1ba3c70
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_04/src/assignment_04/App.java
@@ -0,0 +1,52 @@
+package assignment_04;
+
+import ignore.TestingUtils;
+
+public class App {
+
+ /**
+ The birds in Florida like to sing during favorable temperatures.
+ In particular, they sing if the temperature is between 60 and 90 (inclusive).
+ Unless it is summer, then the upper limit is 100 instead of 90.
+ Given an int temperature and a boolean isSummer,
+ return true if the birds are singing and false otherwise.
+
+
+ * EXPECTATIONS:
+ birdsSinging(70, false) ---> true
+ birdsSinging(95, false) ---> false
+ birdsSinging(95, true) ---> true
+ */
+ public static boolean birdsSinging(int temp, boolean isSummer) {
+
+ int min = 60;
+ int max = 90;
+ boolean singing = false;
+
+ if (isSummer) {
+ max += 10;
+ }
+
+ if (temp >= min && temp <= max) {
+ singing = true;
+ }
+
+
+ return singing;
+ }
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+ }
+}
+
+
diff --git a/Ahmad/2_puzzles/assignment_04/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_04/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..3130948
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_04/src/ignore/TestingUtils.java
@@ -0,0 +1,37 @@
+package ignore;
+
+import assignment_04.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 70, 95, 95, 90, 90, 50, 50, 100, 100, 105, 59, 59, 60 };
+
+ boolean[] params2 = { false, false, true, false, true, false, true, false, true, true, false, true, false };
+
+ boolean[] expected = { true, false, true, true, true, false, false, false, true, false, false, false, true };
+
+ for(int i=0; i < params1.length; i++){
+ boolean result = App.birdsSinging(params1[i], params2[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object expected, Object result){
+ return "PASS: birdsSinging("+ params1.toString()+ ", "+ params2.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: birdsSinging("+ params1.toString()+ ", "+ params2.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_05/.classpath b/Ahmad/2_puzzles/assignment_05/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_05/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Darby/spring-demo-one/.gitignore b/Ahmad/2_puzzles/assignment_05/.gitignore
similarity index 100%
rename from Darby/spring-demo-one/.gitignore
rename to Ahmad/2_puzzles/assignment_05/.gitignore
diff --git a/Ahmad/2_puzzles/assignment_05/.project b/Ahmad/2_puzzles/assignment_05/.project
new file mode 100644
index 0000000..3ddfb2c
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_05/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_05
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_05/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_05/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_05/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_05/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_05/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_05/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_05/src/assignment_05/App.java b/Ahmad/2_puzzles/assignment_05/src/assignment_05/App.java
new file mode 100644
index 0000000..361f3b3
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_05/src/assignment_05/App.java
@@ -0,0 +1,54 @@
+package assignment_05;
+
+import ignore.TestingUtils;
+
+public class App {
+
+ /**
+ Given three ints, first, second, third,
+ return true if second is greater than first, and third is greater than second.
+
+ However, with the exception that if the parameter "itsOk" is true,
+ second does not need to be greater than first but still better be less than third.
+
+
+
+ * EXPECTATIONS:
+ isOrdered(1, 2, 4, false) ---> true
+ isOrdered(1, 2, 1, false) ---> false
+ isOrdered(1, 1, 2, true) ---> true
+ */
+ public static boolean isOrdered(int first, int second, int third, boolean itsOk) {
+
+ boolean value = (itsOk) ? (second < third) : (second > first && third > second);
+
+// boolean ordered = false;
+//
+// if(!itsOk && second > first && third > second) {
+// ordered = true;
+// }
+// if(itsOk && second < third) {
+// ordered = true;
+// }
+
+
+ return value;
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+ }
+}
+
+
diff --git a/Ahmad/2_puzzles/assignment_05/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_05/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..b5185ec
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_05/src/ignore/TestingUtils.java
@@ -0,0 +1,41 @@
+package ignore;
+
+import assignment_05.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 1, 1, 1, 3, 2, 3, 4, 4, 2, 7, 7, 7 };
+
+ int[] params2 = { 2, 2, 1, 2, 3, 2, 2, 5, 4, 9, 5, 5 };
+
+ int[] params3 = { 4, 1, 2, 4, 4, 4, 2, 2, 6, 10, 6, 4 };
+
+ boolean[] params4 = { false, false, true, false, false, true, true, true, true, false, true, true };
+
+ boolean[] expected = { true, false, true, false, true, true, false, false, true, true, true, false };
+
+ for(int i=0; i < params1.length; i++){
+ boolean result = App.isOrdered(params1[i], params2[i], params3[i], params4[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i],params3[i], params4[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], params3[i], params4[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object params3, Object params4, Object expected, Object result){
+ return "PASS: isOrdered("+ params1.toString()+ ", "+ params2.toString()+", "+ params3.toString()+", "+ params4.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object params3, Object params4, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: isOrdered("+ params1.toString()+ ", "+ params2.toString()+", "+ params3.toString()+", "+ params4.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_06/.classpath b/Ahmad/2_puzzles/assignment_06/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_06/.gitignore b/Ahmad/2_puzzles/assignment_06/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_06/.project b/Ahmad/2_puzzles/assignment_06/.project
new file mode 100644
index 0000000..97391bf
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_06
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_06/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_06/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_06/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_06/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_06/src/assignment_06/App.java b/Ahmad/2_puzzles/assignment_06/src/assignment_06/App.java
new file mode 100644
index 0000000..5ab7e6d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/src/assignment_06/App.java
@@ -0,0 +1,48 @@
+package assignment_06;
+
+import ignore.TestingUtils;
+
+public class App {
+
+ /**
+ We'll say a number is cool if it's a multiple of 11 or if it is one more than a multiple of 11.
+ Return true if the given non-negative number is cool. Use the % "modulus" operator
+ we spoke about in the prerequisite section. Watch the lesson on modulus if you need to review
+
+
+
+ * EXPECTATIONS:
+ isCool(22) ---> true
+ isCool(23) ---> true
+ isCool(24) ---> false
+ */
+ public static boolean isCool(int n) {
+
+ boolean cool = false;
+
+ if(n % 11 == 0 || n % 11 == 1) {
+ cool = true;
+ }
+
+ return cool;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
+
diff --git a/Ahmad/2_puzzles/assignment_06/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_06/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..63f9a10
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_06/src/ignore/TestingUtils.java
@@ -0,0 +1,35 @@
+package ignore;
+
+import assignment_06.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 22, 23, 24, 21, 11, 12, 10, 9, 8, 0, 1, 2, 121, 122, 123, 46, 49, 52, 54, 55 };
+ boolean[] expected = { true, true, false, false, true, true, false, false, false, true, true, false, true, true,
+ false, false, false, false, false, true };
+
+ for(int i=0; i < params1.length; i++){
+ boolean result = App.isCool(params1[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: isCool("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: isCool("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_07/.classpath b/Ahmad/2_puzzles/assignment_07/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_07/.gitignore b/Ahmad/2_puzzles/assignment_07/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_07/.project b/Ahmad/2_puzzles/assignment_07/.project
new file mode 100644
index 0000000..75ef8a6
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_07
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_07/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_07/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_07/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_07/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_07/src/assignment_07/App.java b/Ahmad/2_puzzles/assignment_07/src/assignment_07/App.java
new file mode 100644
index 0000000..d76c8fa
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/src/assignment_07/App.java
@@ -0,0 +1,53 @@
+package assignment_07;
+
+import ignore.TestingUtils;
+
+public class App {
+
+ /**
+ Given an int n, return the string form of the number followed by "!".
+ So if the int is for example 13 this method should return "13!".
+ However the catch is that if the number is divisible by 3 the method should return "Fizz!"
+ instead of the number, and if the number is divisible by 5 it should return "Buzz!",
+ and if divisible by both 3 and 5, use "FizzBuzz!". You’ll need to use the % "mod"
+ for computing the remainder after division, so 23 % 10 yields 3.
+
+
+
+
+ * EXPECTATIONS:
+ fizzyWizzy(1) ---> "1!"
+ fizzyWizzy(2) ---> "2!"
+ fizzyWizzy(3) ---> "Fizz!"
+ */
+ public static String fizzyWizzy(int n) {
+
+ boolean fizz = n % 3 == 0;
+ boolean buzz = n % 5 ==0;
+
+ if(fizz & buzz) return "FizzBuzz!";
+ if(fizz) return "Fizz!";
+ if(buzz) return "Buzz!";
+
+ return n + "!";
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
+
diff --git a/Ahmad/2_puzzles/assignment_07/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_07/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..e91cf46
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_07/src/ignore/TestingUtils.java
@@ -0,0 +1,35 @@
+package ignore;
+
+import assignment_07.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 18, 19, 21, 44, 45, 100 };
+ String[] expected = { "1!", "2!", "Fizz!", "4!", "Buzz!", "Fizz!", "7!", "8!", "Fizz!", "FizzBuzz!", "16!",
+ "Fizz!", "19!", "Fizz!", "44!", "FizzBuzz!", "Buzz!" };
+
+ for(int i=0; i < params1.length; i++){
+ String result = App.fizzyWizzy(params1[i]);
+ if(result.equals(expected[i])) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: fizzyWizzy("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: fizzyWizzy("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_08/.classpath b/Ahmad/2_puzzles/assignment_08/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_08/.gitignore b/Ahmad/2_puzzles/assignment_08/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_08/.project b/Ahmad/2_puzzles/assignment_08/.project
new file mode 100644
index 0000000..1d1e6db
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_08
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_08/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_08/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_08/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_08/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_08/src/assignment_08/App.java b/Ahmad/2_puzzles/assignment_08/src/assignment_08/App.java
new file mode 100644
index 0000000..f923aab
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/src/assignment_08/App.java
@@ -0,0 +1,48 @@
+package assignment_08;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+
+ Given 3 int arguments - a, b, c, return their sum. However, if one of the arguments
+ is the same as any of the other ones, that number should not count towards the sum.
+ So basically you only sum unique numbers, not duplicates
+
+
+
+ * EXPECTATIONS:
+ sumUnique(1, 2, 3) ---> 6
+ sumUnique(3, 2, 3) ---> 2
+ sumUnique(3, 3, 3) ---> 0
+ */
+
+ public static int sumUnique(int a, int b, int c) {
+
+ if (a == b && b ==c) {return 0;};
+ if ( a == b ) {return c;};
+ if ( a == c ) {return b;};
+ if ( b == c ) {return a;};
+
+ return a + b + c;
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
diff --git a/Ahmad/2_puzzles/assignment_08/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_08/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..9d3ecbe
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_08/src/ignore/TestingUtils.java
@@ -0,0 +1,39 @@
+package ignore;
+
+import assignment_08.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 1, 3, 3, 9, 2, 2, 2, 4, 1 };
+
+ int[] params2 = { 2, 2, 3, 2, 2, 9, 9, 2, 3 };
+
+ int[] params3 = { 3, 3, 3, 2, 9, 2, 3, 3, 1 };
+
+ int[] expected = { 6, 2, 0, 9, 9, 9, 14, 9, 3 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.sumUnique(params1[i], params2[i], params3[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], params3[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], params3[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object params3, Object expected, Object result){
+ return "PASS: sumUnique("+ params1.toString()+ ", "+ params2.toString()+ ", "+ params3.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object params3, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: sumUnique("+ params1.toString()+ ", "+ params2.toString()+", "+ params3.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_09/.classpath b/Ahmad/2_puzzles/assignment_09/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_09/.gitignore b/Ahmad/2_puzzles/assignment_09/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_09/.project b/Ahmad/2_puzzles/assignment_09/.project
new file mode 100644
index 0000000..41d732d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_09
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_09/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_09/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_09/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_09/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_09/src/assignment_09/App.java b/Ahmad/2_puzzles/assignment_09/src/assignment_09/App.java
new file mode 100644
index 0000000..2a9b52e
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/src/assignment_09/App.java
@@ -0,0 +1,50 @@
+package assignment_09;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+
+ Given 2 positive int arguments (a, b), return whichever argument is
+ nearest to the number 21 without going over.
+ Return 0 if they both go over 21.
+
+
+
+ * EXPECTATIONS:
+ nearestTwentyOne(19, 21) ---> 21
+ nearestTwentyOne(21, 19) ---> 21
+ nearestTwentyOne(19, 22) ---> 19
+ nearestTwentyOne(32, 22) ---> 0
+ */
+
+ public static int nearestTwentyOne(int a, int b) {
+
+ if(a > 21 && b > 21) return 0;
+ if(a > 21 && b <- 21) return b;
+ if(a <= 21 && b > 21) return a;
+
+ if (a > b)
+ return a;
+ else
+ return b;
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
diff --git a/Ahmad/2_puzzles/assignment_09/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_09/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..9123745
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_09/src/ignore/TestingUtils.java
@@ -0,0 +1,37 @@
+package ignore;
+
+import assignment_09.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ int[] params1 = { 19, 21, 19, 22, 22, 22, 33, 1, 34, 17, 18, 16, 3, 3, 21 };
+
+ int[] params2 = { 21, 19, 22, 19, 50, 22, 1, 2, 33, 19, 17, 23, 4, 2, 20 };
+
+ int[] expected = { 21, 21, 19, 19, 0, 0, 1, 2, 0, 19, 18, 16, 4, 3, 21 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.nearestTwentyOne(params1[i], params2[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object expected, Object result){
+ return "PASS: nearestTwentyOne("+ params1.toString()+ ", "+ params2.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: nearestTwentyOne("+ params1.toString()+ ", "+ params2.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_10/.classpath b/Ahmad/2_puzzles/assignment_10/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_10/.gitignore b/Ahmad/2_puzzles/assignment_10/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_10/.project b/Ahmad/2_puzzles/assignment_10/.project
new file mode 100644
index 0000000..b1f6869
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_10
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_10/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_10/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_10/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_10/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_10/src/assignment_10/App.java b/Ahmad/2_puzzles/assignment_10/src/assignment_10/App.java
new file mode 100644
index 0000000..96df596
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/src/assignment_10/App.java
@@ -0,0 +1,60 @@
+package assignment_10;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+
+ Given 3 int arguments, a b c, return their sum. However, if one of the arguments is 13
+ then it does not count towards the sum and arguments to it's right do not count either.
+ So for example, if b is 13, then both b and c do not count.
+
+
+
+ * EXPECTATIONS:
+ partialSum(1, 2, 3) ---> 6
+ partialSum(1, 2, 13) ---> 3
+ partialSum(1, 13, 3) ---> 1
+ */
+
+ public static int partialSum(int a, int b, int c) {
+
+// int sum = 0;
+// int[] nums = {a, b, c};
+//
+// for (int i = 0; i < nums.length; i++) {
+// if (nums[i] == 13) {
+// break;
+// }
+// sum += nums[i];
+// }
+//
+//
+// return sum;
+
+ if (a == 13) return 0;
+ if (b == 13) return a;
+ if (c == 13) return a + b;
+
+ return a + b + c;
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
diff --git a/Ahmad/2_puzzles/assignment_10/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_10/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..6bfb20b
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_10/src/ignore/TestingUtils.java
@@ -0,0 +1,38 @@
+package ignore;
+
+import assignment_10.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+ int[] params1 = { 1, 1, 1, 1, 6, 13, 13, 13, 9, 8, 7, 3 };
+
+ int[] params2 = { 2, 2, 13, 13, 5, 2, 2, 13, 4, 13, 2, 3 };
+
+ int[] params3 = { 3, 13, 3, 13, 2, 3, 13, 2, 13, 2, 1, 13 };
+
+ int[] expected = { 6, 3, 1, 1, 13, 0, 0, 0, 13, 8, 10, 6 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.partialSum(params1[i], params2[i], params3[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], params3[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], params3[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object params3, Object expected, Object result){
+ return "PASS: partialSum("+ params1.toString()+ ", "+ params2.toString()+ ", "+ params3.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object params3, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: partialSum("+ params1.toString()+ ", "+ params2.toString()+", "+ params3.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_11/.classpath b/Ahmad/2_puzzles/assignment_11/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_11/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_11/.gitignore b/Ahmad/2_puzzles/assignment_11/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_11/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_11/.project b/Ahmad/2_puzzles/assignment_11/.project
new file mode 100644
index 0000000..7eb9a73
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_11/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_11
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_11/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_11/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_11/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_11/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_11/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_11/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_11/src/assignment_11/App.java b/Ahmad/2_puzzles/assignment_11/src/assignment_11/App.java
new file mode 100644
index 0000000..0229858
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_11/src/assignment_11/App.java
@@ -0,0 +1,46 @@
+package assignment_11;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+
+ Given a string, return a string where for every char in the original, append another.
+
+
+
+ * EXPECTATIONS:
+ repeatChar("The") --->"TThhee"
+ repeatChar("AAbb") ---> "AAAAbbbb"
+ repeatChar("Hi-There") ---> "HHii--TThheerree"
+ */
+
+ public static String repeatChar(String str) {
+ String result = "";
+
+ for(int i =0; i " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: repeatChar("+ params1.toString()+") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_12/.classpath b/Ahmad/2_puzzles/assignment_12/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_12/.gitignore b/Ahmad/2_puzzles/assignment_12/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_12/.project b/Ahmad/2_puzzles/assignment_12/.project
new file mode 100644
index 0000000..c5b011e
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_12
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_12/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_12/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_12/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_12/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_12/src/assignment_12/App.java b/Ahmad/2_puzzles/assignment_12/src/assignment_12/App.java
new file mode 100644
index 0000000..b023a78
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/src/assignment_12/App.java
@@ -0,0 +1,60 @@
+package assignment_12;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+ Return a version of the given string, where for every star (*)
+ in the string the star and the chars immediately to its left and right are gone.
+ So "ab*cd" yields "ad" and "ab**cd" also yields "ad".
+
+
+ * EXPECTATIONS:
+ starKill("cd*zq") --->"cq"
+ starKill("ab**cd") ---> "ad"
+ starKill("wacy*xko") ---> "wacko"
+ */
+
+ public static String starKill(String str) {
+
+ int len = str.length();
+ String result = "";
+
+ for(int i = 0; i < len; i++) {
+
+ if( i == 0 && str.charAt(i) != '*') {
+ result += str.charAt(i);
+ }
+
+ if( i > 0 && str.charAt(i) != '*' && str.charAt(i - 1) != '*' ) {
+ result += str.charAt(i);
+ }
+
+ if(i > 0 && str.charAt(i) == '*' && str.charAt(i-1) != '*')
+ result = result.substring(0, result.length() -1);
+ }
+
+ return result;
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
diff --git a/Ahmad/2_puzzles/assignment_12/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_12/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..44664a1
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_12/src/ignore/TestingUtils.java
@@ -0,0 +1,36 @@
+package ignore;
+
+import assignment_12.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+ String[] params1 = { "ab*cd", "ab**cd", "sm*eilly", "sm*eil*ly", "sm**eil*ly", "sm***eil*ly", "stringy*",
+ "*stringy", "*str*in*gy", "abc", "a*bc", "ab", "a*b", "a", "a*", "*a", "*", "" };
+
+ String[] expected = { "ad", "ad", "silly", "siy", "siy", "siy", "string", "tringy", "ty", "abc", "c", "ab", "",
+ "a", "", "", "", "" };
+
+ for(int i=0; i < params1.length; i++){
+ String result = App.starKill(params1[i]);
+ if(result.equals(expected[i])) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: starKill("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: starKill("+ params1.toString()+") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_13/.classpath b/Ahmad/2_puzzles/assignment_13/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_13/.gitignore b/Ahmad/2_puzzles/assignment_13/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_13/.project b/Ahmad/2_puzzles/assignment_13/.project
new file mode 100644
index 0000000..46bb0f6
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_13
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_13/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_13/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_13/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_13/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_13/src/assignment_13/App.java b/Ahmad/2_puzzles/assignment_13/src/assignment_13/App.java
new file mode 100644
index 0000000..5f8dcfd
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/src/assignment_13/App.java
@@ -0,0 +1,47 @@
+package assignment_13;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+ Given an array of strings, return the count of the number of strings with the given length
+
+
+ * EXPECTATIONS:
+ wordsCount({"a", "bb", "b", "ccc"}, 1) ---> 2
+ wordsCount({"a", "bb", "b", "ccc"}, 3) ---> 1
+ wordsCount({"a", "bb", "b", "ccc"}, 4) ---> 0
+ */
+
+ public static int wordsCount(String[] words, int len) {
+
+ int count = 0;
+
+ for(int i = 0; i < words.length; i++) {
+
+ if (words[i].length() == len)
+ count += 1;
+ }
+
+ return count;
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
diff --git a/Ahmad/2_puzzles/assignment_13/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_13/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..b6c1c0b
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_13/src/ignore/TestingUtils.java
@@ -0,0 +1,41 @@
+package ignore;
+
+import java.util.Arrays;
+
+import assignment_13.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+ String[] [] params1 = { { "a", "bb", "b", "ccc" }, { "a", "bb", "b", "ccc" }, { "a", "bb", "b", "ccc" },
+ { "xx", "yyy", "x", "yy", "z" }, { "xx", "yyy", "x", "yy", "z" }, { "xx", "yyy", "x", "yy", "z" } };
+
+ int [] params2 = {1,3,4,1,2,3};
+
+ int[] expected = { 2, 1, 0, 2, 2, 1 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.wordsCount(params1[i], params2[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(String[] params1, Object params2, Object expected, Object result){
+ String str = "";
+
+ return "PASS: wordsCount("+Arrays.toString(params1)+", "+ params2+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(String[] params1, Object params2, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: wordsCount("+Arrays.toString(params1)+", "+ params2+") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_14/.classpath b/Ahmad/2_puzzles/assignment_14/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_14/.gitignore b/Ahmad/2_puzzles/assignment_14/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_14/.project b/Ahmad/2_puzzles/assignment_14/.project
new file mode 100644
index 0000000..15f497d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_14
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_14/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_14/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_14/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_14/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_14/src/assignment_14/App.java b/Ahmad/2_puzzles/assignment_14/src/assignment_14/App.java
new file mode 100644
index 0000000..726763c
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/src/assignment_14/App.java
@@ -0,0 +1,56 @@
+package assignment_14;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+ Given 2 arrays that are the same length containing strings, compare the 1st string in one array
+ to the 1st string in the other array, the 2nd to the 2nd and so on.
+ Count the number of times that the 2 strings are non-empty and start with the same char.
+ The strings may be any length, including 0.
+
+
+
+ * EXPECTATIONS:
+ matchingChar({"aa", "bb", "cc"}, {"aaa", "xx", "bb"}) ---> 1
+ matchingChar({"aa", "bb", "cc"}, {"aaa", "b", "bb"}) ---> 2
+ matchingChar({"aa", "bb", "cc"}, {"", "", "ccc"}) ---> 1
+ */
+
+ public static int matchingChar(String[] a, String[] b) {
+
+ int count = 0;
+
+ for (int i = 0; i < a.length; i++) {
+ String str1 = a[i];
+ String str2 = b[i];
+
+ if(!str1.equals("") && !str2.equals("")) {
+ if(str1.charAt(0) == str2.charAt(0))
+ count++;
+ }
+ }
+
+
+ return count;
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
diff --git a/Ahmad/2_puzzles/assignment_14/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_14/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..2f452c6
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_14/src/ignore/TestingUtils.java
@@ -0,0 +1,45 @@
+package ignore;
+
+import java.util.Arrays;
+
+import assignment_14.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+ String[][] params1 = { { "aa", "bb", "cc" }, { "aa", "bb", "cc" }, { "aa", "bb", "cc" }, { "", "", "ccc" },
+ { "", "", "" }, { "aa", "bb", "cc" }, { "aa", "", "ccc" }, { "x", "y", "z" }, { "", "y", "z" },
+ { "x", "y", "z" }, { "x", "y", "z" }, { "b", "x", "y", "z" }, { "aaa", "bb", "c" } };
+
+ String[][] params2 = { { "aaa", "xx", "bb" }, { "aaa", "b", "bb" }, { "", "", "ccc" }, { "aa", "bb", "cc" },
+ { "", "bb", "cc" }, { "", "", "" }, { "", "bb", "cc" }, { "y", "z", "x" }, { "", "y", "x" },
+ { "xx", "yyy", "zzz" }, { "xx", "yyy", "" }, { "a", "xx", "yyy", "zzz" }, { "aaa", "xx", "bb" } };
+
+
+ int[] expected = { 1, 2, 1, 1, 0, 0, 1, 0, 1, 3, 2, 3, 1 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.matchingChar(params1[i], params2[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(String[] params1, String[] params2, Object expected, Object result){
+ String str = "";
+
+ return "PASS: matchingChar("+Arrays.toString(params1)+", "+ Arrays.toString(params2)+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(String[] params1, String[] params2, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: matchingChar("+Arrays.toString(params1)+", "+ Arrays.toString(params2)+") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_15/.classpath b/Ahmad/2_puzzles/assignment_15/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_15/.gitignore b/Ahmad/2_puzzles/assignment_15/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_15/.project b/Ahmad/2_puzzles/assignment_15/.project
new file mode 100644
index 0000000..ce2a280
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_15
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_15/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_15/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_15/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_15/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_15/src/assignment_15/App.java b/Ahmad/2_puzzles/assignment_15/src/assignment_15/App.java
new file mode 100644
index 0000000..2c58417
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/src/assignment_15/App.java
@@ -0,0 +1,59 @@
+package assignment_15;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+ Given a string, return the length of the longest streak of the same chars in the string.
+
+
+
+
+ * EXPECTATIONS:
+ longestStreak("hayyeu") ---> 2
+ longestStreak("XPNzzzddOOOxx") ---> 3
+ longestStreak("") ---> 0
+ */
+
+ public static int longestStreak(String str) {
+
+ int max = 0;
+
+
+
+ for (int i = 0; i < str.length(); i++) {
+ int count = 0;
+
+ for(int j = i; j < str.length(); j++) {
+ if(str.charAt(i) == str.charAt(j))
+ count++;
+ else
+ break;
+ }
+ if (count > max)
+ max = count;
+ }
+ return max;
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
diff --git a/Ahmad/2_puzzles/assignment_15/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_15/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..a6e9675
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_15/src/ignore/TestingUtils.java
@@ -0,0 +1,36 @@
+package ignore;
+
+import assignment_15.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ String[] params1 = { "hoopla", "abbCCCddBBBxx", "", "xyz", "xxyz", "xyzz", "abbbcbbbxbbbx", "XXBBBbbxx",
+ "XXBBBBbbxx", "XXBBBbbxxXXXX", "XX2222BBBbbXX2222" };
+
+ int[] expected = { 2, 3, 0, 1, 2, 2, 3, 3, 4, 4, 4 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.longestStreak(params1[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: longestStreak("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: longestStreak("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_16/.classpath b/Ahmad/2_puzzles/assignment_16/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_16/.gitignore b/Ahmad/2_puzzles/assignment_16/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_16/.project b/Ahmad/2_puzzles/assignment_16/.project
new file mode 100644
index 0000000..5eff228
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_16
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_16/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_16/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_16/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_16/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_16/src/assignment_16/App.java b/Ahmad/2_puzzles/assignment_16/src/assignment_16/App.java
new file mode 100644
index 0000000..481c44a
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/src/assignment_16/App.java
@@ -0,0 +1,60 @@
+package assignment_16;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+ Given a string, compute recursively (no loops) the number of times
+ lowercase "yo" appears in the string.
+
+
+
+ * EXPECTATIONS:
+ yoYo("xhyoxx") ---> 1
+ yoYo("nyonnyon")---> 2
+ yoYo("yo") ---> 1
+ */
+
+ public static int yoYo(String str) {
+
+// int count = 0;
+// for (int i = 0; i < str.length() -1; i++) {
+// if(str.charAt(i) == 'y' && str.charAt(i+1) == 'o')
+// count++;
+// }
+// return count;
+
+
+ if(str.length() < 2)
+ return 0;
+
+ if(str.substring(0, 2).equals("yo"))
+ return 1 + yoYo(str.substring(1));
+
+ else
+
+ return yoYo(str.substring(1));
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
diff --git a/Ahmad/2_puzzles/assignment_16/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_16/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..dcd2da7
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_16/src/ignore/TestingUtils.java
@@ -0,0 +1,36 @@
+package ignore;
+
+import assignment_16.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ String[] params1 = { "xxyoxx", "yyoxyoy", "yo", "yoyoy", "y", "", "oyoyoyoyoy",
+ "oyoyoyoyoyo", "yoAAyo12yo", "xyoxhxiyohhyoh", "yogurt"};
+
+ int[] expected = { 1, 2, 1, 2, 0, 0, 4, 5, 3, 3, 1 };
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.yoYo(params1[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: yoYo("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: yoYo("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_17/.classpath b/Ahmad/2_puzzles/assignment_17/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_17/.gitignore b/Ahmad/2_puzzles/assignment_17/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_17/.project b/Ahmad/2_puzzles/assignment_17/.project
new file mode 100644
index 0000000..93a391d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_17
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_17/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_17/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_17/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_17/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_17/src/assignment_17/App.java b/Ahmad/2_puzzles/assignment_17/src/assignment_17/App.java
new file mode 100644
index 0000000..f094dae
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/src/assignment_17/App.java
@@ -0,0 +1,55 @@
+package assignment_17;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+
+ Given a string, compute recursively a new string where all the
+ lowercase 'o' chars have been moved to the end of the string.
+
+
+
+
+ * EXPECTATIONS:
+ endoo("oore") ---> reoo
+ endoo("oohoi") ---> hiooo
+ endoo("oanotgo") ---> antgooo
+ */
+
+ public static String endoo(String str) {
+
+ // complete the body of this method
+ if(str.equals(""))
+ return str;
+
+ if(str.charAt(0) == 'o')
+ return endoo(str.substring(1)) + 'o';
+
+ else
+ return str.charAt(0) + endoo(str.substring(1));
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
diff --git a/Ahmad/2_puzzles/assignment_17/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_17/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..9268991
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_17/src/ignore/TestingUtils.java
@@ -0,0 +1,37 @@
+package ignore;
+
+import assignment_17.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ String[] params1 = { "oore", "oohioo", "ohiohio", "hiy", "h", "", "o",
+ "oo", "boo", "boao", "aoaoao", "oohoi", "oanotgo"};
+
+ String[] expected = { "reoo", "hioooo", "hihiooo", "hiy", "h", "", "o",
+ "oo", "boo", "baoo", "aaaooo", "hiooo", "antgooo" };
+
+ for(int i=0; i < params1.length; i++){
+ String result = App.endoo(params1[i]);
+ if(result.equals(expected[i])) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: endoo("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: endoo("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_18/.classpath b/Ahmad/2_puzzles/assignment_18/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_18/.gitignore b/Ahmad/2_puzzles/assignment_18/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_18/.project b/Ahmad/2_puzzles/assignment_18/.project
new file mode 100644
index 0000000..a47c0f3
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_18
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_18/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_18/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_18/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_18/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_18/src/assignment_18/App.java b/Ahmad/2_puzzles/assignment_18/src/assignment_18/App.java
new file mode 100644
index 0000000..6f0e0ab
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/src/assignment_18/App.java
@@ -0,0 +1,55 @@
+package assignment_18;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+
+ Given a string, compute recursively a new string where identical chars
+ that are adjacent in the original string are separated from each other by a "-".
+
+
+
+
+ * EXPECTATIONS:
+ repeatHyphen("hello") ---> hel-lo
+ repeatHyphen("xxyy") ---> x-xy-y
+ repeatHyphen("aaaa") ---> a-a-a-a
+ */
+
+ public static String hyphenSplit(String str) {
+
+ // complete the body of this method
+ if(str.length() < 2) {
+ return str;
+ }
+
+ if(str.charAt(0) == str.charAt(1)) {
+ return str.charAt(0) + "-" + hyphenSplit(str.substring(1));
+ }
+
+ return str.charAt(0) + hyphenSplit(str.substring(1));
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
diff --git a/Ahmad/2_puzzles/assignment_18/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_18/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..c19f5d8
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_18/src/ignore/TestingUtils.java
@@ -0,0 +1,37 @@
+package ignore;
+
+import assignment_18.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ String[] params1 = { "hello", "xxyy", "aaaa", "aaab", "aa", "a", "",
+ "noadjacent", "abba", "abbba"};
+
+ String[] expected = { "hel-lo", "x-xy-y", "a-a-a-a", "a-a-ab", "a-a", "a", "",
+ "noadjacent", "ab-ba", "ab-b-ba"};
+
+ for(int i=0; i < params1.length; i++){
+ String result = App.hyphenSplit(params1[i]);
+ if(result.equals(expected[i])) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: hyphenSplit("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: hyphenSplit("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_19/.classpath b/Ahmad/2_puzzles/assignment_19/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_19/.gitignore b/Ahmad/2_puzzles/assignment_19/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/2_puzzles/assignment_19/.project b/Ahmad/2_puzzles/assignment_19/.project
new file mode 100644
index 0000000..24241d2
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/.project
@@ -0,0 +1,17 @@
+
+
+ assignment_19
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Ahmad/2_puzzles/assignment_19/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_19/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_19/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_19/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_19/src/assignment_19/App.java b/Ahmad/2_puzzles/assignment_19/src/assignment_19/App.java
new file mode 100644
index 0000000..a90646f
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/src/assignment_19/App.java
@@ -0,0 +1,53 @@
+package assignment_19;
+
+import ignore.TestingUtils;
+
+public class App {
+
+
+ /**
+ *
+
+ Given a string that contains a single pair of brackets, compute recursively a new string made of
+ only of the brackets and their contents, so "xyz[abc]123" yields "[abc]".
+
+
+
+
+ * EXPECTATIONS:
+ insideBrackets("xyz[abc]123") ---> [abc]
+ insideBrackets("x[hello]") ---> [hello]
+ insideBrackets("[xy]1") ---> [xy]
+ */
+
+ public static String insideBrackets(String str) {
+
+ // complete the body of this method
+ if(str.charAt(0) != '[')
+ return insideBrackets(str.substring(1));
+
+ if(str.charAt(str.length() - 1) != ']')
+ return insideBrackets(str.substring(0, str.length() -1));
+
+ return str;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ //----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+
+ }
+}
+
diff --git a/Ahmad/2_puzzles/assignment_19/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_19/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..0245395
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_19/src/ignore/TestingUtils.java
@@ -0,0 +1,38 @@
+package ignore;
+
+import assignment_19.App;
+
+public class TestingUtils {
+ public static void runTests(){
+
+
+ String[] params1 = { "xyz[abc]123", "x[hello]", "[xy]1", "not really [possible]", "[abc]", "[abc]xyz", "[abc]x",
+ "[x]", "[]", "res [ipsa] loquitor", "hello[not really]there", "ab[ab]ab"};
+
+ String[] expected = { "[abc]", "[hello]", "[xy]", "[possible]", "[abc]", "[abc]", "[abc]",
+ "[x]", "[]", "[ipsa]", "[not really]", "[ab]"};
+
+
+ for(int i=0; i < params1.length; i++){
+ String result = App.insideBrackets(params1[i]);
+ if(result.equals(expected[i])) {
+ System.out.println(printPassResult(params1[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object expected, Object result){
+ return "PASS: insideBrackets("+ params1.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: insideBrackets("+ params1.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/Ahmad/2_puzzles/assignment_n/.classpath b/Ahmad/2_puzzles/assignment_n/.classpath
new file mode 100644
index 0000000..57bca72
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Ahmad/2_puzzles/assignment_n/.gitignore b/Ahmad/2_puzzles/assignment_n/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Ahmad/assigment_01/.project b/Ahmad/2_puzzles/assignment_n/.project
similarity index 92%
rename from Ahmad/assigment_01/.project
rename to Ahmad/2_puzzles/assignment_n/.project
index de97a40..f4c113f 100644
--- a/Ahmad/assigment_01/.project
+++ b/Ahmad/2_puzzles/assignment_n/.project
@@ -1,6 +1,6 @@
- assigment_01
+ assignment_n
diff --git a/Ahmad/2_puzzles/assignment_n/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_n/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/Ahmad/2_puzzles/assignment_n/.settings/org.eclipse.jdt.core.prefs b/Ahmad/2_puzzles/assignment_n/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8c9943d
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/Ahmad/2_puzzles/assignment_n/src/assignment_n/App.java b/Ahmad/2_puzzles/assignment_n/src/assignment_n/App.java
new file mode 100644
index 0000000..635bb70
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/src/assignment_n/App.java
@@ -0,0 +1,34 @@
+package assignment_n;
+
+
+import ignore.TestingUtils;
+
+public class App {
+
+ /**
+ * Add both parameters (a & b) together and
+ * subtract the number 3 and return the result
+ *
+ *
+ * EXPECTATIONS:
+ sumMinus3(2, 5) ---> 4
+ sumMinus3(2, 1) ---> 0
+ sumMinus3(0, 2) ---> -1
+ */
+ public static int sumMinus3(int a, int b) {
+
+ return a+b-3;
+ }
+
+
+
+
+
+
+
+//----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
+ public static void main(String args[]){
+ TestingUtils.runTests();
+ }
+
+}
diff --git a/Ahmad/2_puzzles/assignment_n/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_n/src/ignore/TestingUtils.java
new file mode 100644
index 0000000..a659c5f
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/src/ignore/TestingUtils.java
@@ -0,0 +1,37 @@
+package ignore;
+
+import assignment_n.App;
+
+public class TestingUtils {
+
+ public static void runTests(){
+
+ int [] params1 = {2,0,7,3,1};
+ int [] params2 = {1,3,4,5,2};
+
+ int [] expected = {0,0,8,5,0};
+
+ for(int i=0; i < params1.length; i++){
+ int result = App.sumMinus3(params1[i], params2[i]);
+ if(result == expected[i]) {
+ System.out.println(printPassResult(params1[i], params2[i], expected[i], result));
+ } else{
+ System.out.println(printFailResult(params1[i], params2[i], expected[i], result));
+ }
+ }
+ }
+
+ private static String printPassResult(Object params1, Object params2, Object expected, Object result){
+ return "PASS: sumMinus3("+ params1.toString()+ ", "+ params2.toString()+ ") -> " + result.toString();
+ }
+
+
+ private static String printFailResult(Object params1, Object params2, Object expected, Object result){
+ String ret = "**********************" + "\n";
+ ret += "FAIL: sumMinus3("+ params1.toString()+ ", "+ params2.toString()+ ") -> " + result.toString()
+ + " Expected: "+ expected.toString();
+ ret += "\n" + "**********************";
+ return ret;
+ }
+
+}
diff --git a/Ahmad/2_puzzles/assignment_n/src/module-info.java b/Ahmad/2_puzzles/assignment_n/src/module-info.java
new file mode 100644
index 0000000..25f26ce
--- /dev/null
+++ b/Ahmad/2_puzzles/assignment_n/src/module-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ *
+ */
+module assignment_20 {
+}
\ No newline at end of file
diff --git a/Ahmad/assignment_01/src/assignment_01/App.java b/Ahmad/assignment_01/src/assignment_01/App.java
deleted file mode 100644
index 8e01f22..0000000
--- a/Ahmad/assignment_01/src/assignment_01/App.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package assignment_01;
-
-import ignore.TestingUtils;
-
-public class App {
-
- /**
- Given a string of odd length, return the middle 3 characters from the string,
- so the string "Monitor" yields "nit".
- If the string length is less than 3, return the string as is.
-
- EXPECTATIONS:
- middleThree("bunny") ---> "unn"
- middleThree("peter") ---> "ete"
- middleThree("Jamaica") --->"mai"
- */
-
- public static String middleThree(String str) {
- String result = str;
-
- if(str.length() >= 3) {
- int midIdx = str.length()/2;
- result = str.substring(midIdx-1, midIdx + 2);
- }
-
- return result;
- }
-
-
-
-
-
-
-
-//----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
- public static void main(String args[]){
- TestingUtils.runTests();
- }
-}
diff --git a/Ahmad/cert/.gitignore b/Ahmad/cert/.gitignore
new file mode 100644
index 0000000..e10e727
--- /dev/null
+++ b/Ahmad/cert/.gitignore
@@ -0,0 +1 @@
+/.metadata/
diff --git a/Ahmad/cert/.idea/.gitignore b/Ahmad/cert/.idea/.gitignore
new file mode 100644
index 0000000..5c98b42
--- /dev/null
+++ b/Ahmad/cert/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
\ No newline at end of file
diff --git a/Ahmad/cert/.idea/cert.iml b/Ahmad/cert/.idea/cert.iml
new file mode 100644
index 0000000..16e0a48
--- /dev/null
+++ b/Ahmad/cert/.idea/cert.iml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ahmad/cert/.idea/libraries/lib.xml b/Ahmad/cert/.idea/libraries/lib.xml
new file mode 100644
index 0000000..df50372
--- /dev/null
+++ b/Ahmad/cert/.idea/libraries/lib.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ahmad/cert/.idea/misc.xml b/Ahmad/cert/.idea/misc.xml
new file mode 100644
index 0000000..c6b6842
--- /dev/null
+++ b/Ahmad/cert/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Ahmad/cert/.idea/modules.xml b/Ahmad/cert/.idea/modules.xml
new file mode 100644
index 0000000..dadb392
--- /dev/null
+++ b/Ahmad/cert/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ahmad/cert/.idea/vcs.xml b/Ahmad/cert/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Ahmad/cert/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ahmad/cert/.idea/workspace.xml b/Ahmad/cert/.idea/workspace.xml
new file mode 100644
index 0000000..d8042bf
--- /dev/null
+++ b/Ahmad/cert/.idea/workspace.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1595522228059
+
+
+ 1595522228059
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.lock b/Ahmad/cert/.metadata/.lock
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.mylyn/.repositories.xml.zip b/Ahmad/cert/.metadata/.mylyn/.repositories.xml.zip
new file mode 100644
index 0000000..6377e05
Binary files /dev/null and b/Ahmad/cert/.metadata/.mylyn/.repositories.xml.zip differ
diff --git a/Ahmad/cert/.metadata/.mylyn/.taskListIndex/segments_1 b/Ahmad/cert/.metadata/.mylyn/.taskListIndex/segments_1
new file mode 100644
index 0000000..6363afd
Binary files /dev/null and b/Ahmad/cert/.metadata/.mylyn/.taskListIndex/segments_1 differ
diff --git a/Ahmad/cert/.metadata/.mylyn/.taskListIndex/write.lock b/Ahmad/cert/.metadata/.mylyn/.taskListIndex/write.lock
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.mylyn/.tasks.xml.zip b/Ahmad/cert/.metadata/.mylyn/.tasks.xml.zip
new file mode 100644
index 0000000..61a05bc
Binary files /dev/null and b/Ahmad/cert/.metadata/.mylyn/.tasks.xml.zip differ
diff --git a/Ahmad/cert/.metadata/.mylyn/repositories.xml.zip b/Ahmad/cert/.metadata/.mylyn/repositories.xml.zip
new file mode 100644
index 0000000..7e1e047
Binary files /dev/null and b/Ahmad/cert/.metadata/.mylyn/repositories.xml.zip differ
diff --git a/Ahmad/cert/.metadata/.mylyn/tasks.xml.zip b/Ahmad/cert/.metadata/.mylyn/tasks.xml.zip
new file mode 100644
index 0000000..3e32500
Binary files /dev/null and b/Ahmad/cert/.metadata/.mylyn/tasks.xml.zip differ
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/5065205de6cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/5065205de6cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..ad72333
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/5065205de6cc001a1c9583c41c40e4f0
@@ -0,0 +1,39 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty() == LIMIT) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/80bcf8eb48cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/80bcf8eb48cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..405e519
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/80bcf8eb48cc001a1c9583c41c40e4f0
@@ -0,0 +1,37 @@
+package client;
+
+import inventory.InventoryManager;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ InventoryManager manager = new InventoryManager();
+
+ Thread inventoryTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ Thread displayTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ inventoryTask.start();
+// try {
+// Thread.sleep(2000);
+// } catch (InterruptedException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ inventoryTask.join();
+ displayTask.start();
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/e09ccb1e11cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/e09ccb1e11cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..ba69047
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/10/e09ccb1e11cd001a1d8e8781d501fb14
@@ -0,0 +1,44 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ // executor.shutdown(); // Rejects any new tasks from being submitted
+ // Gracefully shuts down the service
+
+ // executor.shutdownNow(); // Terminates the executor immediately..
+
+ try {
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+// while(!executor.isTerminated()) {
+// }
+
+ System.out.println("submitted all tasks ...");
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/12/40717a9086d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/12/40717a9086d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..0155bd1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/12/40717a9086d0001a1a4afd166bbfcbff
@@ -0,0 +1,138 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/12/c07b6a694bd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/12/c07b6a694bd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..ce36f20
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/12/c07b6a694bd1001a1a4afd166bbfcbff
@@ -0,0 +1,74 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ .filter(x -> x.contains("th"))
+ .collect(Collectors.toList());
+ words.forEach(x -> System.out.print(x + ", "));
+ System.out.println();
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted()
+ .filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/13/a08c1d8686d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/13/a08c1d8686d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..cc49d2b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/13/a08c1d8686d0001a1a4afd166bbfcbff
@@ -0,0 +1,138 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+ System.out.println(reverser.work("Vehicle"));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/15/40d11d2a01cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/15/40d11d2a01cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..2acd61e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/15/40d11d2a01cd001a1c9583c41c40e4f0
@@ -0,0 +1,20 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+public class Application {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ BlockingQueue questionQueue = new ArrayBlockingQueue(5);
+
+ Thread t1 = new Thread(new Producer(questionQueue));
+ Thread t2 = new Thread(new Consumer(questionQueue));
+
+ t1.start();
+ t2.start();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/16/f03f1e0e4ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/16/f03f1e0e4ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..9844148
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/16/f03f1e0e4ad1001a1a4afd166bbfcbff
@@ -0,0 +1,57 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(c -> x.startsWith("C"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", "));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/19/20b84bfc49d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/19/20b84bfc49d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..df7b997
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/19/20b84bfc49d1001a1a4afd166bbfcbff
@@ -0,0 +1,57 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(c -> x.startsWith("C"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", "));
+
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1b/8084e906d5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1b/8084e906d5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..aaaf9c1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1b/8084e906d5d0001a1a4afd166bbfcbff
@@ -0,0 +1,22 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1d/80ba70df48cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1d/80ba70df48cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..e93ebb2
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1d/80ba70df48cc001a1c9583c41c40e4f0
@@ -0,0 +1,37 @@
+package client;
+
+import inventory.InventoryManager;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ InventoryManager manager = new InventoryManager();
+
+ Thread inventoryTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ Thread displayTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ inventoryTask.start();
+// try {
+// Thread.sleep(2000);
+// } catch (InterruptedException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ inverntoryTask.join();
+ displayTask.start();
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1d/d0c833854ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1d/d0c833854ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..2703679
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1d/d0c833854ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractical.files;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("/Lambdas/src/streamsPractical/files/wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1f/00ba3ccf86d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1f/00ba3ccf86d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..d16edbd
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1f/00ba3ccf86d0001a1a4afd166bbfcbff
@@ -0,0 +1,142 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(4));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
+interface GenericInterface{
+ public T work(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1f/80cfb67e02cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1f/80cfb67e02cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..8b1ad3e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/1f/80cfb67e02cd001a1c9583c41c40e4f0
@@ -0,0 +1,5 @@
+package arrayBlockingQueue;
+
+public class Consumer Implements Runnable {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/20/20ff968a0acd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/20/20ff968a0acd001a1d8e8781d501fb14
new file mode 100644
index 0000000..6093aa7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/20/20ff968a0acd001a1d8e8781d501fb14
@@ -0,0 +1,24 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Consumer implements Runnable {
+
+ BlockingQueue questionQueue;
+
+ public Consumer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ System.out.println("ANSWERED QUESTION: " + questionQueue.take());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/23/1023239386d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/23/1023239386d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..a07f6ed
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/23/1023239386d0001a1a4afd166bbfcbff
@@ -0,0 +1,139 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(10));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/24/8076394d0acd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/24/8076394d0acd001a1d8e8781d501fb14
new file mode 100644
index 0000000..e55c160
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/24/8076394d0acd001a1d8e8781d501fb14
@@ -0,0 +1,23 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Consumer implements Runnable() {
+
+ BlockingQueue questionQueue;
+
+ public Consumer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+ questionNo++;
+ try {
+ questionQueue.put(questionNo);
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/25/b0371f6a49d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/25/b0371f6a49d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..876b45e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/25/b0371f6a49d1001a1a4afd166bbfcbff
@@ -0,0 +1,48 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6 ,8 ,10})
+ .map((x) -> x * x)
+ .average()
+ ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/26/20a9af3887d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/26/20a9af3887d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..9de4e70
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/26/20a9af3887d0001a1a4afd166bbfcbff
@@ -0,0 +1,143 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ //StringWorker reverser = (s) -> {
+ MyGenericInterface reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(4));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
+interface MyGenericInterface{
+ public T work(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/26/805e193ebdcf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/26/805e193ebdcf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/28/50edfa6a49cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/28/50edfa6a49cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..eec1eb8
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/28/50edfa6a49cc001a1c9583c41c40e4f0
@@ -0,0 +1,33 @@
+package client;
+
+import inventory.InventoryManager;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ InventoryManager manager = new InventoryManager();
+
+ Thread inventoryTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ Thread displayTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ inventoryTask.start();
+// Thread.sleep(2000);
+// inventoryTask.join();
+
+ displayTask.start();
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/28/a021ec7dd5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/28/a021ec7dd5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..37671aa
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/28/a021ec7dd5d0001a1a4afd166bbfcbff
@@ -0,0 +1,52 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+ printCarsPriceRange(cars, 18000, 22000);
+ printCarByColor(cars, "Red");
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/29/50b2264908d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/29/50b2264908d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..ecd05de
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/29/50b2264908d0001a1a4afd166bbfcbff
@@ -0,0 +1,6 @@
+package lambdasPractice;
+
+@FunctionalInterface
+public interface ALambdaInterface {
+ public void walk();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2b/605b623c4cd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2b/605b623c4cd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..2824ce9
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2b/605b623c4cd1001a1a4afd166bbfcbff
@@ -0,0 +1,95 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream rows = Files.lines(Paths.get("files/stockDataCsv.text"));
+ rows.map(x -> x.split(", "))
+ .filter(x -> x.length > 3)
+ .filter(x -> Integer.parseInt(x[1].trim()) > 15)
+ .foreEach(x -> System.out.println(x[0].trim() + " " + x[2].trim() + " " + x[3].trim()));
+ rows.close();
+
+
+ //
+ Stream rows = Files.lines(Paths.get("files/stockDataCsv.text"));
+ int rowCount = (int) rows
+ .map(x -> x.split(","))
+ .filter(x -> x.length > 3)
+ .count();
+ System.out.println(rowCount + " good rows.");
+ rows.close();
+
+
+
+ //
+ List words = Files.lines(Paths.get("files/wordFile.txt"))
+ .filter(x -> x.contains("th"))
+ .collect(Collectors.toList());
+ words.forEach(x -> System.out.print(x + ", "));
+ System.out.println();
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted()
+ .filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2d/807c0e2b67d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2d/807c0e2b67d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..15a6ec7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2d/807c0e2b67d0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// };
+// return arg1/arg2;
+// };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60cb2bd8e4cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60cb2bd8e4cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..7ab9c3f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60cb2bd8e4cc001a1c9583c41c40e4f0
@@ -0,0 +1,18 @@
+package producerConsumer;
+
+import java.util.ArrayList;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ List questionList = new ArrayList();
+
+ Thread t1 = new Thread(new Producer(questionList));
+ Thread t2 = new Thread(new Consumer(questionList));
+
+ t1.start();
+ t2.start();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3/d0a78b52e6cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3/d0a78b52e6cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..8dd1fb1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3/d0a78b52e6cc001a1c9583c41c40e4f0
@@ -0,0 +1,39 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion() throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty() == LIMIT) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/30/00dea66986d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/30/00dea66986d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..bb4259b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/30/00dea66986d0001a1a4afd166bbfcbff
@@ -0,0 +1,125 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/31/6070845f0fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/31/6070845f0fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..1e865bf
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/31/6070845f0fcd001a1d8e8781d501fb14
@@ -0,0 +1,12 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/32/304a88c30ed0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/32/304a88c30ed0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..ddb01e8
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/32/304a88c30ed0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ helloVar.someMethod();
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+
+ Calculate sumVar = (a, b) -> return arg1+arg2;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println("w");
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0bae0fe49d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0bae0fe49d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..d7988db
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0bae0fe49d1001a1a4afd166bbfcbff
@@ -0,0 +1,57 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(c -> x.startsWith("C"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", "));
+ }
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/34/100c72cd4ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/34/100c72cd4ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..f255101
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/34/100c72cd4ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("/files/wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/35/500937fdd7d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/35/500937fdd7d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..d227737
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/35/500937fdd7d0001a1a4afd166bbfcbff
@@ -0,0 +1,73 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ System.out.println("Printing cars that are blue");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getColor().equals("Blue");
+ }
+
+ });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000)
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test(Car c);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/36/50605efc4ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/36/50605efc4ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..3188a9a
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/36/50605efc4ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/37/70bdcdb30fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/37/70bdcdb30fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..496be3e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/37/70bdcdb30fcd001a1d8e8781d501fb14
@@ -0,0 +1,23 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor);
+
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/38/00bfeca045d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/38/00bfeca045d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..4fe7215
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/38/00bfeca045d1001a1a4afd166bbfcbff
@@ -0,0 +1,82 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+
+ Function priceAndColor (c) -> " price = " + c.getPrice() + " color = " + c.getColor();
+
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ System.out.println("Printing cars that are blue");
+
+// printCars(cars, new CarCondition() {
+// @Override
+// public boolean test(Car c) {
+// return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+// }
+// });
+
+
+// printCars(cars, new CarCondition() {
+//
+// @Override
+// public boolean test(Car c) {
+// return c.getColor().equals("Blue");
+// }
+//
+// });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ // public static void printCars(List cars, CarCondition condition) {
+ public static void printCars(List cars, Predicate predicate) {
+ for(Car c: cars) {
+ if(predicate.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface Condition {
+ public boolean test(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/39/10d5fa5949d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/39/10d5fa5949d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..2501aab
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/39/10d5fa5949d1001a1a4afd166bbfcbff
@@ -0,0 +1,48 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6 ,8 ,10})
+ .map((x) -> * x)
+ .average()
+ ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3a/30d6f7f90ed0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3a/30d6f7f90ed0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..dc2fe5c
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3a/30d6f7f90ed0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ helloVar.someMethod();
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println("w");
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3c/30012bf686d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3c/30012bf686d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..c1630cb
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3c/30012bf686d0001a1a4afd166bbfcbff
@@ -0,0 +1,143 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ //StringWorker reverser = (s) -> {
+ MyGenericInterface reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(4));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
+interface GenericInterface{
+ public T work(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3d/009ea3770acd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3d/009ea3770acd001a1d8e8781d501fb14
new file mode 100644
index 0000000..6116eea
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3d/009ea3770acd001a1d8e8781d501fb14
@@ -0,0 +1,34 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+ try {
+ synchronized(this) {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ questionQueue.put(nextQuestion);
+ }
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+}
+//
+//
+//
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3d/80fdcaabd5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3d/80fdcaabd5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..65618ae
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3d/80fdcaabd5d0001a1a4afd166bbfcbff
@@ -0,0 +1,55 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+ printCars(cars, new CarCondition() {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3e/c01b7519d8d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3e/c01b7519d8d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..5d1b5cf
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/3e/c01b7519d8d0001a1a4afd166bbfcbff
@@ -0,0 +1,73 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ System.out.println("Printing cars that are blue");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getColor().equals("Blue");
+ }
+
+ });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test(Car c);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4/600e808fe6cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4/600e808fe6cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..03c3555
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4/600e808fe6cc001a1c9583c41c40e4f0
@@ -0,0 +1,38 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty()) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.notify();
+ }
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion(questionNo++);
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4/702d28a847d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4/702d28a847d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/42/007d21f9e5cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/42/007d21f9e5cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..8090fb2
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/42/007d21f9e5cc001a1c9583c41c40e4f0
@@ -0,0 +1,41 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ Object myObject = new Object();
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void readQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ System.out.println("New Question: " + questionNo.remove(0));
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ readQuestion(questionNo++);
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/43/6073874f66d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/43/6073874f66d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..dc39e51
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/43/6073874f66d0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println("w");
+ }
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/45/5060ea14d4d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/45/5060ea14d4d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..f8b82e0
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/45/5060ea14d4d0001a1a4afd166bbfcbff
@@ -0,0 +1,21 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500),
+ );
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/45/a02efe7186d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/45/a02efe7186d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..3b3642f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/45/a02efe7186d0001a1a4afd166bbfcbff
@@ -0,0 +1,138 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+ System.out.println(reverser.work("Vehicle"));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/47/e089b1f10bcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/47/e089b1f10bcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..6468d0d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/47/e089b1f10bcd001a1d8e8781d501fb14
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
+org.eclipse.jdt.core.compiler.compliance=9
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=9
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/48/10b7cfe193cf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/48/10b7cfe193cf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6495daf
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/48/10b7cfe193cf001a1a4afd166bbfcbff
@@ -0,0 +1,5 @@
+package lambdasPractice;
+
+public class Human {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/48/502fad0f84d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/48/502fad0f84d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..4fbcfeb
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/48/502fad0f84d0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/49/3072021886d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/49/3072021886d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..94e77bf
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/49/3072021886d0001a1a4afd166bbfcbff
@@ -0,0 +1,116 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle");
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4b/00cc7f25e9cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4b/00cc7f25e9cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4c/80b9fa4210cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4c/80b9fa4210cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..b79397c
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4c/80b9fa4210cd001a1d8e8781d501fb14
@@ -0,0 +1,27 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ executor.shutdown(); // Rejects any new tasks from being submitted
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4d/f000dc45e3cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4d/f000dc45e3cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..fbf652d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4d/f000dc45e3cc001a1c9583c41c40e4f0
@@ -0,0 +1,32 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ Object myObject = new Object();
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void readQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ System.out.println("New Question: " + questionNo);
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/605f0f6a4acc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/605f0f6a4acc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/70b4ba6e49cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/70b4ba6e49cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..7ad4ad0
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/70b4ba6e49cc001a1c9583c41c40e4f0
@@ -0,0 +1,33 @@
+package client;
+
+import inventory.InventoryManager;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ InventoryManager manager = new InventoryManager();
+
+ Thread inventoryTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ Thread displayTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ inventoryTask.start();
+ Thread.sleep(2000);
+// inventoryTask.join();
+
+ displayTask.start();
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/a090cbc00dd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/a090cbc00dd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..0df3224
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/4f/a090cbc00dd0001a1a4afd166bbfcbff
@@ -0,0 +1,88 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ Calculate sumVar = (a, b) -> a+b;
+ helloVar.someMethod();
+ System.out.println(sumVar.compute(4, 6));
+ }
+
+ ////
+ public int sum(int arg1, int arg2) {
+ return arg1+arg2;
+ }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ }
+ return arg1/arg2;
+ }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10, 2));
+
+ }
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5/3029ad454bd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5/3029ad454bd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..57fc9f1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5/3029ad454bd1001a1a4afd166bbfcbff
@@ -0,0 +1,66 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted().filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/51/00e7444586d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/51/00e7444586d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..df0f80a
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/51/00e7444586d0001a1a4afd166bbfcbff
@@ -0,0 +1,116 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/53/90566ad4e4cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/53/90566ad4e4cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..9b01877
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/53/90566ad4e4cc001a1c9583c41c40e4f0
@@ -0,0 +1,16 @@
+package producerConsumer;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ List questionList = new ArrayList();
+
+ Thread t1 = new Thread(new Producer(questionList));
+ Thread t2 = new Thread(new Consumer(questionList));
+
+ t1.start();
+ t2.start();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/54/401e09394cd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/54/401e09394cd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..f102902
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/54/401e09394cd1001a1a4afd166bbfcbff
@@ -0,0 +1,86 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream rows = Files.lines(Paths.get("files/stockDataCsv.text"));
+ int rowCount = (int) rows
+ .map(x -> x.split(","))
+ .filter(x -> x.length > 3)
+ .count();
+ System.out.println(rowCount + " good rows.");
+ rows.close();
+
+
+
+ //
+ List words = Files.lines(Paths.get("files/wordFile.txt"))
+ .filter(x -> x.contains("th"))
+ .collect(Collectors.toList());
+ words.forEach(x -> System.out.print(x + ", "));
+ System.out.println();
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted()
+ .filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/54/c0566a35e5cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/54/c0566a35e5cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..1cc614f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/54/c0566a35e5cc001a1c9583c41c40e4f0
@@ -0,0 +1,42 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ Object myObject = new Object();
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void readQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ System.out.println("New Question: " + questionNo.remove(0));
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ readQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/55/80eee48afecc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/55/80eee48afecc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..fcc2cc0
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/55/80eee48afecc001a1c9583c41c40e4f0
@@ -0,0 +1,33 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+
+ try {
+ synchronized(this) {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ questionQueue.put(nextQuestion);
+ }
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
+}}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/57/40fe2e0166d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/57/40fe2e0166d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..efb50a0
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/57/40fe2e0166d0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivider(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println("w");
+ }
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/57/80c19f9fd5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/57/80c19f9fd5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..b03d565
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/57/80c19f9fd5d0001a1a4afd166bbfcbff
@@ -0,0 +1,55 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+ printCars(cars, new CarCondition() {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface Condition {
+ public boolean test();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0fc3b7ad3d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0fc3b7ad3d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5a/8044c52fbccf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5a/8044c52fbccf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..8f32c04
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5a/8044c52fbccf001a1a4afd166bbfcbff
@@ -0,0 +1,7 @@
+package lambdasPractice;
+
+public class Robot {
+ public void walk() {
+ System.out.println("Robot Walking");
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5c/605a9bf885d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5c/605a9bf885d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..9d10723
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5c/605a9bf885d0001a1a4afd166bbfcbff
@@ -0,0 +1,113 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ return reuslt;
+ };
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5c/d080f44a10cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5c/d080f44a10cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..b100e73
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5c/d080f44a10cd001a1d8e8781d501fb14
@@ -0,0 +1,32 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ executor.shutdown(); // Rejects any new tasks from being submitted
+
+
+ while(!executor.isTerminated()) {
+ System.out.println("submitted all tasks ...");
+ }
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5e/202672d4e1cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5e/202672d4e1cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..a791601
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5e/202672d4e1cc001a1c9583c41c40e4f0
@@ -0,0 +1,20 @@
+package producerConsumer;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ @Override
+ public void run(int questionNo) {
+ with(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5e/601d19485cce001a1a9cc199e4fddddb b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5e/601d19485cce001a1a9cc199e4fddddb
new file mode 100644
index 0000000..07d2c19
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5e/601d19485cce001a1a9cc199e4fddddb
@@ -0,0 +1,44 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ // executor.shutdown(); // Rejects any new tasks from being submitted
+ // Gracefully shuts down the service
+
+ // executor.shutdownNow(); // Terminates the executor immediately..
+
+// try {
+// executor.awaitTermination(2, TimeUnit.SECONDS);
+// } catch (InterruptedException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+
+
+ while(!executor.isTerminated()) {
+ }
+
+ System.out.println("submitted all tasks ...");
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/30054a330ed0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/30054a330ed0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..dd6339a
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/30054a330ed0001a1a4afd166bbfcbff
@@ -0,0 +1,86 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+
+// ALambdaInterface helloVar = () -> System.out.println("hello there");
+// Calculate sumVar = (a, b) -> a+b;
+// helloVar.someMethod();
+// System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10, 2));
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/30055e624cd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/30055e624cd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..41b537d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/30055e624cd1001a1a4afd166bbfcbff
@@ -0,0 +1,95 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream rows = Files.lines(Paths.get("files/stockDataCsv.text"));
+ rows.map(x -> x.split(", "))
+ .filter(x -> x.length > 3)
+ .filter(x -> Integer.parseInt(x[1].trim()) > 15)
+ .forEach(x -> System.out.println(x[0].trim() + " " + x[2].trim() + " " + x[3].trim()));
+ rows.close();
+
+
+ //
+ Stream rows = Files.lines(Paths.get("files/stockDataCsv.text"));
+ int rowCount = (int) rows
+ .map(x -> x.split(","))
+ .filter(x -> x.length > 3)
+ .count();
+ System.out.println(rowCount + " good rows.");
+ rows.close();
+
+
+
+ //
+ List words = Files.lines(Paths.get("files/wordFile.txt"))
+ .filter(x -> x.contains("th"))
+ .collect(Collectors.toList());
+ words.forEach(x -> System.out.print(x + ", "));
+ System.out.println();
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted()
+ .filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/e08fe3a048d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/e08fe3a048d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..c6b29b1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/5f/e08fe3a048d1001a1a4afd166bbfcbff
@@ -0,0 +1,24 @@
+package streamsPractical.files;
+
+import java.util.stream.IntStream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0c2ee1be9cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0c2ee1be9cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/60/a0344e8e45d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/60/a0344e8e45d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..018ce93
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/60/a0344e8e45d1001a1a4afd166bbfcbff
@@ -0,0 +1,76 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ System.out.println("Printing cars that are blue");
+
+// printCars(cars, new CarCondition() {
+// @Override
+// public boolean test(Car c) {
+// return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+// }
+// });
+
+
+// printCars(cars, new CarCondition() {
+//
+// @Override
+// public boolean test(Car c) {
+// return c.getColor().equals("Blue");
+// }
+//
+// });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ // public static void printCars(List cars, CarCondition condition) {
+ public static void printCars(List cars, Predicate predicate) {
+ for(Car c: cars) {
+ if(predicate.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface Condition {
+ public boolean test(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/61/007d67bc09cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/61/007d67bc09cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..b9be092
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/61/007d67bc09cd001a1d8e8781d501fb14
@@ -0,0 +1,48 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+ questionNo++;
+ try {
+ questionQueue.put(questionNo);
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+ private synchronized int getNextQuestion() {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ return nextQuestion;
+ }
+
+}
+//
+// try {
+// synchronized(this) {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// questionQueue.put(nextQuestion);
+// }
+// } catch (InterruptedException e) {
+// System.out.println("Error: " + e);
+// }
+// }
+//
+//
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/63/d0257473d3d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/63/d0257473d3d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..7023803
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/63/d0257473d3d0001a1a4afd166bbfcbff
@@ -0,0 +1,48 @@
+package practicalLamdbaExample;
+
+public class Car {
+ String make, model, color;
+ int price;
+ public Car(String make, String model, String color, int price) {
+ super();
+ this.make = make;
+ this.model = model;
+ this.color = color;
+ this.price = price;
+ }
+ 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;
+ }
+ public int getPrice() {
+ return price;
+ }
+ public void setPrice(int price) {
+ this.price = price;
+ }
+
+ public void printCar() {
+ System.out.println(this);
+ }
+
+ @Override
+ public String toString() {
+ return "Car [make=" + make + ", model=" + model + ", color=" + color + ", price=" + price + "]";
+ }
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/64/406ccf1349d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/64/406ccf1349d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..187bafc
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/64/406ccf1349d1001a1a4afd166bbfcbff
@@ -0,0 +1,32 @@
+package streamsPractical.files;
+
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/66/409a7fd086d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/66/409a7fd086d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..507fb1d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/66/409a7fd086d0001a1a4afd166bbfcbff
@@ -0,0 +1,142 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ MyGenericeInterfae reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(4));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
+interface GenericInterface{
+ public T work(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/67/d08dacc700cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/67/d08dacc700cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..dff6da1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/67/d08dacc700cd001a1c9583c41c40e4f0
@@ -0,0 +1,34 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Overrides
+ public void run() {
+
+ try {
+ synchronized(this) {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ questionQueue.put(nextQuestion);
+ }
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
+}}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/68/a00ec5f40fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/68/a00ec5f40fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..ed26c46
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/68/a00ec5f40fcd001a1d8e8781d501fb14
@@ -0,0 +1,23 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ executor.shutdown(); // Rejects any new tasks from being submitted
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/6e/f012aa6b84d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/6e/f012aa6b84d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..d511a9e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/6e/f012aa6b84d0001a1a4afd166bbfcbff
@@ -0,0 +1,104 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+ public String reverse(String str) {
+ String result = "";
+ for(int i = str.length() - 1; i >=0; i--) {
+ result = str +str.charAt(i);
+ }
+ return result;
+ };
+
+ (str) -> {
+ String result ="";
+ }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7/003a757effcc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7/003a757effcc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..08faf54
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7/003a757effcc001a1c9583c41c40e4f0
@@ -0,0 +1,33 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue = new ArrayBlockingQueue();
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+
+ try {
+ synchronized(this) {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ questionQueue.put(nextQuestion);
+ }
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
+}}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/71/c03094b34ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/71/c03094b34ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..a54a6ad
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/71/c03094b34ad1001a1a4afd166bbfcbff
@@ -0,0 +1,6 @@
+APPL, 92, 145, 422, 600
+FB, 122, 221
+AMZN, 329, 690, 849
+GOOG,
+NVDA, 110, 217
+AMD, 9, 7, 12, 14, 18
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/72/401f2f1284d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/72/401f2f1284d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..63cdfe8
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/72/401f2f1284d0001a1a4afd166bbfcbff
@@ -0,0 +1,99 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // reverse a string
+ public String reverse(String str) {
+ String result = '';
+ for(int i = str.length() - 1; i >=0; i--) {
+ result = str +str.charAt(i);
+ }
+ }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/72/80b39e92e6cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/72/80b39e92e6cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..25cd7d1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/72/80b39e92e6cc001a1c9583c41c40e4f0
@@ -0,0 +1,38 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty()) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.notify();
+ }
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/74/90ae1e7ebdcf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/74/90ae1e7ebdcf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..340ad5d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/74/90ae1e7ebdcf001a1a4afd166bbfcbff
@@ -0,0 +1,5 @@
+package lambdasPractice;
+
+public interface ALambdaInterface {
+ public void someMethod();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/76/6060a823bccf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/76/6060a823bccf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..f1da235
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/76/6060a823bccf001a1a4afd166bbfcbff
@@ -0,0 +1,5 @@
+package lambdasPractice;
+
+public interface Walkable {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/76/a05f40cd48d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/76/a05f40cd48d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..b74972f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/76/a05f40cd48d1001a1a4afd166bbfcbff
@@ -0,0 +1,31 @@
+package streamsPractical.files;
+
+import java.util.stream.IntStream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/77/404b67980dd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/77/404b67980dd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6bb6e63
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/77/404b67980dd0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ Calculate sumVar = (a, b) -> a+b;
+ helloVar.someMethod();
+ System.out.println(sumVar.compute(4, 6));
+
+ ////
+ public int sum(int arg1, int arg2) {
+ return arg1+arg2;
+ }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ }
+ return arg1/arg2;
+ }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10, 2));
+
+ }
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7c/501110684ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7c/501110684ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..288a6bd
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7c/501110684ad1001a1a4afd166bbfcbff
@@ -0,0 +1,57 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7f/907639ba84d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7f/907639ba84d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..787b63a
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/7f/907639ba84d0001a1a4afd166bbfcbff
@@ -0,0 +1,108 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ };
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8/3078fd20e9cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8/3078fd20e9cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/009657580fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/009657580fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..4def4f7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/009657580fcd001a1d8e8781d501fb14
@@ -0,0 +1,5 @@
+package threadPools;
+
+public class ThreadPoolDemo {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/b070e258eacc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/b070e258eacc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..ae3dd17
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/b070e258eacc001a1c9583c41c40e4f0
@@ -0,0 +1,5 @@
+package arrayBlockingQueue;
+
+public class Producer {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/d094da0ad5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/d094da0ad5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..04a21ba
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/80/d094da0ad5d0001a1a4afd166bbfcbff
@@ -0,0 +1,40 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+ printCarsPriceRange(cars, 18000, 22000);
+ printCarByColor(cars, "Red");'
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/82/30dead044ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/82/30dead044ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..5477d59
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/82/30dead044ad1001a1a4afd166bbfcbff
@@ -0,0 +1,57 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(c -> x.startsWith("C"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", "));
+ }}
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/83/b06d52a7d5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/83/b06d52a7d5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..31f2315
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/83/b06d52a7d5d0001a1a4afd166bbfcbff
@@ -0,0 +1,55 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+ printCars(cars, new CarCondition() {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface condition {
+ public boolean test();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/85/90f7c65607d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/85/90f7c65607d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..340ad5d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/85/90f7c65607d0001a1a4afd166bbfcbff
@@ -0,0 +1,5 @@
+package lambdasPractice;
+
+public interface ALambdaInterface {
+ public void someMethod();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/86/c04905a9e3cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/86/c04905a9e3cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..c95052e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/86/c04905a9e3cc001a1c9583c41c40e4f0
@@ -0,0 +1,5 @@
+package producerConsumer;
+
+public class Consumer {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8a/80702cec47d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8a/80702cec47d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8b/c08413c9e8cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8b/c08413c9e8cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..9a39e59
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8b/c08413c9e8cc001a1c9583c41c40e4f0
@@ -0,0 +1,39 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion() throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty()) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.notify();
+ }
+ }
+
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8c/10dc8e4d84d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8c/10dc8e4d84d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..df8ba2b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8c/10dc8e4d84d0001a1a4afd166bbfcbff
@@ -0,0 +1,100 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // reverse a string
+ public String reverse(String str) {
+ String result = '';
+ for(int i = str.length() - 1; i >=0; i--) {
+ result = str +str.charAt(i);
+ }
+ return result;
+ }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8c/806dc81cbccf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8c/806dc81cbccf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8d/000d1aa34ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8d/000d1aa34ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..58b8165
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8d/000d1aa34ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractical.files;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("/files/wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/106ae37ae6cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/106ae37ae6cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..b24196b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/106ae37ae6cc001a1c9583c41c40e4f0
@@ -0,0 +1,37 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty() == LIMIT) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/9095d3e6e3cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/9095d3e6e3cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..ad72333
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/9095d3e6e3cc001a1c9583c41c40e4f0
@@ -0,0 +1,39 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty() == LIMIT) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/e09c8c7cbdcf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/e09c8c7cbdcf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..a3422b7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/e09c8c7cbdcf001a1a4afd166bbfcbff
@@ -0,0 +1,5 @@
+package lambdasPractice;
+
+public class ALambdaInterface {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/f076dd1a0acd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/f076dd1a0acd001a1d8e8781d501fb14
new file mode 100644
index 0000000..01de9c2
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/8e/f076dd1a0acd001a1d8e8781d501fb14
@@ -0,0 +1,24 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Consumer public Consumer(BlockingQueue questionQueue) {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Consumer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+ questionNo++;
+ try {
+ questionQueue.put(questionNo);
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/91/30a34b9ed5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/91/30a34b9ed5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..b93ec96
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/91/30a34b9ed5d0001a1a4afd166bbfcbff
@@ -0,0 +1,55 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+ printCars(cars, new CarCOndition() {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/92/c06d821111cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/92/c06d821111cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..24bab8b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/92/c06d821111cd001a1d8e8781d501fb14
@@ -0,0 +1,38 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ // executor.shutdown(); // Rejects any new tasks from being submitted
+ // Gracefully shuts down the service
+
+ // executor.shutdownNow(); // Terminates the executor immediately..
+
+ executor.awaitTermination(10, TimeUnit.SECONDS);
+
+
+// while(!executor.isTerminated()) {
+// }
+
+ System.out.println("submitted all tasks ...");
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/30965f4c08d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/30965f4c08d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..54144df
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/30965f4c08d0001a1a4afd166bbfcbff
@@ -0,0 +1,8 @@
+package lambdasPractice;
+
+@FunctionalInterface
+public interface ALambdaInterface {
+ public void walk();
+
+ public void someMethod();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/e03f795c07d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/e03f795c07d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6455060
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/e03f795c07d0001a1a4afd166bbfcbff
@@ -0,0 +1,6 @@
+package lambdasPractice;
+
+@FunctionalInterface
+public interface ALambdaInterface {
+ public void someMethod();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/f0062b130ccd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/93/f0062b130ccd001a1d8e8781d501fb14
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/806a0c82ffcc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/806a0c82ffcc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..8fb5b65
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/806a0c82ffcc001a1c9583c41c40e4f0
@@ -0,0 +1,34 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Overrides
+ public void run() {
+
+ try {
+ synchronized(this) {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ questionQueue.put(nextQuestion);
+ }
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/d05a6c8684d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/d05a6c8684d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..5c3592e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/d05a6c8684d0001a1a4afd166bbfcbff
@@ -0,0 +1,107 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+ public String reverse(String str) {
+ String result = "";
+ for(int i = str.length() - 1; i >=0; i--) {
+ result = str +str.charAt(i);
+ }
+ return result;
+
+ (str) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ }
+ }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/f007a5158bd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/94/f007a5158bd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/95/000708ee86d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/95/000708ee86d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..1065c0d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/95/000708ee86d0001a1a4afd166bbfcbff
@@ -0,0 +1,142 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ MyGenericInterface reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(4));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
+interface GenericInterface{
+ public T work(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/96/604446eb85d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/96/604446eb85d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..5c5f882
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/96/604446eb85d0001a1a4afd166bbfcbff
@@ -0,0 +1,109 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ reverser = (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ return reuslt;
+ };
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/96/d03a318101cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/96/d03a318101cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..cb6bd3f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/96/d03a318101cd001a1c9583c41c40e4f0
@@ -0,0 +1,34 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+}
+// @Overrides
+// public void run() {
+//
+// try {
+// synchronized(this) {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// questionQueue.put(nextQuestion);
+// }
+// } catch (InterruptedException e) {
+// System.out.println("Error: " + e);
+// }
+// }
+//
+//
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/97/409abe2ad4d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/97/409abe2ad4d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..54208a8
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/97/409abe2ad4d0001a1a4afd166bbfcbff
@@ -0,0 +1,21 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/99/50a335c30ecd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/99/50a335c30ecd001a1d8e8781d501fb14
new file mode 100644
index 0000000..6e11ea9
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/99/50a335c30ecd001a1d8e8781d501fb14
@@ -0,0 +1,5 @@
+package threadPools;
+
+public class MessageProcessor {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/99/a07b835a0dd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/99/a07b835a0dd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..ca972aa
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/99/a07b835a0dd0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ Calculate sumVar = (a, b) -> a+b;
+ helloVar.someMethod();
+ System.out.println(sumVar.compute(4, 6));
+
+ ////
+ public int sum(int arg1, int arg2) {
+ return arg1+arg2;
+ }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ }
+ return arg1/arg2;
+ }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a ==0 ) {
+ return 0;
+ }
+ return a/b;
+ }
+
+
+
+ }
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9b/40c4234949d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9b/40c4234949d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6e91c43
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9b/40c4234949d1001a1a4afd166bbfcbff
@@ -0,0 +1,39 @@
+package streamsPractical.files;
+
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9c/0080f5a284d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9c/0080f5a284d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..b5f7cc4
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9c/0080f5a284d0001a1a4afd166bbfcbff
@@ -0,0 +1,107 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+ public String reverse(String str) {
+ String result = "";
+ for(int i = str.length() - 1; i >=0; i--) {
+ result = str +str.charAt(i);
+ }
+ return result;
+
+ (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ };
+ }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9c/10694edb0ed0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9c/10694edb0ed0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..45b9b79
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9c/10694edb0ed0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ helloVar.someMethod();
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println("w");
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9d/b0fc3ebf4bd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9d/b0fc3ebf4bd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e3333c3
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/9d/b0fc3ebf4bd1001a1a4afd166bbfcbff
@@ -0,0 +1,75 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ List words = Files.lines(Paths.get("files/wordFile.txt"))
+ .filter(x -> x.contains("th"))
+ .collect(Collectors.toList());
+ words.forEach(x -> System.out.print(x + ", "));
+ System.out.println();
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted()
+ .filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a/90da84aee9cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a/90da84aee9cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..fb572f9
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a/90da84aee9cc001a1c9583c41c40e4f0
@@ -0,0 +1,10 @@
+package arrayBlockingQueue;
+
+public class Application {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a1/102a4d7f4ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a1/102a4d7f4ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..1d4e509
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a1/102a4d7f4ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractical.files;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("/wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a3/c01e4816d8d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a3/c01e4816d8d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..3ba3935
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a3/c01e4816d8d0001a1a4afd166bbfcbff
@@ -0,0 +1,73 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ System.out.println("Printing cars that are blue");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getColor().equals("Blue");
+ }
+
+ });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test(Car c);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a3/f077d5e50ecd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a3/f077d5e50ecd001a1d8e8781d501fb14
new file mode 100644
index 0000000..32d074c
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a3/f077d5e50ecd001a1d8e8781d501fb14
@@ -0,0 +1,27 @@
+package threadPools;
+
+public class MessageProcessor {
+
+ private int message;
+
+ public MessageProcessor(int message) {
+ this.message = message;
+ }
+
+ @Override
+ public void run() {
+ System.out.println(Thread.currentThread().getName() + " [RECEIVED] Message = " + message);
+ respondToMessage(); // make thread sleep to simulate doing some work
+ System.out.println(Thread.currentThread().getName() + "(DONE) Processing Message = " + message);
+ }
+
+ private void respondToMessage() {
+
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {
+ System.out.println("Unable to process message " + message);
+ }
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a4/30a2b45e0dd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a4/30a2b45e0dd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6139438
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a4/30a2b45e0dd0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ Calculate sumVar = (a, b) -> a+b;
+ helloVar.someMethod();
+ System.out.println(sumVar.compute(4, 6));
+
+ ////
+ public int sum(int arg1, int arg2) {
+ return arg1+arg2;
+ }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ }
+ return arg1/arg2;
+ }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ }
+
+
+
+ }
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a4/8060e9f5d7d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a4/8060e9f5d7d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6754299
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a4/8060e9f5d7d0001a1a4afd166bbfcbff
@@ -0,0 +1,71 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ System.out.println("Printing cars that are blue");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getColor().equals("Blue");
+ }
+
+ });
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test(Car c);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a6/4042202a01cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a6/4042202a01cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..67f3174
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a6/4042202a01cd001a1c9583c41c40e4f0
@@ -0,0 +1,5 @@
+package arrayBlockingQueue;
+
+public class Consumer {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a7/403b5bf085d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a7/403b5bf085d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..80384d6
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a7/403b5bf085d0001a1a4afd166bbfcbff
@@ -0,0 +1,113 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ reverser = (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ return reuslt;
+ };
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a8/80a0bdb586d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a8/80a0bdb586d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..cde81dd
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a8/80a0bdb586d0001a1a4afd166bbfcbff
@@ -0,0 +1,139 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length()-1; i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+
+
+ NumberWorker computedNumber = (n) -> {
+ int result = 1;
+ for(int i =1; i<= n; i++) {
+ result =i*result;
+ }
+ return result;
+ };
+
+ System.out.println(reverser.work("Vehicle"));
+ System.out.println(computedNumber.compute(4));
+ }
+
+ // public factorial method
+ public int factorial(int num) {
+ int result = 1;
+ for(int i =1; i<= num; i++) {
+ result =i*result;
+ }
+ return result;
+ }
+
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
+interface NumberWorker{
+ public int compute(int a);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e6d584dad0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e6d584dad0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..754535b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e6d584dad0001a1a4afd166bbfcbff
@@ -0,0 +1,73 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ System.out.println("Printing cars that are blue");
+ printCars(cars, new CarCondition() {
+
+ @Override
+ public boolean test(Car c) {
+ return c.getColor().equals("Blue");
+ }
+
+ });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/c0a3ced2ebcc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/c0a3ced2ebcc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..15f33e1
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/c0a3ced2ebcc001a1c9583c41c40e4f0
@@ -0,0 +1,31 @@
+package arrayBlockingQueue;
+
+public class Producer Implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+
+ try {
+ synchronized(this) {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ questionQueue.put(nextQuestion);
+ }
+ } catch (InterruptedException e) {
+ System.out.println("Error: " + e);
+ }
+ }
+
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/d0028c0886d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/d0028c0886d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..1231f2f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/a9/d0028c0886d0001a1a4afd166bbfcbff
@@ -0,0 +1,113 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ StringWorker reverser = (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += s.charAt(i);
+ }
+ return result;
+ };
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/30fdad6e0dd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/30fdad6e0dd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..abac643
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/30fdad6e0dd0001a1a4afd166bbfcbff
@@ -0,0 +1,86 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom obejct walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ Calculate sumVar = (a, b) -> a+b;
+ helloVar.someMethod();
+ System.out.println(sumVar.compute(4, 6));
+
+ ////
+ public int sum(int arg1, int arg2) {
+ return arg1+arg2;
+ }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ }
+ return arg1/arg2;
+ }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+
+ }
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/90f2ad03e5cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/90f2ad03e5cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..9b458d3
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/90f2ad03e5cc001a1c9583c41c40e4f0
@@ -0,0 +1,42 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ Object myObject = new Object();
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void readQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ System.out.println("New Question: " + questionNo.remove(0));
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/f0671a5abdcf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/f0671a5abdcf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..f5c80a3
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/aa/f0671a5abdcf001a1a4afd166bbfcbff
@@ -0,0 +1,5 @@
+package lambdasPractice;
+
+public interface ALambdaClass {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ae/00c8d52be1cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ae/00c8d52be1cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..ab525f6
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ae/00c8d52be1cc001a1c9583c41c40e4f0
@@ -0,0 +1,5 @@
+package producerConsumer;
+
+public class Producer {
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/af/2009cdd147d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/af/2009cdd147d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/af/f02643870fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/af/f02643870fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..4e076c7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/af/f02643870fcd001a1d8e8781d501fb14
@@ -0,0 +1,13 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b/703215c9e8cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b/703215c9e8cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..4ad3f7c
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b/703215c9e8cc001a1c9583c41c40e4f0
@@ -0,0 +1,43 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ Object myObject = new Object();
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void readQuestion(int questionNo) throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ System.out.println("New Question: " + questionNo);
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+ }
+
+ @Override
+ public void run() {
+ while(true) {
+ try {
+ readQuestion(questionNo++);
+ } catch (InterruptedException e) {
+ }
+
+ }
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/505517c9e8cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/505517c9e8cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..7181d61
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/505517c9e8cc001a1c9583c41c40e4f0
@@ -0,0 +1,19 @@
+package producerConsumer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ List questionList = new ArrayList();
+
+ Thread t1 = new Thread(new Producer(questionList));
+ Thread t2 = new Thread(new Consumer(questionList));
+
+ t1.start();
+ t2.start();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/70434124e7cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/70434124e7cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..ac8559c
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/70434124e7cc001a1c9583c41c40e4f0
@@ -0,0 +1,38 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Consumer implements Runnable{
+
+ List questionList = null;
+
+ public Consumer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void answerQuestion() throws InterruptedException {
+ synchronized(questionList) {
+ while(questionList.isEmpty()) {
+ System.out.println("No Question to Answer ... Waiting for producer to get questions");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ Thread.sleep(5000);
+ System.out.println("ANSWERED Question: " + questionList.remove(0));
+ questionList.notify();
+ }
+ }
+
+ @Override
+ public void run() {
+
+ while(true) {
+ try {
+ answerQuestion();
+ } catch (InterruptedException e) {
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/900e1edd43d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/900e1edd43d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..93b5c01
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/900e1edd43d1001a1a4afd166bbfcbff
@@ -0,0 +1,74 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ System.out.println("Printing cars that are blue");
+
+// printCars(cars, new CarCondition() {
+// @Override
+// public boolean test(Car c) {
+// return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+// }
+// });
+
+
+// printCars(cars, new CarCondition() {
+//
+// @Override
+// public boolean test(Car c) {
+// return c.getColor().equals("Blue");
+// }
+//
+// });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface Condition {
+ public boolean test(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/c031bf25d5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/c031bf25d5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..de60d5b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b0/c031bf25d5d0001a1a4afd166bbfcbff
@@ -0,0 +1,40 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+ printCarsPriceRange(cars, 18000, 22000);
+ printCarByColor(cars, "Red");
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b1/10ffca0549cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b1/10ffca0549cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..8389df4
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b1/10ffca0549cc001a1c9583c41c40e4f0
@@ -0,0 +1,42 @@
+package client;
+
+import inventory.InventoryManager;
+
+public class Application {
+
+ public static void main(String[] args) {
+
+ InventoryManager manager = new InventoryManager();
+
+ Thread inventoryTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ Thread displayTask = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ manager.populateSoldProducts();
+ }
+ });
+
+ inventoryTask.start();
+// try {
+// Thread.sleep(2000);
+// } catch (InterruptedException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ try {
+ inventoryTask.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ displayTask.start();
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b2/505f18a34ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b2/505f18a34ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..58b8165
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b2/505f18a34ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractical.files;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("/files/wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b2/60ba5bdfe1cc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b2/60ba5bdfe1cc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..95b8057
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b2/60ba5bdfe1cc001a1c9583c41c40e4f0
@@ -0,0 +1,32 @@
+package producerConsumer;
+
+import java.util.List;
+
+public class Producer implements Runnable{
+
+ List questionList = null;
+ final int LIMIT = 5;
+ private int questionNo;
+
+ Object myObject = new Object();
+
+ public Producer(List questionList) {
+ this.questionList = questionList;
+ }
+
+ public void readQuestion(int questionNo) {
+ synchronized(questionList) {
+ while(questionList.size() == LIMIT) {
+ System.out.println("Questions have piled up.. wait for answers");
+ questionList.wait();
+ }
+ }
+
+ synchronized(questionList) {
+ System.out.println("New Question: " + questionNo);
+ questionList.add(questionNo);
+ Thread.sleep(100);
+ questionList.notify();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/40d384284ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/40d384284ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..b1c38ef
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/40d384284ad1001a1a4afd166bbfcbff
@@ -0,0 +1,57 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("C"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", "));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/80898a5766d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/80898a5766d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..154d229
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/80898a5766d0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// };
+// return arg1/arg2;
+// };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider(10,2));
+ }
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/80b35e80bdcf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/80b35e80bdcf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..a7747c0
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b4/80b35e80bdcf001a1a4afd166bbfcbff
@@ -0,0 +1,4 @@
+
+public interface ALambdaInterface {
+ public void someMethod();
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b6/d0533b754acc001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b6/d0533b754acc001a1c9583c41c40e4f0
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b7/f0a848c80fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b7/f0a848c80fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..0e0b4bc
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/b7/f0a848c80fcd001a1d8e8781d501fb14
@@ -0,0 +1,23 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/bc/b0667d1856cf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/bc/b0667d1856cf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6468d0d
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/bc/b0667d1856cf001a1a4afd166bbfcbff
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
+org.eclipse.jdt.core.compiler.compliance=9
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=9
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/be/9048784967d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/be/9048784967d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..6a2704b
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/be/9048784967d0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(arg1, arg2) {
+ if(arg1==0) {
+ return 0;
+ }
+ return arg1/arg2;
+ }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+ }
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/be/c0812d6d4cd1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/be/c0812d6d4cd1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..45ae7fe
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/be/c0812d6d4cd1001a1a4afd166bbfcbff
@@ -0,0 +1,95 @@
+package streamsPractice;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream rows = Files.lines(Paths.get("files/stockDataCsv.text"));
+ rows.map(x -> x.split(","))
+ .filter(x -> x.length > 3)
+ .filter(x -> Integer.parseInt(x[1].trim()) > 15)
+ .forEach(x -> System.out.println(x[0].trim() + " " + x[2].trim() + " " + x[3].trim()));
+ rows.close();
+
+
+ //
+ Stream rows1 = Files.lines(Paths.get("files/stockDataCsv.text"));
+ int rowCount = (int) rows
+ .map(x -> x.split(","))
+ .filter(x -> x.length > 3)
+ .count();
+ System.out.println(rowCount + " good rows.");
+ rows.close();
+
+
+
+ //
+ List words = Files.lines(Paths.get("files/wordFile.txt"))
+ .filter(x -> x.contains("th"))
+ .collect(Collectors.toList());
+ words.forEach(x -> System.out.print(x + ", "));
+ System.out.println();
+
+ //
+ Stream lines = Files.lines(Paths.get("files/wordFile.txt"));
+ lines.sorted()
+ .filter(l -> l.length() > 6)
+ .forEach(x -> System.out.print(x + ", "));
+ lines.close();
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c/000965b4fcc6001a1eb4e8d2c924f3ed b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c/000965b4fcc6001a1eb4e8d2c924f3ed
new file mode 100644
index 0000000..487af58
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c/000965b4fcc6001a1eb4e8d2c924f3ed
@@ -0,0 +1,38 @@
+package inventory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class InventoryManager {
+
+ List soldProductList = new ArrayList();
+ List purchasedProductsList = new ArrayList();
+
+ public void populatSoldProducts() {
+ for(int i = 0; i < 1000; i++) {
+ Product prod = new Product (i, "text_product_" + i);
+ soldProductList.add(prod);
+ System.out.println("ADDED: " + prod);
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void displaySoldProducts() {
+ for (Product product : soldProductList) {
+ System.out.println("PRINTING THE SOLD: " + product);
+ Thread.sleep(10);
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e0b936fb10cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e0b936fb10cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..7049b7e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e0b936fb10cd001a1d8e8781d501fb14
@@ -0,0 +1,35 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ // executor.shutdown(); // Rejects any new tasks from being submitted
+ // Gracefully shuts down the service
+
+ executor.shutdownNow();
+
+
+ while(!executor.isTerminated()) {
+ }
+ System.out.println("submitted all tasks ...");
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c4/70a225744ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c4/70a225744ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..c8fd9e2
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c4/70a225744ad1001a1a4afd166bbfcbff
@@ -0,0 +1,64 @@
+package streamsPractical.files;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) throws IOException {
+
+ //
+ Stream lines = Files.lines(Paths.get("wordFile.txt"));
+
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("c"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", \n"));
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c08154344ad1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c08154344ad1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e7f9b0a
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c08154344ad1001a1a4afd166bbfcbff
@@ -0,0 +1,58 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Stream from a list, filter and print
+ List listOfItems = Arrays.asList("Computer", "Toothpaste", "Box", "Pencil", "Car", "Tent", "Door", "Toy");
+ listOfItems.stream()
+ .map(x -> x.toLowerCase())
+ .filter(x -> x.startsWith("C"))
+ .sorted()
+ .forEach(x -> System.out.print(x + ", "));
+ }
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6, 8, 10})
+ .map((x) -> x * x)
+ .average()
+ .ifPresent(n -> System.out.print(n));
+ System.out.println();
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c5/3048c91701cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c5/3048c91701cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..8b9e3c7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/c5/3048c91701cd001a1c9583c41c40e4f0
@@ -0,0 +1,10 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=13
+org.eclipse.jdt.core.compiler.compliance=13
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=13
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ca/7036a33102cd001a1c9583c41c40e4f0 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ca/7036a33102cd001a1c9583c41c40e4f0
new file mode 100644
index 0000000..ba13be7
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ca/7036a33102cd001a1c9583c41c40e4f0
@@ -0,0 +1,19 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+public class Application {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ BlockingQueue questionQueue = new ArrayBlockingQueue(5);
+ Thread t1 = new Thread(new Producer(questionQueue));
+ Thread t2 = new Thread(new Consumer(questionQueue));
+
+ t1.start();
+ t2.start();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ca/e00c279345d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ca/e00c279345d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..dbc1963
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ca/e00c279345d1001a1a4afd166bbfcbff
@@ -0,0 +1,81 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+
+ Function priceAndColor (c) -> " price = " + c.getPrice() + " color = " + c.getColor();
+
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ System.out.println("Printing cars that are blue");
+
+// printCars(cars, new CarCondition() {
+// @Override
+// public boolean test(Car c) {
+// return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+// }
+// });
+
+
+// printCars(cars, new CarCondition() {
+//
+// @Override
+// public boolean test(Car c) {
+// return c.getColor().equals("Blue");
+// }
+//
+// });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ // public static void printCars(List cars, CarCondition condition) {
+ public static void printCars(List cars, Predicate predicate) {
+ for(Car c: cars) {
+ if(predicate.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface Condition {
+ public boolean test(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cb/307f46f485d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cb/307f46f485d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..3901046
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cb/307f46f485d0001a1a4afd166bbfcbff
@@ -0,0 +1,113 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ reverser = (s) -> {
+ String result ="";
+ for(int i = s.length(); i >=0; i--) {
+ result += str.charAt(i);
+ }
+ return reuslt;
+ };
+ }
+
+
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+
+ // public reverse-String method
+// public String reverse(String str) {
+// String result = "";
+// for(int i = str.length() - 1; i >=0; i--) {
+// result = str +str.charAt(i);
+// }
+// return result;
+
+
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
+interface StringWorker {
+ public String work(String str);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cb/40e0a73a11cd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cb/40e0a73a11cd001a1d8e8781d501fb14
new file mode 100644
index 0000000..1816f2f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cb/40e0a73a11cd001a1d8e8781d501fb14
@@ -0,0 +1,44 @@
+package threadPools;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+public class ThreadPoolDemo {
+
+ public static void main(String[] args) {
+
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ Runnable processor = new MessageProcessor(2);
+ executor.execute(processor);
+
+ Runnable processor2 = new MessageProcessor(3);
+ executor.execute(processor2);
+
+ Runnable processor3 = new MessageProcessor(4);
+ executor.execute(processor3);
+
+ Runnable processor4 = new MessageProcessor(4);
+ executor.execute(processor4);
+
+ // executor.shutdown(); // Rejects any new tasks from being submitted
+ // Gracefully shuts down the service
+
+ // executor.shutdownNow(); // Terminates the executor immediately..
+
+ try {
+ executor.awaitTermination(2, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+// while(!executor.isTerminated()) {
+// }
+
+ System.out.println("submitted all tasks ...");
+
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cc/30928a4cd6d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cc/30928a4cd6d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..366eef0
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cc/30928a4cd6d0001a1a4afd166bbfcbff
@@ -0,0 +1,55 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+ printCars(cars, new CarCondition() {
+ return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+ }
+ });
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface CarCondition {
+ public boolean test(Car c);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ce/800f5c0f0acd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ce/800f5c0f0acd001a1d8e8781d501fb14
new file mode 100644
index 0000000..499519f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/ce/800f5c0f0acd001a1d8e8781d501fb14
@@ -0,0 +1,48 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Producer implements Runnable {
+
+ int questionNo;
+ BlockingQueue questionQueue;
+
+ public Producer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+ questionNo++;
+ try {
+ questionQueue.put(questionNo);
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+ private synchronized int getNextQuestion() {
+ int nextQuestion = questionNo++;
+ System.out.println("Got new Question: " + nextQuestion);
+ return nextQuestion;
+ }
+
+}
+//
+// try {
+// synchronized(this) {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// questionQueue.put(nextQuestion);
+// }
+// } catch (InterruptedException e) {
+// System.out.println("Error: " + e);
+// }
+// }
+//
+//
+// private synchronized int getNextQuestion() {
+// int nextQuestion = questionNo++;
+// System.out.println("Got new Question: " + nextQuestion);
+// return nextQuestion;
+// }
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/0045019944d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/0045019944d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..8154f7e
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/0045019944d1001a1a4afd166bbfcbff
@@ -0,0 +1,75 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+// printCarsPriceRange(cars, 18000, 22000);
+// printCarByColor(cars, "Red");
+
+ System.out.println("Printing cars between price 18000 and 22000");
+ System.out.println("Printing cars that are blue");
+
+// printCars(cars, new CarCondition() {
+// @Override
+// public boolean test(Car c) {
+// return c.getPrice() >= 18000 && c.getPrice() <= 22000;
+// }
+// });
+
+
+// printCars(cars, new CarCondition() {
+//
+// @Override
+// public boolean test(Car c) {
+// return c.getColor().equals("Blue");
+// }
+//
+// });
+
+ printCars(cars, (c) -> c.getPrice() >= 18000 && c.getPrice() <= 22000);
+ }
+
+ // public static void printCars(List cars, CarCondition condition) {
+ public static void printCars(List cars, Predicate predicate) {
+ for(Car c: cars) {
+ if(condition.test(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+}
+
+@FunctionalInterface
+interface Condition {
+ public boolean test(T t);
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/5077125649d1001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/5077125649d1001a1a4afd166bbfcbff
new file mode 100644
index 0000000..91f33ac
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/5077125649d1001a1a4afd166bbfcbff
@@ -0,0 +1,47 @@
+package streamsPractical.files;
+
+import java.util.Arrays;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ // Average of squares of an int array
+ Arrays.stream(new int[] {2, 4, 6 ,8 ,10})
+ .map((x) -> * x)
+ .average()
+ ifPresent(n -> System.out.print(n));
+
+
+ // Stream from Array, sort, filter and print
+ String[] items = {"car", "computer", "toothpaste", "box", "pencil", "tent", "door", "toy"};
+ Stream.of(items)
+ .filter((x) -> x.startsWith("t"))
+ .sorted().forEach(x -> System.out.println(x + ", "));
+ System.out.println();
+
+ // Stream.of, sorted and findFirst
+ Stream.of("Hello", "bottle", "Africa")
+ .sorted()
+ .findFirst()
+ .ifPresent((x) -> System.out.println(x));
+
+
+ // Integer stream with sum
+ int val = IntStream
+ .range(1, 5)
+ .sum();
+ System.out.println(val);
+
+
+ // Integer Stream with Skip
+ IntStream
+ .range(1, 10)
+ .skip(5) // skip 5 elements of the stream
+ .forEach((x) -> System.out.println(x));
+ System.out.println();
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/b06e111d0fd0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/b06e111d0fd0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..29dc486
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/cf/b06e111d0fd0001a1a4afd166bbfcbff
@@ -0,0 +1,87 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+ public int nonZeroDivide(int arg1, int arg2) {
+ if(arg1==0) {
+ return 0;
+ };
+ return arg1/arg2;
+ };
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println("w");
+
+
+
+// public void sayHello() {
+// System.out.println("hello there");
+// }
+
+// public static void walker(Human human) {
+// human.walk();
+// }
+
+ public static void walker(Walkable walkableEntity) {
+ walkableEntity.walk();
+ }
+}
+
+interface Calculate{
+ public int compute(int a, int b);
+}
+
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d/403c2c840acd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d/403c2c840acd001a1d8e8781d501fb14
new file mode 100644
index 0000000..c8ba159
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d/403c2c840acd001a1d8e8781d501fb14
@@ -0,0 +1,23 @@
+package arrayBlockingQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+public class Consumer implements Runnable {
+
+ BlockingQueue questionQueue;
+
+ public Consumer(BlockingQueue questionQueue) {
+ this.questionQueue = questionQueue;
+ }
+
+ @Override
+ public void run() {
+
+ try {
+ System.out.println("ANSWERED QUESTION: " + questionQueue.take());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d0/007f260a0fcd001a1d8e8781d501fb14 b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d0/007f260a0fcd001a1d8e8781d501fb14
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d0/307ca048d5d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d0/307ca048d5d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..a5d4e95
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d0/307ca048d5d0001a1a4afd166bbfcbff
@@ -0,0 +1,48 @@
+package practicalLamdbaExample;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ List cars = Arrays.asList(
+ new Car("Honda", "Acord", "Red", 22300),
+ new Car("Honda", "Civic", "Blue", 17700),
+ new Car("Toyota", "Land Cruiser", "White", 48500),
+ new Car("Toyota", "Corolla", "Black", 16200),
+ new Car("Toyota", "Camry", "Blue", 24000),
+ new Car("Nissan", "Sentra", "White", 17300),
+ new Car("Mistubishi", "Lancer", "White", 20000),
+ new Car("Jeep", "Wrangler", "Red", 24500)
+ );
+ printCarsPriceRange(cars, 18000, 22000);
+ printCarByColor(cars, "Red");
+ }
+
+ public static void printCars(List cars, CarCondition condition) {
+ for(Car c: cars) {
+ if(condition.text(c)) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarsPriceRange(List cars, int low, int high) {
+ for(Car c: cars) {
+ if(low <= c.getPrice() && c.getPrice() <= high) {
+ c.printCar();
+ }
+ }
+ }
+
+ public static void printCarByColor(List cars, String color) {
+ for(Car c: cars) {
+ if(c.getColor().contentEquals(color)) {
+ c.printCar();
+ }
+ }
+ }
+
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d2/70b0862bbccf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d2/70b0862bbccf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..a4cf18f
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d2/70b0862bbccf001a1a4afd166bbfcbff
@@ -0,0 +1,7 @@
+package lambdasPractice;
+
+public class Human {
+ public void walk() {
+ System.out.println("Human Walking");
+ }
+}
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d2/b05cd04256cf001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d2/b05cd04256cf001a1a4afd166bbfcbff
new file mode 100644
index 0000000..e69de29
diff --git a/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d4/90e7e82387d0001a1a4afd166bbfcbff b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d4/90e7e82387d0001a1a4afd166bbfcbff
new file mode 100644
index 0000000..cda3129
--- /dev/null
+++ b/Ahmad/cert/.metadata/.plugins/org.eclipse.core.resources/.history/d4/90e7e82387d0001a1a4afd166bbfcbff
@@ -0,0 +1,143 @@
+package lambdasPractice;
+
+public class App {
+
+ public static void main(String[] args) {
+
+ Human tom = new Human();
+ // tom.walk();
+ walker(tom);
+
+ Robot wally = new Robot();
+ //wally.walk();
+ walker(wally);
+
+// // anonymous class definition
+// walker(new Walkable() {
+//
+// @Override
+// public void walk() {
+// System.out.println("Custom object walking ...");
+// // behavior not tied to any class
+// }
+// });
+
+ // lambda expression
+ // walker(() -> System.out.println("Custom object walking ...."));
+//// ALambdaInterface aBlockOfCode = () -> {
+//// System.out.println("Custom object walking ....");
+//// };
+
+ Walkable aBlockOfCode = () -> {
+ System.out.println("Custom object walking...");
+ System.out.println("the object tripped...");
+ };
+
+ walker(aBlockOfCode);
+ ALambdaInterface helloVar = () -> System.out.println("hello there");
+ helloVar.someMethod();
+
+
+ Calculate sumVar = (a, b) -> a + b;
+ System.out.println(sumVar.compute(4, 6));
+
+
+ ////
+// public int sum(int arg1, int arg2) {
+// return arg1+arg2;
+// }
+
+
+ // public method
+// public int nonZeroDivide(int arg1, int arg2) {
+// if(arg1==0) {
+// return 0;
+// }
+// return arg1/arg2;
+// }
+
+ // lambda expression
+ Calculate nonZeroDivider = (a, b) -> {
+ if(a == 0 ) {
+ return 0;
+ }
+ return a/b;
+ };
+
+ System.out.println(nonZeroDivider.compute(10,2));
+
+ //StringWorker reverser = (s) -> {
+ MyGenericInterface