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/assignment_01/.gitignore b/Ahmad/2_puzzles/assignment_01/.gitignore index ae3c172..09e3bc9 100644 --- a/Ahmad/2_puzzles/assignment_01/.gitignore +++ b/Ahmad/2_puzzles/assignment_01/.gitignore @@ -1 +1,2 @@ /bin/ +/target/ diff --git a/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.core.resources.prefs b/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 99f26c0..0000000 --- a/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 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/assignment_01/App.java b/Ahmad/2_puzzles/assignment_01/src/assignment_01/App.java deleted file mode 100644 index 6d9a81d..0000000 --- a/Ahmad/2_puzzles/assignment_01/src/assignment_01/App.java +++ /dev/null @@ -1,38 +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) { - int middle = str.length() / 2; - String result = str; - - if (str.length() >= 3) { - result = str.substring(middle-1, middle+2); - } - return result; - } - - - - - - - -//----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------// - public static void main(String args[]){ - TestingUtils.runTests(); - } -} 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/2_puzzles/assignment_01/src/ignore/TestingUtils.java b/Ahmad/2_puzzles/assignment_01/src/ignore/TestingUtils.java deleted file mode 100644 index 00bf896..0000000 --- a/Ahmad/2_puzzles/assignment_01/src/ignore/TestingUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package ignore; - -import assignment_01.App; - -public class TestingUtils { - public static void runTests(){ - - - String [] params1 = {"12345","apple","tiger","candy","add","ad","a","","del","denny","sfveaadelbb"}; - String [] expected = {"234","ppl","ige","and","add","ad","a","","del","enn","aad"}; - - for(int i=0; i < params1.length; i++){ - String result = App.middleThree(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: middleThree("+ params1.toString()+ ") -> " + result.toString(); - } - - - private static String printFailResult(Object params1, Object expected, Object result){ - String ret = "**********************" + "\n"; - ret += "FAIL: middleThree("+ params1.toString()+ ") -> " + result.toString() - + " Expected: "+ expected.toString(); - ret += "\n" + "**********************"; - return ret; - } -} \ No newline at end of file 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/Collections/.classpath b/Ahmad/cert/Collections/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/Ahmad/cert/Collections/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/Collections/.gitignore b/Ahmad/cert/Collections/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/Collections/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/Collections/.project b/Ahmad/cert/Collections/.project new file mode 100644 index 0000000..c461daf --- /dev/null +++ b/Ahmad/cert/Collections/.project @@ -0,0 +1,17 @@ + + + Collections + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/Collections/.settings/org.eclipse.jdt.core.prefs similarity index 81% rename from Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.jdt.core.prefs rename to Ahmad/cert/Collections/.settings/org.eclipse.jdt.core.prefs index 8c9943d..ef28d2b 100644 --- a/Ahmad/2_puzzles/assignment_01/.settings/org.eclipse.jdt.core.prefs +++ b/Ahmad/cert/Collections/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ 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.targetPlatform=13 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.compliance=13 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -11,4 +11,4 @@ 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 +org.eclipse.jdt.core.compiler.source=13 diff --git a/Ahmad/cert/Collections/src/collectionMethods/Application.java b/Ahmad/cert/Collections/src/collectionMethods/Application.java new file mode 100644 index 0000000..b413fff --- /dev/null +++ b/Ahmad/cert/Collections/src/collectionMethods/Application.java @@ -0,0 +1,48 @@ +package collectionMethods; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +public class Application { + + public static void main(String[] args) { + +// ArrayList list1 = new ArrayList(); +// HashSet list1 = new HashSet(); +// HashSet hashSet = new HashSet(); + HashSet hashSet = new HashSet(); + + hashSet.add(new Employee("Mike", 3500, "Accounting")); + hashSet.add(new Employee("Peter", 3000, "Admin")); + hashSet.add(new Employee("Paula", 4000, "IT")); + hashSet.add(new Employee("Joan", 2000, "Maint")); + + ArrayList myList = new ArrayList(hashSet); + + Collections.sort(myList); + + System.out.println(myList); + + +// List li = new ArrayList(list1); +// // converts hashset to list +// +// ArrayList newList = new ArrayList(); +// newList.add(10); +// newList.add(67); +// newList.add(15); +// +// list1.addAll(newList); +//// list1.removeAll(newList); +//// list1.clear(); +//// boolean hasValue = list1.contains(67); +// +// boolean hasValue = list1.retainAll(newList); +// //deletes anything not inside newList +// +// System.out.println(list1); +// System.out.println(hasValue); + } +} diff --git a/Ahmad/cert/Collections/src/collectionMethods/Employee.java b/Ahmad/cert/Collections/src/collectionMethods/Employee.java new file mode 100644 index 0000000..277d597 --- /dev/null +++ b/Ahmad/cert/Collections/src/collectionMethods/Employee.java @@ -0,0 +1,55 @@ +package collectionMethods; + +public class Employee implements Comparable{ + + String name; + int salary; + String department; + + + + @Override + public String toString() { + return "Employee [name=" + name + ", salary=" + salary + ", department=" + department + "]"; + } + + + @Override + public int compareTo(Employee o) { + // TODO Auto-generated method stub + return 0; + } + + + public Employee(String name, int salary, String department) { + super(); + this.name = name; + this.salary = salary; + this.department = department; + } + + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public int getSalary() { + return salary; + } + public void setSalary(int salary) { + this.salary = salary; + } + public String getDepartment() { + return department; + } + public void setDepartment(String department) { + this.department = department; + } + + + + + +} diff --git a/Ahmad/cert/Collections/src/maps/Application.java b/Ahmad/cert/Collections/src/maps/Application.java new file mode 100644 index 0000000..71f779c --- /dev/null +++ b/Ahmad/cert/Collections/src/maps/Application.java @@ -0,0 +1,32 @@ +package maps; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +public class Application { + + public static void main(String[] args) { + +// HashMap dictionary = new HashMap(); +// LinkedHashMap dictionary = new LinkedHashMap(); + TreeMap dictionary = new TreeMap(); + + dictionary.put("Brave", "ready to face and endure danger or pain; showing courage."); + dictionary.put("Brilliant", "exceptionally clever or talented."); + dictionary.put("Joy", "a feeling of great pleasure and happiness."); + dictionary.put("Confidence", "the state of feeling certain about the truth of something."); + +// for(String word: dictionary.keySet()) { +// System.out.println(dictionary.get(word)); +// } + + for( Map.Entry entry: dictionary.entrySet()) { + System.out.println(entry.getKey()); + System.out.println(entry.getValue()); + } + + } + +} diff --git a/Ahmad/cert/Collections/src/traversingHashSets/Animal.java b/Ahmad/cert/Collections/src/traversingHashSets/Animal.java new file mode 100644 index 0000000..49dfcd9 --- /dev/null +++ b/Ahmad/cert/Collections/src/traversingHashSets/Animal.java @@ -0,0 +1,55 @@ +package traversingHashSets; + +public class Animal { + String name; + int age; + + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + age; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Animal other = (Animal) obj; + if (age != other.age) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + + + @Override + public String toString() { + return "Animal [name=" + name + ", age=" + age + "]"; + } + + + + public Animal(String name, int age) { + super(); + this.name = name; + this.age = age; + } + + +} diff --git a/Ahmad/cert/Collections/src/traversingHashSets/Application.java b/Ahmad/cert/Collections/src/traversingHashSets/Application.java new file mode 100644 index 0000000..1535277 --- /dev/null +++ b/Ahmad/cert/Collections/src/traversingHashSets/Application.java @@ -0,0 +1,37 @@ +package traversingHashSets; + +import java.util.HashSet; +import java.util.LinkedHashSet; + +public class Application { + + public static void main(String[] args) { +// LinkedHashSet animals = new LinkedHashSet(); + // linked HS maintains order of items entered + + HashSet animals = new HashSet(); + + Animal animal1 = new Animal("Dog", 12); + Animal animal2 = new Animal("Cat", 8); + Animal animal3 = new Animal("Bird", 3); + Animal animal4 = new Animal("Dog", 12); + Animal animal5 = new Animal("Kangaroo", 24); + + animals.add(animal1); + animals.add(animal2); + animals.add(animal3); + animals.add(animal4); + animals.add(animal5); + + System.out.println(animal1.equals(animal4)); + System.out.println(animal1.hashCode()); + System.out.println(animal4.hashCode()); + + System.out.println("****** \n"); + + for(Animal value : animals){ + System.out.println(value); + } + } + +} diff --git a/Ahmad/cert/Collections/src/traversingLists/Application.java b/Ahmad/cert/Collections/src/traversingLists/Application.java new file mode 100644 index 0000000..8bc0383 --- /dev/null +++ b/Ahmad/cert/Collections/src/traversingLists/Application.java @@ -0,0 +1,52 @@ +package traversingLists; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class Application { + + public static void main(String[] args) { + ArrayList animals = new ArrayList(); + animals.add("Lion"); + animals.add("Cat"); + animals.add("Dog"); + animals.add("Bird"); + +// for(int i =0; i < animals.size(); i++) { +// System.out.println(animals.get(i)); +// } +// +// System.out.println("*******"); +// +// for(String value : animals) { +// System.out.println(value); +// } + +// ArrayList vehicles = new ArrayList(); +// LinkedList vehicles = new LinkedList(); + List vehicles = new LinkedList(); + + + Vehicle vehicle2 = new Vehicle("Toyota", "Camary", 12000, false); + + vehicles.add(new Vehicle("Honda", "accord", 12000, false)); + vehicles.add(vehicle2); + vehicles.add(new Vehicle("Jeep", "Wrangler", 2500, true)); + +// for(Vehicle car : vehicles){ +// System.out.println(car); +// } + + printElements(vehicles); + System.out.println("*******"); + printElements(animals); + } + + public static void printElements(List someList) { + for(int i = 0; i < someList.size(); i++) { + System.out.println(someList.get(i)); + } + } + +} diff --git a/Ahmad/cert/Collections/src/traversingLists/Vehicle.java b/Ahmad/cert/Collections/src/traversingLists/Vehicle.java new file mode 100644 index 0000000..3c99043 --- /dev/null +++ b/Ahmad/cert/Collections/src/traversingLists/Vehicle.java @@ -0,0 +1,47 @@ +package traversingLists; + +public class Vehicle { + + String make; + String modle; + int price; + boolean fourWDrive; + + @Override + public String toString() { + return "Vehicle [make=" + make + ", modle=" + modle + ", price=" + price + ", fourWDrive=" + fourWDrive + "]"; + } + + public Vehicle(String make, String modle, int price, boolean fourWDrive) { + super(); + this.make = make; + this.modle = modle; + this.price = price; + this.fourWDrive = fourWDrive; + } + + public String getMake() { + return make; + } + public void setMake(String make) { + this.make = make; + } + public String getModle() { + return modle; + } + public void setModle(String modle) { + this.modle = modle; + } + public int getPrice() { + return price; + } + public void setPrice(int price) { + this.price = price; + } + public boolean isFourWDrive() { + return fourWDrive; + } + public void setFourWDrive(boolean fourWDrive) { + this.fourWDrive = fourWDrive; + } +} diff --git a/Ahmad/cert/Generics/.classpath b/Ahmad/cert/Generics/.classpath new file mode 100644 index 0000000..4ed3c97 --- /dev/null +++ b/Ahmad/cert/Generics/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/Generics/.gitignore b/Ahmad/cert/Generics/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/Generics/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/Generics/.project b/Ahmad/cert/Generics/.project new file mode 100644 index 0000000..35f7874 --- /dev/null +++ b/Ahmad/cert/Generics/.project @@ -0,0 +1,17 @@ + + + Generics + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/Generics/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/Generics/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/Generics/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/Generics/src/generics/Application.java b/Ahmad/cert/Generics/src/generics/Application.java new file mode 100644 index 0000000..28a6278 --- /dev/null +++ b/Ahmad/cert/Generics/src/generics/Application.java @@ -0,0 +1,42 @@ +package generics; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + + +public class Application { + + public static void main(String[] args) { + Container container = new Container<>(12, "Hello"); + int val1 = container.getItem1(); + String val2 = container.getItem2(); + + SetmySet1 = new HashSet(); + mySet1.add("first"); + mySet1.add("second"); + mySet1.add("whatever"); + + SetmySet2 = new HashSet(); + mySet1.add("first"); + mySet1.add("second"); + mySet1.add("Computer"); + + Set resultSet = union(mySet1, mySet2); + + Iterator itr = resultSet.iterator(); + while(itr.hasNext()) { + String var = itr.next(); + System.out.println(var); + } + + } + + public static Set union(Set set1, Set set2){ + Set result = new HashSet(set1); + result.addAll(set2); + return result; + } + +} diff --git a/Ahmad/cert/Generics/src/generics/Container.java b/Ahmad/cert/Generics/src/generics/Container.java new file mode 100644 index 0000000..009e76f --- /dev/null +++ b/Ahmad/cert/Generics/src/generics/Container.java @@ -0,0 +1,37 @@ +package generics; + +public class Container { + + i1 item1; + i2 item2; + + public Container(i1 item1, i2 item2) { + super(); + this.item1 = item1; + this.item2 = item2; + }; + + public void printItems() { + System.out.println("Printing Contents of container: "); + System.out.println("Item 1: " + item1); + System.out.println("Item 1: " + item2); + } + + public i1 getItem1() { + return item1; + } + + public void setItem1(i1 item1) { + this.item1 = item1; + } + + public i2 getItem2() { + return item2; + } + + public void setItem2(i2 item2) { + this.item2 = item2; + } + + +} diff --git a/Ahmad/cert/Generics/src/genericsWithWildcards/Accountant.java b/Ahmad/cert/Generics/src/genericsWithWildcards/Accountant.java new file mode 100644 index 0000000..6913be8 --- /dev/null +++ b/Ahmad/cert/Generics/src/genericsWithWildcards/Accountant.java @@ -0,0 +1,8 @@ +package genericsWithWildcards; + +public class Accountant extends Employee { + + public void work() { + System.out.println("Accountant working"); + } +} diff --git a/Ahmad/cert/Generics/src/genericsWithWildcards/Application.java b/Ahmad/cert/Generics/src/genericsWithWildcards/Application.java new file mode 100644 index 0000000..51a2dac --- /dev/null +++ b/Ahmad/cert/Generics/src/genericsWithWildcards/Application.java @@ -0,0 +1,47 @@ +package genericsWithWildcards; + +import java.util.ArrayList; +import java.util.List; + +public class Application { + + public static void main(String[] args) { + + Object myObject = new Object(); + String myVar = "hello"; + myObject = myVar; + + Employee emp = new Employee(); + Accountant acc = new Accountant(); + emp = acc; + + ArrayList employees = new ArrayList(); + employees.add(new Employee()); + ArrayList accountants = new ArrayList(); + accountants.add(new Accountant()); + //employees = accountants; + + ArrayList employees2 = new ArrayList<>(); + ArrayList accountants2 = new ArrayList(); + employees2 = accountants2; + + // upper bound + ArrayList employees3 = new ArrayList<>(); + ArrayList accountants3 = new ArrayList(); + employees3 = accountants3; + + // lower bound + ArrayList employees4 = new ArrayList<>(); + ArrayList accountants4 = new ArrayList(); + employees4 = accountants4; + + makeEmployeeWork(accountants); + } + + public static void makeEmployeeWork(List employees) { + for(Employee emp : employees) { + emp.work(); + } + } + +} diff --git a/Ahmad/cert/Generics/src/genericsWithWildcards/Container.java b/Ahmad/cert/Generics/src/genericsWithWildcards/Container.java new file mode 100644 index 0000000..76c8ce1 --- /dev/null +++ b/Ahmad/cert/Generics/src/genericsWithWildcards/Container.java @@ -0,0 +1,37 @@ +package genericsWithWildcards; + +public class Container { + + i1 item1; + i2 item2; + + public Container(i1 item1, i2 item2) { + super(); + this.item1 = item1; + this.item2 = item2; + }; + + public void printItems() { + System.out.println("Printing Contents of container: "); + System.out.println("Item 1: " + item1); + System.out.println("Item 1: " + item2); + } + + public i1 getItem1() { + return item1; + } + + public void setItem1(i1 item1) { + this.item1 = item1; + } + + public i2 getItem2() { + return item2; + } + + public void setItem2(i2 item2) { + this.item2 = item2; + } + + +} diff --git a/Ahmad/cert/Generics/src/genericsWithWildcards/Employee.java b/Ahmad/cert/Generics/src/genericsWithWildcards/Employee.java new file mode 100644 index 0000000..4c0fcb1 --- /dev/null +++ b/Ahmad/cert/Generics/src/genericsWithWildcards/Employee.java @@ -0,0 +1,9 @@ +package genericsWithWildcards; + +public class Employee { + + @override + public void work() { + System.out.println("E,ployee working"); + } +} diff --git a/Ahmad/cert/Generics/src/genericsWithWildcards/override.java b/Ahmad/cert/Generics/src/genericsWithWildcards/override.java new file mode 100644 index 0000000..aee73cb --- /dev/null +++ b/Ahmad/cert/Generics/src/genericsWithWildcards/override.java @@ -0,0 +1,5 @@ +package genericsWithWildcards; + +public @interface override { + +} diff --git a/Ahmad/cert/IO_and_Exceptions/.classpath b/Ahmad/cert/IO_and_Exceptions/.classpath new file mode 100644 index 0000000..adeb0a3 --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/IO_and_Exceptions/.gitignore b/Ahmad/cert/IO_and_Exceptions/.gitignore new file mode 100644 index 0000000..112a8b8 --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/.gitignore @@ -0,0 +1,3 @@ +/bin/ + +../../../Buchalka/ diff --git a/Ahmad/cert/IO_and_Exceptions/.project b/Ahmad/cert/IO_and_Exceptions/.project new file mode 100644 index 0000000..29f649d --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/.project @@ -0,0 +1,17 @@ + + + IO_and_Exceptions + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/IO_and_Exceptions/myFile.txt b/Ahmad/cert/IO_and_Exceptions/myFile.txt new file mode 100644 index 0000000..08ede7a --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/myFile.txt @@ -0,0 +1,3 @@ +First random data +second sample set +third in the order of firsts \ No newline at end of file diff --git a/Ahmad/cert/IO_and_Exceptions/src/default_package/Application.java b/Ahmad/cert/IO_and_Exceptions/src/default_package/Application.java new file mode 100644 index 0000000..fa00124 --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/src/default_package/Application.java @@ -0,0 +1,49 @@ +package default_package; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Application { + + public static void main(String[] args) { + +// for(int i=0; i<=3; i++){ +// Scanner input = new Scanner(System.in); +// System.out.println("Enter some text: "); +// String enteredText = input.nextLine(); +// System.out.println(enteredText); +// } + + try { + File file = new File("myfile.txt"); + Scanner input = null; + input = new Scanner(file); + + while(input.hasNextLine()) { + String line = input.nextLine(); + System.out.println(line); + } + input.close(); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + // System.out.println("File not found."); + + } + + + MyFileUtils myUtil = new MyFileUtils(); + try { + System.out.println(myUtil.subtract10FromLargerNumber(5)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + + +} diff --git a/Ahmad/cert/IO_and_Exceptions/src/default_package/MyFileUtils.java b/Ahmad/cert/IO_and_Exceptions/src/default_package/MyFileUtils.java new file mode 100644 index 0000000..d4dc8d2 --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/src/default_package/MyFileUtils.java @@ -0,0 +1,17 @@ +package default_package; + +public class MyFileUtils { + + public int subtract10FromLargerNumber(int number) throws Exception { + if(number < 10) { + throw new fooRuntimeErr("Foo runtime exception..."); + } + return number -10; + } + + public class fooRuntimeErr extends Exception { + public fooRuntimeErr(String message) { + super(message); + } + } +} diff --git a/Ahmad/cert/IO_and_Exceptions/src/learningFileReader/Application.java b/Ahmad/cert/IO_and_Exceptions/src/learningFileReader/Application.java new file mode 100644 index 0000000..73c423f --- /dev/null +++ b/Ahmad/cert/IO_and_Exceptions/src/learningFileReader/Application.java @@ -0,0 +1,49 @@ +package learningFileReader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class Application { + + public static void main(String[] args) { + + File file = new File("myfile.txt"); + BufferedReader bufferedReader = null; + FileReader fileReader = null; + + try(FileReader fileReader1 = new FileReader(file); + BufferedReader bufferedReader1 = new BufferedReader(fileReader1);) { + + String line = bufferedReader1.readLine(); + + while(line != null) { + System.out.println(line); + line = bufferedReader1.readLine(); + } + + + } catch (FileNotFoundException e) { + System.out.println("File not found"); + } catch (IOException e) { + System.out.println("Problem reading the file " + file.getName()); + +// } finally { +// try { +// if(bufferedReader != null) { +// bufferedReader.close(); +// } +// if(fileReader != null) { +// fileReader.close(); +// } +// } catch (IOException e) { +// System.out.println("unable to close file " + file.getName()); +// } catch(NullPointerException ex) { +// System.out.println(" file was probably never opened" + ex); +// } + } + } + +} diff --git a/Ahmad/cert/Lambdas/.classpath b/Ahmad/cert/Lambdas/.classpath new file mode 100644 index 0000000..f104eb5 --- /dev/null +++ b/Ahmad/cert/Lambdas/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Ahmad/cert/Lambdas/.gitignore b/Ahmad/cert/Lambdas/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/Lambdas/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/Lambdas/.project b/Ahmad/cert/Lambdas/.project new file mode 100644 index 0000000..6c60625 --- /dev/null +++ b/Ahmad/cert/Lambdas/.project @@ -0,0 +1,17 @@ + + + Lambdas + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/Lambdas/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/Lambdas/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..021167a --- /dev/null +++ b/Ahmad/cert/Lambdas/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +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.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=9 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=9 diff --git a/Ahmad/cert/Lambdas/files/stockDataCsv.text b/Ahmad/cert/Lambdas/files/stockDataCsv.text new file mode 100644 index 0000000..a54a6ad --- /dev/null +++ b/Ahmad/cert/Lambdas/files/stockDataCsv.text @@ -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/Lambdas/files/wordFile.txt b/Ahmad/cert/Lambdas/files/wordFile.txt new file mode 100644 index 0000000..452d905 --- /dev/null +++ b/Ahmad/cert/Lambdas/files/wordFile.txt @@ -0,0 +1,12 @@ +Hello +POwerade +Samantha +Bitcoin +Camera +Dry Cleaner +Computer Application +Health Insurance +Keyboard +Bottle +White Board +Education \ No newline at end of file diff --git a/Ahmad/cert/Lambdas/src/lambdasPractice/ALambdaInterface.java b/Ahmad/cert/Lambdas/src/lambdasPractice/ALambdaInterface.java new file mode 100644 index 0000000..acb9c10 --- /dev/null +++ b/Ahmad/cert/Lambdas/src/lambdasPractice/ALambdaInterface.java @@ -0,0 +1,8 @@ +package lambdasPractice; + +@FunctionalInterface +public interface ALambdaInterface { + //public void walk(); + + public void someMethod(); +} diff --git a/Ahmad/cert/Lambdas/src/lambdasPractice/App.java b/Ahmad/cert/Lambdas/src/lambdasPractice/App.java new file mode 100644 index 0000000..68ed144 --- /dev/null +++ b/Ahmad/cert/Lambdas/src/lambdasPractice/App.java @@ -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/Lambdas/src/lambdasPractice/Human.java b/Ahmad/cert/Lambdas/src/lambdasPractice/Human.java new file mode 100644 index 0000000..998f68c --- /dev/null +++ b/Ahmad/cert/Lambdas/src/lambdasPractice/Human.java @@ -0,0 +1,7 @@ +package lambdasPractice; + +public class Human implements Walkable { + public void walk() { + System.out.println("Human Walking"); + } +} diff --git a/Ahmad/cert/Lambdas/src/lambdasPractice/Robot.java b/Ahmad/cert/Lambdas/src/lambdasPractice/Robot.java new file mode 100644 index 0000000..7f297fe --- /dev/null +++ b/Ahmad/cert/Lambdas/src/lambdasPractice/Robot.java @@ -0,0 +1,7 @@ +package lambdasPractice; + +public class Robot implements Walkable { + public void walk() { + System.out.println("Robot Walking"); + } +} diff --git a/Ahmad/cert/Lambdas/src/lambdasPractice/Walkable.java b/Ahmad/cert/Lambdas/src/lambdasPractice/Walkable.java new file mode 100644 index 0000000..db5febc --- /dev/null +++ b/Ahmad/cert/Lambdas/src/lambdasPractice/Walkable.java @@ -0,0 +1,5 @@ +package lambdasPractice; + +public interface Walkable { + public void walk(); +} diff --git a/Ahmad/cert/Lambdas/src/practicalLamdbaExample/App.java b/Ahmad/cert/Lambdas/src/practicalLamdbaExample/App.java new file mode 100644 index 0000000..98bdd04 --- /dev/null +++ b/Ahmad/cert/Lambdas/src/practicalLamdbaExample/App.java @@ -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/Lambdas/src/practicalLamdbaExample/Car.java b/Ahmad/cert/Lambdas/src/practicalLamdbaExample/Car.java new file mode 100644 index 0000000..1f0f10b --- /dev/null +++ b/Ahmad/cert/Lambdas/src/practicalLamdbaExample/Car.java @@ -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/Lambdas/src/streamsPractice/App.java b/Ahmad/cert/Lambdas/src/streamsPractice/App.java new file mode 100644 index 0000000..e446a69 --- /dev/null +++ b/Ahmad/cert/Lambdas/src/streamsPractice/App.java @@ -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 { + + // Filter streams w. first val greater than 15 + Stream rows = Files.lines(Paths.get("files/stockDataCsv.text")); + rows.map(x -> x.split(",")) //convert to list + .filter(x -> x.length > 3) // filter length greater than 3 + .filter(x -> Integer.parseInt(x[1].trim()) > 15) // convert to ints, val greater than 15 + .forEach(x -> System.out.println(x[0].trim() + " " + x[2].trim() + " " + x[3].trim())); // print remaining stream elms + rows.close(); + + + // Return rowCount mathcing length greater than 3 + Stream rows1 = Files.lines(Paths.get("files/stockDataCsv.text")); + int rowCount = (int) rows1 + .map(x -> x.split(",")) + .filter(x -> x.length > 3) + .count(); + System.out.println(rowCount + " good rows."); + rows1.close(); + + + + // Filter words that contain 'th' + List words = Files.lines(Paths.get("files/wordFile.txt")) + .filter(x -> x.contains("th")) + .collect(Collectors.toList()); // converts stream of words to collection + words.forEach(x -> System.out.print(x + ", ")); + System.out.println(); + + // Filter words w. length greater than 6 + 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/OOP/.classpath b/Ahmad/cert/OOP/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/Ahmad/cert/OOP/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/OOP/.gitignore b/Ahmad/cert/OOP/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/OOP/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/OOP/.project b/Ahmad/cert/OOP/.project new file mode 100644 index 0000000..7b61216 --- /dev/null +++ b/Ahmad/cert/OOP/.project @@ -0,0 +1,17 @@ + + + OOP + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/OOP/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/OOP/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/OOP/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/OOP/src/car_dealership/Customer.java b/Ahmad/cert/OOP/src/car_dealership/Customer.java new file mode 100644 index 0000000..5a1227b --- /dev/null +++ b/Ahmad/cert/OOP/src/car_dealership/Customer.java @@ -0,0 +1,46 @@ +package car_dealership; + +public class Customer { + + private String name; + private String address; + private double cashOnHand; + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getAddress() { + return address; + } + + + public void setAddress(String address) { + address += "Dealership City"; + this.address = address; + } + + + public double getCashOnHand() { + return cashOnHand; + } + + + public void setCashOnHand(double cashOnHand) { + cashOnHand += 5000; + this.cashOnHand = cashOnHand; + } + + + public void purchaseCar(Vehicle vehicle, Employee emp, boolean finance) { + emp.handleCustomer(this, finance, vehicle); + + } +} diff --git a/Ahmad/cert/OOP/src/car_dealership/Dealership.java b/Ahmad/cert/OOP/src/car_dealership/Dealership.java new file mode 100644 index 0000000..f25d42a --- /dev/null +++ b/Ahmad/cert/OOP/src/car_dealership/Dealership.java @@ -0,0 +1,24 @@ +package car_dealership; + +public class Dealership { + + public static void main(String[] args) { + + Customer cust1 = new Customer(); + cust1.setName("Tom"); + cust1.setAddress("123 Something St, "); + cust1.setCashOnHand(12000); + + + Vehicle vehicle = new Vehicle("Honda", "Accord", 1500); +// vehicle.setMake("Honda"); +// vehicle.setModel("Accord"); +// vehicle.setPrice(15000); + + Employee emp = new Employee(); + + cust1.purchaseCar(vehicle, emp, false); + + } + +} diff --git a/Ahmad/cert/OOP/src/car_dealership/Employee.java b/Ahmad/cert/OOP/src/car_dealership/Employee.java new file mode 100644 index 0000000..ec29cad --- /dev/null +++ b/Ahmad/cert/OOP/src/car_dealership/Employee.java @@ -0,0 +1,29 @@ +package car_dealership; + +public class Employee { + + public void handleCustomer(Customer cust, boolean finance, Vehicle vehicle) { + if(finance == true) { + double loanAmount = vehicle.getPrice() - cust.getCashOnHand(); + runCreditHistory(cust, loanAmount); + }else if (vehicle.getPrice() <= cust.getCashOnHand()) { + // customer pays in cash + processTransaction(cust, vehicle); + } else { + System.out.println("Customer will need more money to purchase vehicle: " + vehicle); + } + } + + public void runCreditHistory(Customer cust, double loanAmount) { + System.out.println("Ran credit history for Customer ..."); + System.out.println("Customer has been approved to purchase the vehicle"); + } + + + private void processTransaction(Customer cust, Vehicle vehicle) { + System.out.println("Customer has purchased the vehicle: " + + vehicle + " for the price " + vehicle.getPrice()); + } + + +} diff --git a/Ahmad/cert/OOP/src/car_dealership/Vehicle.java b/Ahmad/cert/OOP/src/car_dealership/Vehicle.java new file mode 100644 index 0000000..958dd95 --- /dev/null +++ b/Ahmad/cert/OOP/src/car_dealership/Vehicle.java @@ -0,0 +1,49 @@ +package car_dealership; + +public class Vehicle { + + private String make; + private String model; + private double price; + + // src: generate constructor using fields + public Vehicle(String make, String model, double price) { + super(); + this.make = make; + this.model = model; + 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 void setPrice(double price) { + this.price = price; + } + + public double getPrice() { + // TODO Auto-generated method stub + return price; + } + + + @Override + public String toString() { + return "Vehicle [make=" + make + ", model=" + model + ", price=" + price + "]"; + } + + +} diff --git a/Ahmad/cert/OOP/src/oop/Earth.java b/Ahmad/cert/OOP/src/oop/Earth.java new file mode 100644 index 0000000..3fa15ff --- /dev/null +++ b/Ahmad/cert/OOP/src/oop/Earth.java @@ -0,0 +1,17 @@ +package oop; + +public class Earth { + + public static void main(String[] args) { + + Human tom; + + tom = new Human(); + tom.age=5; + tom.eyeColor="brown"; + tom.heightInInches=72; + tom.name="Tom Zabo"; + + tom.speak(); + } +} diff --git a/Ahmad/cert/OOP/src/oop/Human.java b/Ahmad/cert/OOP/src/oop/Human.java new file mode 100644 index 0000000..0855fce --- /dev/null +++ b/Ahmad/cert/OOP/src/oop/Human.java @@ -0,0 +1,30 @@ +package oop; + +public class Human { + + String name; + int age; + int heightInInches; + String eyeColor; + + public void speak(){ + System.out.println("Hello, my name is " + name); + System.out.println("I am " + heightInInches + " inches tall"); + System.out.println("I am " + age + " years old"); + System.out.println("My eye color is " + eyeColor); + } + + public void eat() { + System.out.println("eating..."); + } + + public void walk() { + System.out.println("walking..."); + } + + public void work() { + System.out.println("working..."); + } + + +} diff --git a/Ahmad/cert/arrayBlockingQueue/.classpath b/Ahmad/cert/arrayBlockingQueue/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/arrayBlockingQueue/.gitignore b/Ahmad/cert/arrayBlockingQueue/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/arrayBlockingQueue/.project b/Ahmad/cert/arrayBlockingQueue/.project new file mode 100644 index 0000000..440f8af --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/.project @@ -0,0 +1,17 @@ + + + arrayBlockingQueue + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/arrayBlockingQueue/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/arrayBlockingQueue/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Application.java b/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Application.java new file mode 100644 index 0000000..2acd61e --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Application.java @@ -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/arrayBlockingQueue/src/arrayBlockingQueue/Consumer.java b/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Consumer.java new file mode 100644 index 0000000..beb9bc8 --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Consumer.java @@ -0,0 +1,25 @@ +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 { + Thread.sleep(1000); + System.out.println("ANSWERED QUESTION: " + questionQueue.take()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Producer.java b/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Producer.java new file mode 100644 index 0000000..b50ce8a --- /dev/null +++ b/Ahmad/cert/arrayBlockingQueue/src/arrayBlockingQueue/Producer.java @@ -0,0 +1,36 @@ +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() { + while(true) { + 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/data-analysis/.DS_Store b/Ahmad/cert/data-analysis/.DS_Store new file mode 100644 index 0000000..5172429 Binary files /dev/null and b/Ahmad/cert/data-analysis/.DS_Store differ diff --git a/Ahmad/cert/data-analysis/.classpath b/Ahmad/cert/data-analysis/.classpath new file mode 100644 index 0000000..b5891cf --- /dev/null +++ b/Ahmad/cert/data-analysis/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/data-analysis/.project b/Ahmad/cert/data-analysis/.project new file mode 100644 index 0000000..d61c177 --- /dev/null +++ b/Ahmad/cert/data-analysis/.project @@ -0,0 +1,17 @@ + + + stock-analysis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/data-analysis/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/data-analysis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/data-analysis/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/data-analysis/bin/.DS_Store b/Ahmad/cert/data-analysis/bin/.DS_Store new file mode 100644 index 0000000..1c68439 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/.DS_Store differ diff --git a/Ahmad/cert/data-analysis/bin/aggregators/Aggregator.class b/Ahmad/cert/data-analysis/bin/aggregators/Aggregator.class new file mode 100644 index 0000000..e40a89f Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/aggregators/Aggregator.class differ diff --git a/Ahmad/cert/data-analysis/bin/aggregators/AggregatorProcessor.class b/Ahmad/cert/data-analysis/bin/aggregators/AggregatorProcessor.class new file mode 100644 index 0000000..46a7696 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/aggregators/AggregatorProcessor.class differ diff --git a/Ahmad/cert/data-analysis/bin/aggregators/MaxAggregator.class b/Ahmad/cert/data-analysis/bin/aggregators/MaxAggregator.class new file mode 100644 index 0000000..db03e87 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/aggregators/MaxAggregator.class differ diff --git a/Ahmad/cert/data-analysis/bin/aggregators/MeanAggregator.class b/Ahmad/cert/data-analysis/bin/aggregators/MeanAggregator.class new file mode 100644 index 0000000..0f8bd84 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/aggregators/MeanAggregator.class differ diff --git a/Ahmad/cert/data-analysis/bin/aggregators/MinAggregator.class b/Ahmad/cert/data-analysis/bin/aggregators/MinAggregator.class new file mode 100644 index 0000000..7f5f905 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/aggregators/MinAggregator.class differ diff --git a/Ahmad/cert/data-analysis/bin/client/AggregatorApp.class b/Ahmad/cert/data-analysis/bin/client/AggregatorApp.class new file mode 100644 index 0000000..8858d70 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/client/AggregatorApp.class differ diff --git a/Ahmad/cert/data-analysis/bin/client/Application.class b/Ahmad/cert/data-analysis/bin/client/Application.class new file mode 100644 index 0000000..b2815b6 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/client/Application.class differ diff --git a/Ahmad/cert/data-analysis/bin/client/StockFileApplication.class b/Ahmad/cert/data-analysis/bin/client/StockFileApplication.class new file mode 100644 index 0000000..355fe66 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/client/StockFileApplication.class differ diff --git a/Ahmad/cert/data-analysis/bin/fileprocessors/StockFileData.class b/Ahmad/cert/data-analysis/bin/fileprocessors/StockFileData.class new file mode 100644 index 0000000..c3bacb0 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/fileprocessors/StockFileData.class differ diff --git a/Ahmad/cert/data-analysis/bin/fileprocessors/StockFileReader.class b/Ahmad/cert/data-analysis/bin/fileprocessors/StockFileReader.class new file mode 100644 index 0000000..8671c55 Binary files /dev/null and b/Ahmad/cert/data-analysis/bin/fileprocessors/StockFileReader.class differ diff --git a/Ahmad/cert/data-analysis/src/.DS_Store b/Ahmad/cert/data-analysis/src/.DS_Store new file mode 100644 index 0000000..1c68439 Binary files /dev/null and b/Ahmad/cert/data-analysis/src/.DS_Store differ diff --git a/Ahmad/cert/data-analysis/src/aggregators/Aggregator.java b/Ahmad/cert/data-analysis/src/aggregators/Aggregator.java new file mode 100644 index 0000000..79e9ac1 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/aggregators/Aggregator.java @@ -0,0 +1,34 @@ +package aggregators; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Aggregator { + + List numbers; + + public Aggregator(){ + numbers = new ArrayList(); + } + + public Aggregator(List numbers){ + numbers = new ArrayList(numbers); + } + + /** + * add data to the given collection + * + */ + public void add(Double number) { + numbers.add(number); + } + /** + * Any class that is a derivative of the abstract class + * Aggregator must implement the calculate method. + * @return double + */ + public abstract double calculate(); + + public abstract List getValues(); + +} diff --git a/Ahmad/cert/data-analysis/src/aggregators/AggregatorProcessor.java b/Ahmad/cert/data-analysis/src/aggregators/AggregatorProcessor.java new file mode 100644 index 0000000..a65b3bf --- /dev/null +++ b/Ahmad/cert/data-analysis/src/aggregators/AggregatorProcessor.java @@ -0,0 +1,34 @@ +package aggregators; + +import java.io.IOException; +import java.util.List; + +import fileprocessors.StockFileReader; + +public class AggregatorProcessor { + + T aggregator; + String file; + + public AggregatorProcessor(T aggregator, String file) { + super(); + this.aggregator = aggregator; + this.file = file; + } + + public double runAggregator(int colIdx) throws IOException { + StockFileReader fileReader = new StockFileReader(file); + List lines = fileReader.readFileData(); + colIdx--; + + for(String line : lines){ + String [] numbers = line.split(","); + double value = Double.parseDouble(numbers[colIdx]); + aggregator.add(value); + } + + double number = aggregator.calculate(); + return number; + } + +} diff --git a/Ahmad/cert/data-analysis/src/aggregators/MaxAggregator.java b/Ahmad/cert/data-analysis/src/aggregators/MaxAggregator.java new file mode 100644 index 0000000..b330965 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/aggregators/MaxAggregator.java @@ -0,0 +1,24 @@ +package aggregators; + +import java.util.List; + +public class MaxAggregator extends Aggregator{ + + + @Override + public double calculate() { + double max = numbers.get(0); + for(double number : numbers){ + if(number > max){ + max = number; + } + } + return max; + } + + @Override + public List getValues() { + return numbers; + } + +} diff --git a/Ahmad/cert/data-analysis/src/aggregators/MeanAggregator.java b/Ahmad/cert/data-analysis/src/aggregators/MeanAggregator.java new file mode 100644 index 0000000..ad91e59 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/aggregators/MeanAggregator.java @@ -0,0 +1,24 @@ +package aggregators; + +import java.util.List; + +public class MeanAggregator extends Aggregator{ + + public double calculate() { + double result = 0; + if(!numbers.isEmpty()){ + double value = 0.00; + for(Number number : numbers){ + value+=number.doubleValue(); + } + result = value/numbers.size(); + } + return result; + } + + @Override + public List getValues() { + return numbers; + } + +} diff --git a/Ahmad/cert/data-analysis/src/aggregators/MinAggregator.java b/Ahmad/cert/data-analysis/src/aggregators/MinAggregator.java new file mode 100644 index 0000000..cfe7c82 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/aggregators/MinAggregator.java @@ -0,0 +1,23 @@ +package aggregators; + +import java.util.List; + +public class MinAggregator extends Aggregator{ + + @Override + public double calculate() { + double min = numbers.get(0); + for(double number : numbers){ + if(number < min){ + min = number; + } + } + return min; + } + + @Override + public List getValues() { + return numbers; + } + +} diff --git a/Ahmad/cert/data-analysis/src/client/AggregatorApp.java b/Ahmad/cert/data-analysis/src/client/AggregatorApp.java new file mode 100644 index 0000000..647b603 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/client/AggregatorApp.java @@ -0,0 +1,32 @@ +package client; + +import java.io.IOException; + +import aggregators.AggregatorProcessor; +import aggregators.MaxAggregator; +import aggregators.MinAggregator; + +public class AggregatorApp { + + public static void main(String[] args) throws IOException { + + /** + You'll need to uncomment the below code. You'll notice it does not compile! + + There are 2 objectives in this assignment. + + 1). Make sure the code compiles correctly after you uncomment it below. + 2). Make sure it runs as explained in the assignment video! + + -->> YOUR WORK SHOULD BE DONE IN THE AggregatorProcessor CLASS. + **/ + + MaxAggregator agg = new MaxAggregator(); + AggregatorProcessor aggsProcessor = new AggregatorProcessor(agg, "table.csv"); + double value = aggsProcessor.runAggregator(1); + System.out.println(value); + + + } + +} diff --git a/Ahmad/cert/data-analysis/src/client/Application.java b/Ahmad/cert/data-analysis/src/client/Application.java new file mode 100644 index 0000000..0b1d34f --- /dev/null +++ b/Ahmad/cert/data-analysis/src/client/Application.java @@ -0,0 +1,9 @@ +package client; + +public class Application { + + public static void main(String[] args) { + + } + +} diff --git a/Ahmad/cert/data-analysis/src/client/StockFileApplication.java b/Ahmad/cert/data-analysis/src/client/StockFileApplication.java new file mode 100644 index 0000000..7dcf5f4 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/client/StockFileApplication.java @@ -0,0 +1,36 @@ +package client; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import fileprocessors.StockFileData; +import fileprocessors.StockFileReader; + +public class StockFileApplication { + + public static void main(String args[]) throws IOException{ + StockFileReader fr = new StockFileReader("table.csv"); + + List> dataResult = populateStockFileData(fr.getHeaders(), fr.readFileData()); + StockFileData fileData = new StockFileData(); + fileData.addData(dataResult); + fileData.printData(); + System.out.println(dataResult.size()); + } + /** + * Complete the method body so that it returns the given structure needed to + * populate the data field in the StockFileData class. + * @param headers + * @param lines + * @return List + */ + public static List> populateStockFileData(List headers, List lines){ + List> dataResult = new ArrayList<>(); + // Insert your code here.. + return dataResult; + } + + +} diff --git a/Ahmad/cert/data-analysis/src/fileprocessors/StockFileData.java b/Ahmad/cert/data-analysis/src/fileprocessors/StockFileData.java new file mode 100644 index 0000000..112cb80 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/fileprocessors/StockFileData.java @@ -0,0 +1,18 @@ +package fileprocessors; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class StockFileData { + + List> data = new LinkedList<>(); + + public void printData(){ + System.out.println(data); + } + + public void addData(List> dataIn){ + data = dataIn; + } +} diff --git a/Ahmad/cert/data-analysis/src/fileprocessors/StockFileReader.java b/Ahmad/cert/data-analysis/src/fileprocessors/StockFileReader.java new file mode 100644 index 0000000..2e662c0 --- /dev/null +++ b/Ahmad/cert/data-analysis/src/fileprocessors/StockFileReader.java @@ -0,0 +1,52 @@ +package fileprocessors; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class StockFileReader { + + String filePath = null; + + public StockFileReader(String filePath){ + this.filePath = filePath; + } + + public List getHeaders() throws IOException{ + String line = readFirstLine(filePath); + String [] header = line.split(","); + List values = new ArrayList(); + values = Arrays.asList(header); + return values; + } + + static String readFirstLine(String path) throws IOException { + try (BufferedReader br = + new BufferedReader(new FileReader(path))) { + return br.readLine(); + } + } + /** + * Complete the body of this method. + * @return List + * @throws IOException + */ + public List readFileData() throws IOException{ + List lines = new ArrayList(); + try(BufferedReader br = new BufferedReader(new FileReader(filePath))){ + //skip the first line: + br.readLine(); + String line = null; + // populate data from next line onwards + while((line = br.readLine()) != null){ + lines.add(line); + } + } + return lines; + } + + +} diff --git a/Ahmad/cert/data-analysis/table.csv b/Ahmad/cert/data-analysis/table.csv new file mode 100644 index 0000000..be133f3 --- /dev/null +++ b/Ahmad/cert/data-analysis/table.csv @@ -0,0 +1,252 @@ +Open,High,Low,Close,Volume,Adj Close +142.440002,142.679993,141.850006,142.270004,17245200,142.270004 +141.220001,142.919998,141.160004,142.440002,23251100,142.440002 +141.880005,142,140.449997,140.679993,17271300,140.679993 +141.410004,142.039993,141.110001,141.199997,14660800,141.199997 +141.479996,141.880005,140.869995,141.830002,16424000,141.830002 +141.910004,142.380005,141.050003,141.050003,17652900,141.050003 +141.600006,142.149994,141.009995,141.800003,20238900,141.800003 +142.940002,143.350006,140.059998,141.630005,30275300,141.630005 +143.600006,143.880005,142.899994,143.169998,18473000,143.169998 +143.729996,144.179993,143.270004,143.339996,16621300,143.339996 +144.289993,144.520004,143.449997,143.660004,21118000,143.660004 +144.220001,145.460007,143.809998,144.020004,27481500,144.020004 +143.25,144.889999,143.169998,144.770004,19765700,144.770004 +143.710007,144.119995,143.050003,143.699997,19985700,143.699997 +143.720001,144.270004,143.009995,143.660004,19661700,143.660004 +144.190002,144.5,143.5,143.929993,21207300,143.929993 +143.679993,144.490005,143.190002,144.119995,29190000,144.119995 +140.910004,144.039993,140.619995,143.800003,33374800,143.800003 +139.389999,141.220001,138.619995,140.880005,23575100,140.880005 +141.5,141.740005,140.350006,140.639999,22395600,140.639999 +141.259995,141.580002,140.610001,140.919998,20346300,140.919998 +139.850006,141.600006,139.759995,141.419998,25860200,141.419998 +142.110001,142.800003,139.729996,139.839996,39529900,139.839996 +140.399994,141.5,140.229996,141.460007,21542000,141.460007 +141,141,139.889999,139.990005,43885000,139.990005 +140.720001,141.020004,140.259995,140.690002,19232000,140.690002 +139.410004,140.75,139.029999,140.460007,25691800,140.460007 +139.300003,139.649994,138.839996,138.990005,15309100,138.990005 +138.850006,139.429993,138.820007,139.199997,17421700,139.199997 +139.25,139.360001,138.639999,139.139999,19612800,139.139999 +138.740005,138.789993,137.050003,138.679993,22155900,138.679993 +138.949997,139.800003,138.820007,139,18707200,139 +139.059998,139.979996,138.789993,139.520004,17446300,139.520004 +139.369995,139.770004,138.600006,139.339996,21750000,139.339996 +138.779999,139.830002,138.589996,139.779999,21108100,139.779999 +140,140.279999,138.759995,138.960007,26211000,138.960007 +137.889999,140.149994,137.600006,139.789993,36414600,139.789993 +137.080002,137.440002,136.699997,136.990005,23482900,136.990005 +137.139999,137.440002,136.279999,136.929993,20257400,136.929993 +135.910004,136.660004,135.279999,136.660004,21776600,136.660004 +137.380005,137.479996,136.300003,136.529999,20788200,136.529999 +136.429993,137.119995,136.110001,137.110001,20836900,137.110001 +136.229996,136.75,135.979996,136.699997,24507200,136.699997 +135.100006,135.830002,135.100006,135.720001,22198200,135.720001 +135.669998,135.899994,134.839996,135.350006,22584600,135.350006 +135.520004,136.270004,134.619995,135.509995,35623100,135.509995 +133.470001,135.089996,133.25,135.020004,33226200,135.020004 +133.080002,133.820007,132.75,133.289993,23035400,133.289993 +132.460007,132.940002,132.050003,132.119995,20065500,132.119995 +131.649994,132.449997,131.119995,132.419998,28349900,132.419998 +131.350006,132.220001,131.220001,132.039993,23004100,131.469994 +130.539993,132.089996,130.449997,131.529999,38183800,130.962201 +129.130005,130.5,128.899994,130.289993,26845900,129.727549 +128.309998,129.190002,128.160004,129.080002,24507300,128.522781 +127.980003,129.389999,127.779999,128.529999,33710400,127.975152 +127.029999,130.490005,127.010002,128.75,111985000,128.194203 +121.150002,121.389999,120.620003,121.349998,49201000,120.826147 +120.93,121.629997,120.660004,121.629997,30377500,121.104937 +122.139999,122.349998,121.599998,121.949997,20562900,121.423555 +121.669998,122.440002,121.599998,121.940002,26337600,121.413604 +120.419998,122.099998,120.279999,121.879997,32377600,121.353858 +119.550003,120.099998,119.5,119.970001,23211000,119.452107 +120,120.809998,119.769997,120.080002,22050200,119.561633 +120.449997,120.449997,119.730003,120,32597900,119.481976 +119.400002,120.089996,119.370003,119.779999,25597300,119.262925 +120,120.5,119.709999,119.989998,23713000,119.472017 +118.339996,120.239998,118.220001,120,34439800,119.481976 +119.110001,119.620003,118.809998,119.040001,26111900,118.526121 +118.900002,119.300003,118.209999,119.25,27086200,118.735214 +118.739998,119.93,118.599998,119.75,27588600,119.233055 +118.769997,119.379997,118.300003,119.110001,24462100,118.595819 +117.949997,119.43,117.940002,118.989998,33561900,118.476334 +116.779999,118.160004,116.470001,117.910004,31751900,117.401002 +115.919998,116.860001,115.809998,116.610001,22193600,116.106611 +115.849998,116.510002,115.75,116.019997,21118100,115.519154 +115.800003,116.330002,114.760002,116.150002,28781900,115.648597 +116.650002,117.199997,115.43,115.82,30586300,115.32002 +116.449997,117.110001,116.400002,116.730003,15039500,116.226096 +117.519997,118.019997,116.199997,116.760002,20905900,116.255965 +116.519997,117.800003,116.489998,117.260002,18296900,116.753806 +115.589996,116.519997,115.589996,116.519997,14181200,116.016995 +116.349998,116.510002,115.639999,116.290001,26085900,115.787993 +116.800003,117.400002,116.779999,117.059998,23783200,116.554665 +116.739998,117.5,116.68,116.949997,21425000,116.445139 +115.800003,117.379997,115.75,116.639999,27779400,116.13648 +116.470001,116.5,115.650002,115.970001,44351100,115.469374 +115.379997,116.730003,115.230003,115.82,46524500,115.32002 +115.040001,116.199997,114.980003,115.190002,34031800,114.692743 +113.839996,115.919998,113.75,115.190002,43733800,114.692743 +113.290001,115,112.489998,113.300003,26374400,112.810902 +112.309998,114.699997,112.309998,113.949997,34402600,113.45809 +110.860001,112.43,110.599998,112.120003,27068300,111.635996 +109.260002,111.190002,109.160004,111.029999,29998700,110.550697 +109.5,110.360001,109.190002,109.949997,26195500,109.475358 +110,110.029999,108.25,109.110001,34324500,108.638987 +109.169998,110.089996,108.849998,109.900002,26528000,109.425578 +110.370003,110.940002,109.029999,109.489998,37086900,109.017344 +111.599998,112.199997,110.269997,110.519997,36162300,110.042897 +110.779999,112.029999,110.07,111.459999,28528800,110.978841 +111.43,112.470001,111.389999,111.57,27194000,111.088367 +111.129997,111.870003,110.949997,111.790001,11475900,111.307418 +111.360001,111.510002,110.330002,111.230003,27426400,110.749838 +111.949997,112.419998,111.400002,111.800003,25965500,111.317377 +110.120003,111.989998,110.010002,111.730003,29264600,111.24768 +109.720001,110.540001,109.660004,110.059998,28428900,109.584883 +109.809998,110.349998,108.830002,109.949997,27632000,109.475358 +106.699997,110.230003,106.599998,109.989998,58840500,109.515186 +106.57,107.68,106.160004,107.110001,32264500,106.647621 +107.709999,107.809998,104.080002,105.709999,51175500,105.253663 +107.120003,108.870003,106.550003,108.43,34094100,107.961922 +111.089996,111.089996,105.830002,107.790001,57134500,107.324686 +109.879997,111.32,108.050003,110.879997,59176400,110.401343 +110.309998,111.720001,109.699997,111.059998,24054500,110.580566 +110.080002,110.510002,109.459999,110.410004,32560000,109.933378 +108.529999,110.25,108.110001,108.839996,30837000,108.370149 +110.980003,111.459999,109.550003,109.830002,26932600,109.35588 +111.400002,112.349998,111.230003,111.589996,28331700,110.540737 +113.459999,113.769997,110.529999,111.489998,43825800,110.441678 +113.650002,114.230003,113.199997,113.540001,26419400,112.472406 +113.870003,115.209999,113.449997,113.720001,37861700,112.650713 +115.389999,115.860001,114.099998,114.480003,34562000,113.403569 +114.309998,115.699997,113.309998,115.589996,66134200,114.503125 +117.949997,118.360001,117.309998,118.25,48129000,117.138118 +117.099998,117.739998,117,117.650002,23538700,116.543761 +116.809998,116.910004,116.279999,116.599998,23192700,115.503631 +116.860001,117.379997,116.330002,117.059998,24125800,115.959304 +117.25,117.760002,113.800003,117.120003,20034600,116.018745 +118.18,118.209999,117.449997,117.470001,24553500,116.365453 +117.330002,117.839996,116.779999,117.550003,23624900,116.444703 +117.879997,118.169998,117.129997,117.629997,35652200,116.523945 +116.790001,117.440002,115.720001,116.980003,35192400,115.880062 +117.349998,117.980003,116.75,117.339996,37586800,116.23667 +117.699997,118.690002,116.199997,116.300003,64041000,115.206456 +115.019997,116.75,114.720001,116.050003,36236000,114.958807 +114.309998,114.559998,113.510002,114.059998,24358400,112.987513 +113.699997,114.339996,113.129997,113.889999,28779300,112.819113 +113.400002,113.660004,112.690002,113.050003,21453100,111.987015 +113.059998,114.309998,112.629997,113,29736800,111.937482 +112.709999,113.050003,112.279999,112.519997,21701800,111.461992 +112.459999,113.370003,111.800003,113.050003,36379100,111.987015 +113.160004,113.800003,111.800003,112.18,35887000,111.125193 +113.690002,114.639999,113.43,113.949997,29641100,112.878547 +113,113.18,112.339996,113.089996,24607400,112.026632 +111.639999,113.389999,111.550003,112.879997,29869400,111.818608 +114.419998,114.790001,111.550003,112.709999,52481200,111.650208 +114.349998,114.940002,114,114.620003,31074000,113.542252 +113.849998,113.989998,112.440002,113.550003,36003200,112.482314 +113.050003,114.120003,112.510002,113.57,34514300,112.502122 +115.190002,116.18,113.25,113.580002,47023000,112.51203 +115.120003,116.129997,114.040001,114.919998,79886900,113.839427 +113.860001,115.730003,113.489998,115.57,89983600,114.483317 +108.730003,113.029999,108.599998,111.769997,110888700,110.719044 +107.510002,108.790001,107.239998,107.949997,62176200,106.934963 +102.650002,105.720001,102.529999,105.440002,45292800,104.44857 +104.639999,105.720001,103.129997,103.129997,46557000,102.160285 +107.25,107.269997,105.239998,105.519997,53002000,104.527812 +107.830002,108.760002,107.07,108.360001,42364300,107.341112 +107.900002,108.300003,107.510002,107.699997,26880400,106.687314 +107.699997,108,106.82,107.730003,26802500,106.717038 +106.139999,106.800003,105.620003,106.730003,26701500,105.726441 +105.660004,106.57,105.639999,106.099998,29662400,105.10236 +105.800003,106.5,105.5,106,24863900,105.003302 +106.620003,107.440002,106.290001,106.82,24970300,105.815591 +107.410004,107.949997,106.309998,106.940002,27766300,105.934466 +107.389999,107.879997,106.68,107.57,25086200,106.558539 +108.57,108.75,107.68,108.029999,23675100,107.014213 +108.589996,109.32,108.529999,108.849998,21257700,107.826502 +108.860001,109.099998,107.849998,108.510002,25820200,107.489703 +108.769997,109.690002,108.360001,109.360001,25368100,108.331709 +109.230003,109.599998,109.019997,109.080002,21984700,108.054343 +109.099998,109.370003,108.339996,109.220001,25356000,108.193026 +109.629997,110.230003,109.209999,109.379997,33794400,108.351518 +108.139999,109.540001,108.080002,109.480003,25868200,108.450584 +107.779999,108.440002,107.779999,108.18,18660400,107.162804 +108.519997,108.93,107.849998,107.93,27484500,106.915155 +108.709999,108.900002,107.760002,108,24008500,106.984496 +108.230003,108.940002,108.010002,108.809998,26315200,107.786878 +107.519997,108.370003,107.160004,108.370003,28037200,107.35102 +106.269997,107.650002,106.18,107.480003,40553400,106.469389 +105.580002,106,105.279999,105.870003,27408700,104.874527 +104.809998,105.839996,104.769997,105.790001,30202600,104.230638 +106.050003,106.07,104,104.480003,33816600,102.93995 +104.410004,106.150002,104.410004,106.050003,38167900,104.486808 +104.190002,104.550003,103.68,104.209999,27733700,102.673926 +102.830002,104.449997,102.82,104.339996,39869800,102.802007 +104.269997,104.349998,102.75,102.949997,92344800,101.432497 +96.82,97.970001,96.419998,96.669998,56239800,95.245066 +98.25,98.839996,96.919998,97.339996,40382900,95.905188 +99.260002,99.300003,98.309998,98.660004,28313700,97.205739 +99.830002,101,99.129997,99.43,32702000,97.964385 +100,100.459999,99.739998,99.959999,26276000,98.486572 +99.559998,100,99.339996,99.870003,23779900,98.397902 +98.699997,100.129997,98.599998,99.830002,36493900,98.358491 +98.919998,99.300003,98.5,98.779999,30137000,97.323965 +97.389999,98.989998,97.32,98.790001,38919000,97.33382 +97.410004,97.669998,96.839996,96.870003,25892200,95.442123 +97.169998,97.699997,97.120003,97.419998,24167500,95.984011 +96.75,97.650002,96.730003,96.980003,23794900,95.550502 +96.489998,96.889999,96.050003,96.68,28912100,95.254921 +95.699997,96.5,95.620003,95.940002,25139600,94.525831 +94.599998,95.660004,94.370003,95.529999,30949100,94.12187 +95.389999,95.400002,94.459999,94.989998,27705200,93.589829 +95.489998,96.470001,95.330002,95.889999,26026500,94.476565 +94.440002,95.769997,94.300003,95.599998,35836400,94.190838 +93.970001,94.550003,93.629997,94.400002,36531000,93.00853 +92.900002,93.660004,92.139999,93.589996,40444900,92.210464 +93,93.050003,91.5,92.040001,45489600,90.683316 +92.910004,94.660004,92.650002,93.400002,75311400,92.02327 +95.940002,96.290001,95.25,96.099998,32240200,94.683468 +96.25,96.889999,95.349998,95.550003,29219100,94.14158 +94.940002,96.349998,94.68,95.910004,35546400,94.496274 +96,96.57,95.029999,95.099998,34411900,93.698208 +96.620003,96.650002,95.300003,95.330002,61008200,93.924821 +96.449997,97.75,96.07,97.550003,31326800,96.1121 +97.82,98.410004,97.029999,97.139999,29445200,95.708139 +97.32,98.480003,96.75,97.459999,31931900,96.023422 +98.690002,99.120003,97.099998,97.339996,38020500,95.905188 +98.529999,99.349998,98.480003,98.830002,31712900,97.373231 +98.5,99.989998,98.459999,99.650002,26601400,98.181144 +99.019997,99.559998,98.68,98.940002,20848100,97.48161 +99.25,99.870003,98.959999,99.029999,22409500,97.57028 +97.989998,101.889999,97.550003,98.629997,23292500,97.176174 +97.790001,98.269997,97.449997,97.919998,28062900,96.476641 +97.599998,97.839996,96.629997,97.720001,40191600,96.279592 +99.019997,99.540001,98.330002,98.459999,29173300,97.008682 +99.599998,100.400002,98.82,99.860001,42307200,98.388047 +99.440002,100.470001,99.25,100.349998,36229500,98.870823 +99.68,100.730003,98.639999,100.410004,56331200,98.929943 +98.669998,99.739998,98.110001,99.620003,38168800,98.151587 +97.220001,98.089996,96.839996,97.900002,35140200,96.456939 +95.870003,97.190002,95.669998,96.43,38018600,95.008606 +94.639999,95.43,94.519997,95.220001,32026000,93.816442 +94.639999,94.639999,93.57,94.199997,30442100,92.811473 +94.160004,95.209999,93.889999,94.559998,42062400,93.166167 +94.550003,94.699997,93.010002,93.489998,46916900,92.111939 +92.389999,94.389999,91.650002,93.879997,61259800,92.49619 +90,91.669998,90,90.519997,44392800,89.185717 +92.720001,92.779999,89.470001,90.339996,76314700,89.00837 +93.480003,93.57,92.459999,92.510002,28719100,91.146389 +93.330002,93.57,92.110001,93.419998,33686800,92.042972 +93,93.769997,92.589996,92.790001,32936400,91.422261 +93.370003,93.449997,91.849998,92.720001,43458200,91.353293 +94,94.07,92.68,93.239998,35890500,91.865625 +95.199997,95.900002,93.82,94.190002,41025500,92.240024 +94.199997,95.739998,93.68,95.18,56831300,93.209527 +93.970001,94.080002,92.400002,93.639999,48160100,91.701408 +93.989998,94.720001,92.510002,93.739998,68531500,91.799336 +97.610001,97.879997,94.25,94.830002,82242700,92.866774 +96,98.709999,95.68,97.82,114602100,95.794871 +103.910004,105.300003,103.910004,104.349998,56016200,102.189682 +105,105.650002,104.510002,105.080002,28031600,102.904573 \ No newline at end of file diff --git a/Ahmad/cert/producerConsumer/.classpath b/Ahmad/cert/producerConsumer/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/Ahmad/cert/producerConsumer/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/producerConsumer/.gitignore b/Ahmad/cert/producerConsumer/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/producerConsumer/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/producerConsumer/.project b/Ahmad/cert/producerConsumer/.project new file mode 100644 index 0000000..39124d5 --- /dev/null +++ b/Ahmad/cert/producerConsumer/.project @@ -0,0 +1,17 @@ + + + producerConsumer + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/producerConsumer/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/producerConsumer/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/producerConsumer/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/producerConsumer/src/waitNotify/Application.java b/Ahmad/cert/producerConsumer/src/waitNotify/Application.java new file mode 100644 index 0000000..8ebb9c9 --- /dev/null +++ b/Ahmad/cert/producerConsumer/src/waitNotify/Application.java @@ -0,0 +1,19 @@ +package waitNotify; + +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/producerConsumer/src/waitNotify/Consumer.java b/Ahmad/cert/producerConsumer/src/waitNotify/Consumer.java new file mode 100644 index 0000000..db77228 --- /dev/null +++ b/Ahmad/cert/producerConsumer/src/waitNotify/Consumer.java @@ -0,0 +1,39 @@ +package waitNotify; + +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/producerConsumer/src/waitNotify/Producer.java b/Ahmad/cert/producerConsumer/src/waitNotify/Producer.java new file mode 100644 index 0000000..c7d5c9e --- /dev/null +++ b/Ahmad/cert/producerConsumer/src/waitNotify/Producer.java @@ -0,0 +1,43 @@ +package waitNotify; + +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/stock-analysis/.classpath b/Ahmad/cert/stock-analysis/.classpath new file mode 100644 index 0000000..b5891cf --- /dev/null +++ b/Ahmad/cert/stock-analysis/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/stock-analysis/.project b/Ahmad/cert/stock-analysis/.project new file mode 100644 index 0000000..d61c177 --- /dev/null +++ b/Ahmad/cert/stock-analysis/.project @@ -0,0 +1,17 @@ + + + stock-analysis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/stock-analysis/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/stock-analysis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/stock-analysis/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/stock-analysis/bin/aggregators/Aggregator.class b/Ahmad/cert/stock-analysis/bin/aggregators/Aggregator.class new file mode 100644 index 0000000..5d218e7 Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/aggregators/Aggregator.class differ diff --git a/Ahmad/cert/stock-analysis/bin/aggregators/MaxAggregator.class b/Ahmad/cert/stock-analysis/bin/aggregators/MaxAggregator.class new file mode 100644 index 0000000..97531ce Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/aggregators/MaxAggregator.class differ diff --git a/Ahmad/cert/stock-analysis/bin/aggregators/MeanAggregator.class b/Ahmad/cert/stock-analysis/bin/aggregators/MeanAggregator.class new file mode 100644 index 0000000..ab251fc Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/aggregators/MeanAggregator.class differ diff --git a/Ahmad/cert/stock-analysis/bin/aggregators/MinAggregator.class b/Ahmad/cert/stock-analysis/bin/aggregators/MinAggregator.class new file mode 100644 index 0000000..0db1953 Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/aggregators/MinAggregator.class differ diff --git a/Ahmad/cert/stock-analysis/bin/client/Application.class b/Ahmad/cert/stock-analysis/bin/client/Application.class new file mode 100644 index 0000000..f8c197b Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/client/Application.class differ diff --git a/Ahmad/cert/stock-analysis/bin/client/StockFileApplication.class b/Ahmad/cert/stock-analysis/bin/client/StockFileApplication.class new file mode 100644 index 0000000..761bd44 Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/client/StockFileApplication.class differ diff --git a/Ahmad/cert/stock-analysis/bin/fileprocessors/StockFileData.class b/Ahmad/cert/stock-analysis/bin/fileprocessors/StockFileData.class new file mode 100644 index 0000000..c3bacb0 Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/fileprocessors/StockFileData.class differ diff --git a/Ahmad/cert/stock-analysis/bin/fileprocessors/StockFileReader.class b/Ahmad/cert/stock-analysis/bin/fileprocessors/StockFileReader.class new file mode 100644 index 0000000..19e5b6c Binary files /dev/null and b/Ahmad/cert/stock-analysis/bin/fileprocessors/StockFileReader.class differ diff --git a/Ahmad/cert/stock-analysis/src/aggregators/Aggregator.java b/Ahmad/cert/stock-analysis/src/aggregators/Aggregator.java new file mode 100644 index 0000000..d23529a --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/aggregators/Aggregator.java @@ -0,0 +1,34 @@ +package aggregators; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Aggregator { + + List numbers; + + public Aggregator(){ + numbers = new ArrayList(); + } + + public Aggregator(List numbers){ + numbers = new ArrayList(numbers); + } + + /** + * add data to the given collection + * + */ + public void add(double number) { + numbers.add(number); + } + /** + * Any class that is a derivative of the abstract class + * Aggregator must implement the calculate method. + * @return double + */ + public abstract double calculate(); + + public abstract List getValues(); + +} diff --git a/Ahmad/cert/stock-analysis/src/aggregators/MaxAggregator.java b/Ahmad/cert/stock-analysis/src/aggregators/MaxAggregator.java new file mode 100644 index 0000000..d1d9d80 --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/aggregators/MaxAggregator.java @@ -0,0 +1,28 @@ +package aggregators; + +import java.util.ArrayList; +import java.util.List; + +public class MaxAggregator extends Aggregator{ + + public MaxAggregator(List numbers) { + this.numbers = new ArrayList(); + } + + @Override + public double calculate() { + double max = numbers.get(0); + for(Double number : numbers){ + if(number > max){ + max = number; + } + } + return max; + } + + @Override + public List getValues() { + return numbers; + } + +} diff --git a/Ahmad/cert/stock-analysis/src/aggregators/MeanAggregator.java b/Ahmad/cert/stock-analysis/src/aggregators/MeanAggregator.java new file mode 100644 index 0000000..1666dcd --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/aggregators/MeanAggregator.java @@ -0,0 +1,24 @@ +package aggregators; + +import java.util.List; + +public class MeanAggregator extends Aggregator{ + + public double calculate() { + double result = 0; + if(!numbers.isEmpty()){ + double value = 0.00; + for(Double number : numbers){ + value+=number; + } + result = value/numbers.size(); + } + return result; + } + + @Override + public List getValues() { + return numbers; + } + +} diff --git a/Ahmad/cert/stock-analysis/src/aggregators/MinAggregator.java b/Ahmad/cert/stock-analysis/src/aggregators/MinAggregator.java new file mode 100644 index 0000000..2170376 --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/aggregators/MinAggregator.java @@ -0,0 +1,28 @@ +package aggregators; + +import java.util.ArrayList; +import java.util.List; + +public class MinAggregator extends Aggregator{ + + public MinAggregator(List numbers) { + this.numbers = new ArrayList(numbers); + } + + @Override + public double calculate() { + double min = numbers.get(0); + for(Double number : numbers){ + if(number < min){ + min = number; + } + } + return min; + } + + @Override + public List getValues() { + return numbers; + } + +} diff --git a/Ahmad/cert/stock-analysis/src/client/Application.java b/Ahmad/cert/stock-analysis/src/client/Application.java new file mode 100644 index 0000000..4be742b --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/client/Application.java @@ -0,0 +1,27 @@ +package client; + +import aggregators.Aggregator; +import aggregators.MeanAggregator; +import aggregators.MinAggregator; + +public class Application { + + public static void main(String[] args) { + + Aggregator values = new MeanAggregator(); + values.add(100.93); + values.add(101.32); + values.add(103.41); + values.add(107.87); + values.add(100.90); + values.add(98.76); + + Aggregator minValue = new MinAggregator(values.getValues()); + + double result = minValue.calculate(); + + System.out.println(result); + + } + +} diff --git a/Ahmad/cert/stock-analysis/src/client/StockFileApplication.java b/Ahmad/cert/stock-analysis/src/client/StockFileApplication.java new file mode 100644 index 0000000..717c482 --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/client/StockFileApplication.java @@ -0,0 +1,47 @@ +package client; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import fileprocessors.StockFileData; +import fileprocessors.StockFileReader; + +public class StockFileApplication { + + public static void main(String args[]) throws IOException{ + StockFileReader fr = new StockFileReader("table.csv"); + + List> dataResult = populateStockFileData(fr.getHeaders(), fr.readFileData()); + StockFileData fileData = new StockFileData(); + fileData.addData(dataResult); + fileData.printData(); + System.out.println(dataResult.size()); + } + + /** + * Complete the method body so that it returns the given structure needed to + * populate the data field in the StockFileData class. + * @param headers + * @param lines + * @return List + */ + + public static List> populateStockFileData(List headers, List lines){ + List> dataResult = new ArrayList<>(); + for(String line : lines) { + String [] values = line.split(","); + int cnt = 0; + HashMap headerValueMap = new HashMap<>(); + for(String value: values) { + double dval = Double.parseDouble(value); + headerValueMap.put(headers.get(cnt), dval); + cnt++; + } + dataResult.add(headerValueMap); + } + // Insert your code here.. + return dataResult; + } +} diff --git a/Ahmad/cert/stock-analysis/src/fileprocessors/StockFileData.java b/Ahmad/cert/stock-analysis/src/fileprocessors/StockFileData.java new file mode 100644 index 0000000..112cb80 --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/fileprocessors/StockFileData.java @@ -0,0 +1,18 @@ +package fileprocessors; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class StockFileData { + + List> data = new LinkedList<>(); + + public void printData(){ + System.out.println(data); + } + + public void addData(List> dataIn){ + data = dataIn; + } +} diff --git a/Ahmad/cert/stock-analysis/src/fileprocessors/StockFileReader.java b/Ahmad/cert/stock-analysis/src/fileprocessors/StockFileReader.java new file mode 100644 index 0000000..0cca076 --- /dev/null +++ b/Ahmad/cert/stock-analysis/src/fileprocessors/StockFileReader.java @@ -0,0 +1,56 @@ +package fileprocessors; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class StockFileReader { + + String filePath = null; + + public StockFileReader(String filePath){ + this.filePath = filePath; + } + + public List getHeaders() throws IOException{ + String line = readFirstLine(filePath); + String [] header = line.split(","); + List values = new ArrayList(); + values = Arrays.asList(header); + return values; + } + + static String readFirstLine(String path) throws IOException { + try (BufferedReader br = + new BufferedReader(new FileReader(path))) { + return br.readLine(); + } + } + + /** + * Complete the body of this method. + * @return List + * @throws IOException + */ + + + public List readFileData() throws IOException{ + List lines = new ArrayList(); + try(BufferedReader br = new BufferedReader(new FileReader(filePath))){ + // skip the first line + br.readLine(); + String line = null; + // advance from the second line onwards + while((line = br.readLine()) != null) { + lines.add(line); + } + } + + return lines; + } + + +} diff --git a/Ahmad/cert/stock-analysis/table.csv b/Ahmad/cert/stock-analysis/table.csv new file mode 100644 index 0000000..be133f3 --- /dev/null +++ b/Ahmad/cert/stock-analysis/table.csv @@ -0,0 +1,252 @@ +Open,High,Low,Close,Volume,Adj Close +142.440002,142.679993,141.850006,142.270004,17245200,142.270004 +141.220001,142.919998,141.160004,142.440002,23251100,142.440002 +141.880005,142,140.449997,140.679993,17271300,140.679993 +141.410004,142.039993,141.110001,141.199997,14660800,141.199997 +141.479996,141.880005,140.869995,141.830002,16424000,141.830002 +141.910004,142.380005,141.050003,141.050003,17652900,141.050003 +141.600006,142.149994,141.009995,141.800003,20238900,141.800003 +142.940002,143.350006,140.059998,141.630005,30275300,141.630005 +143.600006,143.880005,142.899994,143.169998,18473000,143.169998 +143.729996,144.179993,143.270004,143.339996,16621300,143.339996 +144.289993,144.520004,143.449997,143.660004,21118000,143.660004 +144.220001,145.460007,143.809998,144.020004,27481500,144.020004 +143.25,144.889999,143.169998,144.770004,19765700,144.770004 +143.710007,144.119995,143.050003,143.699997,19985700,143.699997 +143.720001,144.270004,143.009995,143.660004,19661700,143.660004 +144.190002,144.5,143.5,143.929993,21207300,143.929993 +143.679993,144.490005,143.190002,144.119995,29190000,144.119995 +140.910004,144.039993,140.619995,143.800003,33374800,143.800003 +139.389999,141.220001,138.619995,140.880005,23575100,140.880005 +141.5,141.740005,140.350006,140.639999,22395600,140.639999 +141.259995,141.580002,140.610001,140.919998,20346300,140.919998 +139.850006,141.600006,139.759995,141.419998,25860200,141.419998 +142.110001,142.800003,139.729996,139.839996,39529900,139.839996 +140.399994,141.5,140.229996,141.460007,21542000,141.460007 +141,141,139.889999,139.990005,43885000,139.990005 +140.720001,141.020004,140.259995,140.690002,19232000,140.690002 +139.410004,140.75,139.029999,140.460007,25691800,140.460007 +139.300003,139.649994,138.839996,138.990005,15309100,138.990005 +138.850006,139.429993,138.820007,139.199997,17421700,139.199997 +139.25,139.360001,138.639999,139.139999,19612800,139.139999 +138.740005,138.789993,137.050003,138.679993,22155900,138.679993 +138.949997,139.800003,138.820007,139,18707200,139 +139.059998,139.979996,138.789993,139.520004,17446300,139.520004 +139.369995,139.770004,138.600006,139.339996,21750000,139.339996 +138.779999,139.830002,138.589996,139.779999,21108100,139.779999 +140,140.279999,138.759995,138.960007,26211000,138.960007 +137.889999,140.149994,137.600006,139.789993,36414600,139.789993 +137.080002,137.440002,136.699997,136.990005,23482900,136.990005 +137.139999,137.440002,136.279999,136.929993,20257400,136.929993 +135.910004,136.660004,135.279999,136.660004,21776600,136.660004 +137.380005,137.479996,136.300003,136.529999,20788200,136.529999 +136.429993,137.119995,136.110001,137.110001,20836900,137.110001 +136.229996,136.75,135.979996,136.699997,24507200,136.699997 +135.100006,135.830002,135.100006,135.720001,22198200,135.720001 +135.669998,135.899994,134.839996,135.350006,22584600,135.350006 +135.520004,136.270004,134.619995,135.509995,35623100,135.509995 +133.470001,135.089996,133.25,135.020004,33226200,135.020004 +133.080002,133.820007,132.75,133.289993,23035400,133.289993 +132.460007,132.940002,132.050003,132.119995,20065500,132.119995 +131.649994,132.449997,131.119995,132.419998,28349900,132.419998 +131.350006,132.220001,131.220001,132.039993,23004100,131.469994 +130.539993,132.089996,130.449997,131.529999,38183800,130.962201 +129.130005,130.5,128.899994,130.289993,26845900,129.727549 +128.309998,129.190002,128.160004,129.080002,24507300,128.522781 +127.980003,129.389999,127.779999,128.529999,33710400,127.975152 +127.029999,130.490005,127.010002,128.75,111985000,128.194203 +121.150002,121.389999,120.620003,121.349998,49201000,120.826147 +120.93,121.629997,120.660004,121.629997,30377500,121.104937 +122.139999,122.349998,121.599998,121.949997,20562900,121.423555 +121.669998,122.440002,121.599998,121.940002,26337600,121.413604 +120.419998,122.099998,120.279999,121.879997,32377600,121.353858 +119.550003,120.099998,119.5,119.970001,23211000,119.452107 +120,120.809998,119.769997,120.080002,22050200,119.561633 +120.449997,120.449997,119.730003,120,32597900,119.481976 +119.400002,120.089996,119.370003,119.779999,25597300,119.262925 +120,120.5,119.709999,119.989998,23713000,119.472017 +118.339996,120.239998,118.220001,120,34439800,119.481976 +119.110001,119.620003,118.809998,119.040001,26111900,118.526121 +118.900002,119.300003,118.209999,119.25,27086200,118.735214 +118.739998,119.93,118.599998,119.75,27588600,119.233055 +118.769997,119.379997,118.300003,119.110001,24462100,118.595819 +117.949997,119.43,117.940002,118.989998,33561900,118.476334 +116.779999,118.160004,116.470001,117.910004,31751900,117.401002 +115.919998,116.860001,115.809998,116.610001,22193600,116.106611 +115.849998,116.510002,115.75,116.019997,21118100,115.519154 +115.800003,116.330002,114.760002,116.150002,28781900,115.648597 +116.650002,117.199997,115.43,115.82,30586300,115.32002 +116.449997,117.110001,116.400002,116.730003,15039500,116.226096 +117.519997,118.019997,116.199997,116.760002,20905900,116.255965 +116.519997,117.800003,116.489998,117.260002,18296900,116.753806 +115.589996,116.519997,115.589996,116.519997,14181200,116.016995 +116.349998,116.510002,115.639999,116.290001,26085900,115.787993 +116.800003,117.400002,116.779999,117.059998,23783200,116.554665 +116.739998,117.5,116.68,116.949997,21425000,116.445139 +115.800003,117.379997,115.75,116.639999,27779400,116.13648 +116.470001,116.5,115.650002,115.970001,44351100,115.469374 +115.379997,116.730003,115.230003,115.82,46524500,115.32002 +115.040001,116.199997,114.980003,115.190002,34031800,114.692743 +113.839996,115.919998,113.75,115.190002,43733800,114.692743 +113.290001,115,112.489998,113.300003,26374400,112.810902 +112.309998,114.699997,112.309998,113.949997,34402600,113.45809 +110.860001,112.43,110.599998,112.120003,27068300,111.635996 +109.260002,111.190002,109.160004,111.029999,29998700,110.550697 +109.5,110.360001,109.190002,109.949997,26195500,109.475358 +110,110.029999,108.25,109.110001,34324500,108.638987 +109.169998,110.089996,108.849998,109.900002,26528000,109.425578 +110.370003,110.940002,109.029999,109.489998,37086900,109.017344 +111.599998,112.199997,110.269997,110.519997,36162300,110.042897 +110.779999,112.029999,110.07,111.459999,28528800,110.978841 +111.43,112.470001,111.389999,111.57,27194000,111.088367 +111.129997,111.870003,110.949997,111.790001,11475900,111.307418 +111.360001,111.510002,110.330002,111.230003,27426400,110.749838 +111.949997,112.419998,111.400002,111.800003,25965500,111.317377 +110.120003,111.989998,110.010002,111.730003,29264600,111.24768 +109.720001,110.540001,109.660004,110.059998,28428900,109.584883 +109.809998,110.349998,108.830002,109.949997,27632000,109.475358 +106.699997,110.230003,106.599998,109.989998,58840500,109.515186 +106.57,107.68,106.160004,107.110001,32264500,106.647621 +107.709999,107.809998,104.080002,105.709999,51175500,105.253663 +107.120003,108.870003,106.550003,108.43,34094100,107.961922 +111.089996,111.089996,105.830002,107.790001,57134500,107.324686 +109.879997,111.32,108.050003,110.879997,59176400,110.401343 +110.309998,111.720001,109.699997,111.059998,24054500,110.580566 +110.080002,110.510002,109.459999,110.410004,32560000,109.933378 +108.529999,110.25,108.110001,108.839996,30837000,108.370149 +110.980003,111.459999,109.550003,109.830002,26932600,109.35588 +111.400002,112.349998,111.230003,111.589996,28331700,110.540737 +113.459999,113.769997,110.529999,111.489998,43825800,110.441678 +113.650002,114.230003,113.199997,113.540001,26419400,112.472406 +113.870003,115.209999,113.449997,113.720001,37861700,112.650713 +115.389999,115.860001,114.099998,114.480003,34562000,113.403569 +114.309998,115.699997,113.309998,115.589996,66134200,114.503125 +117.949997,118.360001,117.309998,118.25,48129000,117.138118 +117.099998,117.739998,117,117.650002,23538700,116.543761 +116.809998,116.910004,116.279999,116.599998,23192700,115.503631 +116.860001,117.379997,116.330002,117.059998,24125800,115.959304 +117.25,117.760002,113.800003,117.120003,20034600,116.018745 +118.18,118.209999,117.449997,117.470001,24553500,116.365453 +117.330002,117.839996,116.779999,117.550003,23624900,116.444703 +117.879997,118.169998,117.129997,117.629997,35652200,116.523945 +116.790001,117.440002,115.720001,116.980003,35192400,115.880062 +117.349998,117.980003,116.75,117.339996,37586800,116.23667 +117.699997,118.690002,116.199997,116.300003,64041000,115.206456 +115.019997,116.75,114.720001,116.050003,36236000,114.958807 +114.309998,114.559998,113.510002,114.059998,24358400,112.987513 +113.699997,114.339996,113.129997,113.889999,28779300,112.819113 +113.400002,113.660004,112.690002,113.050003,21453100,111.987015 +113.059998,114.309998,112.629997,113,29736800,111.937482 +112.709999,113.050003,112.279999,112.519997,21701800,111.461992 +112.459999,113.370003,111.800003,113.050003,36379100,111.987015 +113.160004,113.800003,111.800003,112.18,35887000,111.125193 +113.690002,114.639999,113.43,113.949997,29641100,112.878547 +113,113.18,112.339996,113.089996,24607400,112.026632 +111.639999,113.389999,111.550003,112.879997,29869400,111.818608 +114.419998,114.790001,111.550003,112.709999,52481200,111.650208 +114.349998,114.940002,114,114.620003,31074000,113.542252 +113.849998,113.989998,112.440002,113.550003,36003200,112.482314 +113.050003,114.120003,112.510002,113.57,34514300,112.502122 +115.190002,116.18,113.25,113.580002,47023000,112.51203 +115.120003,116.129997,114.040001,114.919998,79886900,113.839427 +113.860001,115.730003,113.489998,115.57,89983600,114.483317 +108.730003,113.029999,108.599998,111.769997,110888700,110.719044 +107.510002,108.790001,107.239998,107.949997,62176200,106.934963 +102.650002,105.720001,102.529999,105.440002,45292800,104.44857 +104.639999,105.720001,103.129997,103.129997,46557000,102.160285 +107.25,107.269997,105.239998,105.519997,53002000,104.527812 +107.830002,108.760002,107.07,108.360001,42364300,107.341112 +107.900002,108.300003,107.510002,107.699997,26880400,106.687314 +107.699997,108,106.82,107.730003,26802500,106.717038 +106.139999,106.800003,105.620003,106.730003,26701500,105.726441 +105.660004,106.57,105.639999,106.099998,29662400,105.10236 +105.800003,106.5,105.5,106,24863900,105.003302 +106.620003,107.440002,106.290001,106.82,24970300,105.815591 +107.410004,107.949997,106.309998,106.940002,27766300,105.934466 +107.389999,107.879997,106.68,107.57,25086200,106.558539 +108.57,108.75,107.68,108.029999,23675100,107.014213 +108.589996,109.32,108.529999,108.849998,21257700,107.826502 +108.860001,109.099998,107.849998,108.510002,25820200,107.489703 +108.769997,109.690002,108.360001,109.360001,25368100,108.331709 +109.230003,109.599998,109.019997,109.080002,21984700,108.054343 +109.099998,109.370003,108.339996,109.220001,25356000,108.193026 +109.629997,110.230003,109.209999,109.379997,33794400,108.351518 +108.139999,109.540001,108.080002,109.480003,25868200,108.450584 +107.779999,108.440002,107.779999,108.18,18660400,107.162804 +108.519997,108.93,107.849998,107.93,27484500,106.915155 +108.709999,108.900002,107.760002,108,24008500,106.984496 +108.230003,108.940002,108.010002,108.809998,26315200,107.786878 +107.519997,108.370003,107.160004,108.370003,28037200,107.35102 +106.269997,107.650002,106.18,107.480003,40553400,106.469389 +105.580002,106,105.279999,105.870003,27408700,104.874527 +104.809998,105.839996,104.769997,105.790001,30202600,104.230638 +106.050003,106.07,104,104.480003,33816600,102.93995 +104.410004,106.150002,104.410004,106.050003,38167900,104.486808 +104.190002,104.550003,103.68,104.209999,27733700,102.673926 +102.830002,104.449997,102.82,104.339996,39869800,102.802007 +104.269997,104.349998,102.75,102.949997,92344800,101.432497 +96.82,97.970001,96.419998,96.669998,56239800,95.245066 +98.25,98.839996,96.919998,97.339996,40382900,95.905188 +99.260002,99.300003,98.309998,98.660004,28313700,97.205739 +99.830002,101,99.129997,99.43,32702000,97.964385 +100,100.459999,99.739998,99.959999,26276000,98.486572 +99.559998,100,99.339996,99.870003,23779900,98.397902 +98.699997,100.129997,98.599998,99.830002,36493900,98.358491 +98.919998,99.300003,98.5,98.779999,30137000,97.323965 +97.389999,98.989998,97.32,98.790001,38919000,97.33382 +97.410004,97.669998,96.839996,96.870003,25892200,95.442123 +97.169998,97.699997,97.120003,97.419998,24167500,95.984011 +96.75,97.650002,96.730003,96.980003,23794900,95.550502 +96.489998,96.889999,96.050003,96.68,28912100,95.254921 +95.699997,96.5,95.620003,95.940002,25139600,94.525831 +94.599998,95.660004,94.370003,95.529999,30949100,94.12187 +95.389999,95.400002,94.459999,94.989998,27705200,93.589829 +95.489998,96.470001,95.330002,95.889999,26026500,94.476565 +94.440002,95.769997,94.300003,95.599998,35836400,94.190838 +93.970001,94.550003,93.629997,94.400002,36531000,93.00853 +92.900002,93.660004,92.139999,93.589996,40444900,92.210464 +93,93.050003,91.5,92.040001,45489600,90.683316 +92.910004,94.660004,92.650002,93.400002,75311400,92.02327 +95.940002,96.290001,95.25,96.099998,32240200,94.683468 +96.25,96.889999,95.349998,95.550003,29219100,94.14158 +94.940002,96.349998,94.68,95.910004,35546400,94.496274 +96,96.57,95.029999,95.099998,34411900,93.698208 +96.620003,96.650002,95.300003,95.330002,61008200,93.924821 +96.449997,97.75,96.07,97.550003,31326800,96.1121 +97.82,98.410004,97.029999,97.139999,29445200,95.708139 +97.32,98.480003,96.75,97.459999,31931900,96.023422 +98.690002,99.120003,97.099998,97.339996,38020500,95.905188 +98.529999,99.349998,98.480003,98.830002,31712900,97.373231 +98.5,99.989998,98.459999,99.650002,26601400,98.181144 +99.019997,99.559998,98.68,98.940002,20848100,97.48161 +99.25,99.870003,98.959999,99.029999,22409500,97.57028 +97.989998,101.889999,97.550003,98.629997,23292500,97.176174 +97.790001,98.269997,97.449997,97.919998,28062900,96.476641 +97.599998,97.839996,96.629997,97.720001,40191600,96.279592 +99.019997,99.540001,98.330002,98.459999,29173300,97.008682 +99.599998,100.400002,98.82,99.860001,42307200,98.388047 +99.440002,100.470001,99.25,100.349998,36229500,98.870823 +99.68,100.730003,98.639999,100.410004,56331200,98.929943 +98.669998,99.739998,98.110001,99.620003,38168800,98.151587 +97.220001,98.089996,96.839996,97.900002,35140200,96.456939 +95.870003,97.190002,95.669998,96.43,38018600,95.008606 +94.639999,95.43,94.519997,95.220001,32026000,93.816442 +94.639999,94.639999,93.57,94.199997,30442100,92.811473 +94.160004,95.209999,93.889999,94.559998,42062400,93.166167 +94.550003,94.699997,93.010002,93.489998,46916900,92.111939 +92.389999,94.389999,91.650002,93.879997,61259800,92.49619 +90,91.669998,90,90.519997,44392800,89.185717 +92.720001,92.779999,89.470001,90.339996,76314700,89.00837 +93.480003,93.57,92.459999,92.510002,28719100,91.146389 +93.330002,93.57,92.110001,93.419998,33686800,92.042972 +93,93.769997,92.589996,92.790001,32936400,91.422261 +93.370003,93.449997,91.849998,92.720001,43458200,91.353293 +94,94.07,92.68,93.239998,35890500,91.865625 +95.199997,95.900002,93.82,94.190002,41025500,92.240024 +94.199997,95.739998,93.68,95.18,56831300,93.209527 +93.970001,94.080002,92.400002,93.639999,48160100,91.701408 +93.989998,94.720001,92.510002,93.739998,68531500,91.799336 +97.610001,97.879997,94.25,94.830002,82242700,92.866774 +96,98.709999,95.68,97.82,114602100,95.794871 +103.910004,105.300003,103.910004,104.349998,56016200,102.189682 +105,105.650002,104.510002,105.080002,28031600,102.904573 \ No newline at end of file diff --git a/Ahmad/cert/threadPools/.classpath b/Ahmad/cert/threadPools/.classpath new file mode 100644 index 0000000..6ee61f2 --- /dev/null +++ b/Ahmad/cert/threadPools/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/threadPools/.gitignore b/Ahmad/cert/threadPools/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/threadPools/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/threadPools/.project b/Ahmad/cert/threadPools/.project new file mode 100644 index 0000000..60729f4 --- /dev/null +++ b/Ahmad/cert/threadPools/.project @@ -0,0 +1,17 @@ + + + threadPools + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/threadPools/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/threadPools/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..021167a --- /dev/null +++ b/Ahmad/cert/threadPools/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +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.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=9 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=9 diff --git a/Ahmad/cert/threadPools/src/threadPools/MessageProcessor.java b/Ahmad/cert/threadPools/src/threadPools/MessageProcessor.java new file mode 100644 index 0000000..6d8b39b --- /dev/null +++ b/Ahmad/cert/threadPools/src/threadPools/MessageProcessor.java @@ -0,0 +1,27 @@ +package threadPools; + +public class MessageProcessor implements Runnable { + + 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/threadPools/src/threadPools/ThreadPoolDemo.java b/Ahmad/cert/threadPools/src/threadPools/ThreadPoolDemo.java new file mode 100644 index 0000000..07d2c19 --- /dev/null +++ b/Ahmad/cert/threadPools/src/threadPools/ThreadPoolDemo.java @@ -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/threadingExamples/.classpath b/Ahmad/cert/threadingExamples/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/Ahmad/cert/threadingExamples/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/threadingExamples/.gitignore b/Ahmad/cert/threadingExamples/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/threadingExamples/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/threadingExamples/.project b/Ahmad/cert/threadingExamples/.project new file mode 100644 index 0000000..eb69370 --- /dev/null +++ b/Ahmad/cert/threadingExamples/.project @@ -0,0 +1,17 @@ + + + threadingExamples + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/threadingExamples/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/threadingExamples/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/threadingExamples/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/threadingExamples/src/threadingExamples/Application.java b/Ahmad/cert/threadingExamples/src/threadingExamples/Application.java new file mode 100644 index 0000000..a9c1126 --- /dev/null +++ b/Ahmad/cert/threadingExamples/src/threadingExamples/Application.java @@ -0,0 +1,80 @@ +package threadingExamples; + +public class Application { + + public static void main(String[] args) { + + // first thread + System.out.println("Starting Thread 1"); +// Task taskRunner = new Task("Thread-A"); + Thread t1 = new Thread(new Runnable() { + @Override + public void run() { + for (int i =0; i < 1000; i++) { + System.out.println("number: "+ i + Thread.currentThread().getName()); + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }); + +// taskRunner.start(); +// taskRunner.run(); + t1.start(); + + + // second thread + System.out.println("Starting Thread 2"); +// Task taskRunner2 = new Task("Thread-B"); + Thread t2 = new Thread(new Runnable() { + + + @Override + public void run() { + for (int i =0; i < 1000; i++) { + System.out.println("number: "+ i + Thread.currentThread().getName()); + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }); +// taskRunner2.start(); +// taskRunner2.run(); + t2.start(); + + } + +} + + +//class Task extends Thread { +class Task implements Runnable { + + String name; + + public Task(String name) { + this.name = name; + } + + public void run() { + Thread.currentThread().setName(this.name); + for (int i =0; i < 1000; i++) { + System.out.println("number: "+ i + Thread.currentThread().getName()); + + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/Ahmad/cert/threadingExamples/src/threadingSafety/Application.java b/Ahmad/cert/threadingExamples/src/threadingSafety/Application.java new file mode 100644 index 0000000..df1fd21 --- /dev/null +++ b/Ahmad/cert/threadingExamples/src/threadingSafety/Application.java @@ -0,0 +1,34 @@ +package threadingSafety; + +public class Application { + + public static void main(String[] args) { + + Sequence sequence = new Sequence(); + + Worker worker1 = new Worker(sequence); + worker1.start(); + + Worker worker2 = new Worker(sequence); + worker2.start(); + + for(int i = 0; i < 100; i++) { + System.out.println(sequence.getNext()); + } + } +} + + +class Worker extends Thread { + Sequence sequence = null; + + public Worker(Sequence sequence) { + this.sequence = sequence; + } + + public void run() { + for(int i=0; i < 100; i++) { + System.out.println(Thread.currentThread().getName() + " got value: " + sequence); + } + } +} \ No newline at end of file diff --git a/Ahmad/cert/threadingExamples/src/threadingSafety/Sequence.java b/Ahmad/cert/threadingExamples/src/threadingSafety/Sequence.java new file mode 100644 index 0000000..3fc4c48 --- /dev/null +++ b/Ahmad/cert/threadingExamples/src/threadingSafety/Sequence.java @@ -0,0 +1,15 @@ +package threadingSafety; + +public class Sequence { + + private int value = 0; + + public synchronized int getNext() { +// synchronized (this) { + value = value + 1; + return value; +// } + } + +} + diff --git a/Ahmad/cert/threadingInventoryManager/.classpath b/Ahmad/cert/threadingInventoryManager/.classpath new file mode 100644 index 0000000..038a0e7 --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Ahmad/cert/threadingInventoryManager/.gitignore b/Ahmad/cert/threadingInventoryManager/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Ahmad/cert/threadingInventoryManager/.project b/Ahmad/cert/threadingInventoryManager/.project new file mode 100644 index 0000000..d5513c2 --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/.project @@ -0,0 +1,17 @@ + + + threadingInventoryManager + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Ahmad/cert/threadingInventoryManager/.settings/org.eclipse.jdt.core.prefs b/Ahmad/cert/threadingInventoryManager/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/.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=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +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=13 diff --git a/Ahmad/cert/threadingInventoryManager/src/client/Application.java b/Ahmad/cert/threadingInventoryManager/src/client/Application.java new file mode 100644 index 0000000..de982f7 --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/src/client/Application.java @@ -0,0 +1,38 @@ +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/threadingInventoryManager/src/inventory/InventoryManager.java b/Ahmad/cert/threadingInventoryManager/src/inventory/InventoryManager.java new file mode 100644 index 0000000..41c93f9 --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/src/inventory/InventoryManager.java @@ -0,0 +1,39 @@ +package inventory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +public class InventoryManager { + + List soldProductList = new CopyOnWriteArrayList(); + List purchasedProductsList = new ArrayList(); + + public void populateSoldProducts() { + 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() throws InterruptedException { + 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/threadingInventoryManager/src/inventory/Product.java b/Ahmad/cert/threadingInventoryManager/src/inventory/Product.java new file mode 100644 index 0000000..d026a00 --- /dev/null +++ b/Ahmad/cert/threadingInventoryManager/src/inventory/Product.java @@ -0,0 +1,17 @@ +package inventory; + +public class Product { + + int id; + String name; + + public Product(int id, String name) { + super(); + this.id = id; + this.name = name; + } + + public String toString() { + return "id: " + id + " | name: " + name; + } +} diff --git a/Darby/.gitignore b/Darby/.gitignore new file mode 100644 index 0000000..3719efc --- /dev/null +++ b/Darby/.gitignore @@ -0,0 +1,7 @@ +/.metadata/ + +/spring-demo-one/lib/ + +/Solutions/ + +../ \ No newline at end of file diff --git a/Darby/.project b/Darby/.project new file mode 100644 index 0000000..375ae12 --- /dev/null +++ b/Darby/.project @@ -0,0 +1,11 @@ + + + Darby + + + + + + + + diff --git a/Darby/spring-demo-one/.classpath b/Darby/spring-demo-one/.classpath new file mode 100644 index 0000000..50e0a3b --- /dev/null +++ b/Darby/spring-demo-one/.classpath @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Darby/spring-demo-one/.project b/Darby/spring-demo-one/.project new file mode 100644 index 0000000..749de1c --- /dev/null +++ b/Darby/spring-demo-one/.project @@ -0,0 +1,23 @@ + + + spring-demo-one + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/Darby/spring-demo-one/.settings/org.eclipse.jdt.core.prefs b/Darby/spring-demo-one/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..db24ee7 --- /dev/null +++ b/Darby/spring-demo-one/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,15 @@ +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.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Darby/spring-demo-one/src/applicationContext.xml b/Darby/spring-demo-one/src/applicationContext.xml new file mode 100644 index 0000000..b9a4b0c --- /dev/null +++ b/Darby/spring-demo-one/src/applicationContext.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Fedin/.gitignore b/Fedin/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/Fedin/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/Fedin/DesignStrategies/.classpath b/Fedin/DesignStrategies/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Fedin/DesignStrategies/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Fedin/DesignStrategies/.gitignore b/Fedin/DesignStrategies/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Fedin/DesignStrategies/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Fedin/DesignStrategies/.project b/Fedin/DesignStrategies/.project new file mode 100644 index 0000000..acbab4c --- /dev/null +++ b/Fedin/DesignStrategies/.project @@ -0,0 +1,17 @@ + + + DesignStrategies + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Fedin/DesignStrategies/.settings/org.eclipse.jdt.core.prefs b/Fedin/DesignStrategies/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Fedin/DesignStrategies/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Fedin/DesignStrategies/src/.classpath b/Fedin/DesignStrategies/src/.classpath new file mode 100644 index 0000000..3f3893a --- /dev/null +++ b/Fedin/DesignStrategies/src/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Fedin/DesignStrategies/src/.gitignore b/Fedin/DesignStrategies/src/.gitignore new file mode 100644 index 0000000..fb842cd --- /dev/null +++ b/Fedin/DesignStrategies/src/.gitignore @@ -0,0 +1 @@ +/hhh.class diff --git a/Fedin/DesignStrategies/src/.project b/Fedin/DesignStrategies/src/.project new file mode 100644 index 0000000..0f6f6a7 --- /dev/null +++ b/Fedin/DesignStrategies/src/.project @@ -0,0 +1,17 @@ + + + src + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Fedin/DesignStrategies/src/DelegationExample/.gitignore b/Fedin/DesignStrategies/src/DelegationExample/.gitignore new file mode 100644 index 0000000..cab6c99 --- /dev/null +++ b/Fedin/DesignStrategies/src/DelegationExample/.gitignore @@ -0,0 +1,3 @@ +/Printer.class +/RealPrinter.class +/Tester.class diff --git a/Fedin/DesignStrategies/src/DelegationExample/Tester.java b/Fedin/DesignStrategies/src/DelegationExample/Tester.java new file mode 100644 index 0000000..fa7a41f --- /dev/null +++ b/Fedin/DesignStrategies/src/DelegationExample/Tester.java @@ -0,0 +1,27 @@ +package DelegationExample; + +class RealPrinter { + + // the "delegate" + void print() { + System.out.println("The Delegate"); + } +} + +class Printer { + // the "delegator" + RealPrinter p = new RealPrinter(); + + // create the delegate + void print() { + p.print(); // delegation + } +} + +class Tester { + // to the outside world it looks like Printer actually prints + public static void main(String[] args) { + Printer printer = new Printer(); + printer.print(); + } +} \ No newline at end of file diff --git a/Fedin/DesignStrategies/src/LiskovSubstitution/Vehicle.java b/Fedin/DesignStrategies/src/LiskovSubstitution/Vehicle.java new file mode 100644 index 0000000..e007929 --- /dev/null +++ b/Fedin/DesignStrategies/src/LiskovSubstitution/Vehicle.java @@ -0,0 +1,30 @@ +package LiskovSubstitution; + +public class Vehicle { + abstract int getSpeed(); + abstract int getCubicCapacity(); +} + +public class Car extends Vehicle { + int getSPeed() { } + int getCubicCapacity() {} + boolean sHatchBack() {} +} + +public class Bus extend Vehicle +{ + int getSpeed() { + inte getCubicCapacity() {} + String getEmergencyExitLoc() {} + } +} + +public static void main (String [] args) { + + Vehicle vehicle = new Bus(); + vehicle.getSpeed(); + vehicle = new Car(); + vehicle.getCubicCapacity(); +} + + diff --git a/Fedin/DesignStrategies/src/OpenClosedPrinciple/Shape.java b/Fedin/DesignStrategies/src/OpenClosedPrinciple/Shape.java new file mode 100644 index 0000000..4d63425 --- /dev/null +++ b/Fedin/DesignStrategies/src/OpenClosedPrinciple/Shape.java @@ -0,0 +1,32 @@ +package OpenClosedPrinciple; + +public interface Shape { + public double calculateArea(); + // open for extension +} + +class Rectangle implements Shape { + public double length; + public double width; + + public double calculateArea() { + return length * length; + } +} + +class Circle implements Shape { + public double radius; + + public double calculateArea() { + return (22/7) * radius * radius; + } +} + +class AreaCalculator { + public double calculateRectangleArea(Shape shape) + { + return shape.calculateArea(); + // implement calcArea w. method specific to that class + // closed for modification + } +} \ No newline at end of file diff --git a/Fedin/DesignStrategies/src/ProgrammingToAnInterface/.gitignore b/Fedin/DesignStrategies/src/ProgrammingToAnInterface/.gitignore new file mode 100644 index 0000000..947e231 --- /dev/null +++ b/Fedin/DesignStrategies/src/ProgrammingToAnInterface/.gitignore @@ -0,0 +1,4 @@ +/Computer.class +/Monitor.class +/Projector.class +/displayModule.class diff --git a/Fedin/DesignStrategies/src/ProgrammingToAnInterface/Computer.java b/Fedin/DesignStrategies/src/ProgrammingToAnInterface/Computer.java new file mode 100644 index 0000000..ee0227a --- /dev/null +++ b/Fedin/DesignStrategies/src/ProgrammingToAnInterface/Computer.java @@ -0,0 +1,42 @@ +package ProgrammingToAnInterface; + + +interface displayModule { + public void display(); +} + + +class Monitor implements displayModule { + public void display() { + System.out.println("Display through Monitor"); + } +} + +class Projector implements displayModule { + public void display() { + System.out.println("Display through projector"); + } +} + +public class Computer { + displayModule dm; + + public void setDisplayModule(displayModule dm) { + this.dm = dm; + } + + public void display() { + dm.display(); + } + + public static void main(String args[]) { + Computer cm = new Computer(); + displayModule dm = new Monitor(); + displayModule dm1 = new Projector(); + + cm.setDisplayModule(dm); + cm.display(); + cm.setDisplayModule(dm1); + cm.display(); + } +} \ No newline at end of file diff --git a/Fedin/DesignStrategies/src/SinglerResponsibility/Employee.java b/Fedin/DesignStrategies/src/SinglerResponsibility/Employee.java new file mode 100644 index 0000000..1511a98 --- /dev/null +++ b/Fedin/DesignStrategies/src/SinglerResponsibility/Employee.java @@ -0,0 +1,22 @@ +package SinglerResponsibility; + +import java.util.Date; + +public class Employee { + private String employeeId; + private String name; + private String address; + private Date dateOfJoining; + + // extracted to external classes +// public boolean isPromotionDueThisYear() { +// //promotion logic +// } +// +// public double calcIncomeTaxForCurrentYear() { +// // income tax logic +// } + + // getters / setters for all member variables +} + diff --git a/Fedin/DesignStrategies/src/SinglerResponsibility/Finance.java b/Fedin/DesignStrategies/src/SinglerResponsibility/Finance.java new file mode 100644 index 0000000..7c42bdd --- /dev/null +++ b/Fedin/DesignStrategies/src/SinglerResponsibility/Finance.java @@ -0,0 +1,7 @@ +package SinglerResponsibility; + +public class Finance { + public double calcIncomeTaxForCurrentYear(Employee imp) { + return 0; + } +} diff --git a/Fedin/DesignStrategies/src/SinglerResponsibility/HRPromotions.java b/Fedin/DesignStrategies/src/SinglerResponsibility/HRPromotions.java new file mode 100644 index 0000000..64f53c1 --- /dev/null +++ b/Fedin/DesignStrategies/src/SinglerResponsibility/HRPromotions.java @@ -0,0 +1,9 @@ +package SinglerResponsibility; + +public class HRPromotions { + + public boolean isPromotionDueThisYear(Employee emp) { + return false; + // promotion logic implementation is using the employee information passed in + } +}