diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1b2d693 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2801bef --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Detective.java b/Detective.java index 5707416..aacfd83 100644 --- a/Detective.java +++ b/Detective.java @@ -16,7 +16,7 @@ public static void main(String[] args) { // Poirot ArrayList poirotsToDos = new ArrayList(); - + poirotsToDos.add("visit the crime scene"); poirotsToDos.add("interview suspects"); poirotsToDos.add("let the little grey cells do their work"); @@ -25,11 +25,20 @@ public static void main(String[] args) { poirotsToDos.add("reveal the truth of the crime"); // Print the size of each ArrayList below: - + System.out.println("sherlocksToDo's size: "+ sherlocksToDos.size()); + System.out.println("poirotsToDo's size: "+ poirotsToDos.size()); // Print the name of the detective with the larger to-do list: - + if(poirotsToDos.size()sherlocksToDos.size()){ + System.out.println("Poirot has more things to do"); + } + else if(poirotsToDos.size()==sherlocksToDos.size()){ + System.out.println("both detectives have same amount of things to do"); + } + } } diff --git a/HashCollisionChecker.java b/HashCollisionChecker.java index 80631a7..8fa927d 100644 --- a/HashCollisionChecker.java +++ b/HashCollisionChecker.java @@ -3,12 +3,22 @@ public class HashCollisionChecker { public static int countOfUniqueHashCodes(HashSet set) { // TODO: Implement - return 0; + HashSet hashcode = new HashSet<>(); + for(T i : set){ + hashcode.add(i.hashCode()); + + } + return hashcode.size(); } public static int countOfUniqueHashCodes(HashMap map) { // TODO: Implement - return 0; + HashSet hashcode = new HashSet<>(); + for(K i : map.keySet()){ + hashcode.add(i.hashCode()); + + } + return hashcode.size(); } public static void main(String[] args) { diff --git a/Last-Assignment.iml b/Last-Assignment.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/Last-Assignment.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SafEMashin.java b/SafEMashin.java new file mode 100644 index 0000000..52cdaa7 --- /dev/null +++ b/SafEMashin.java @@ -0,0 +1,40 @@ +import java.util.LinkedList; +import java.util.Queue; +import java.util.Iterator; +public class SafEMashin{ + public static void main(String[] args){ + Queue carqueue= new LinkedList<>(); + // برای صف ماشین ها میتوانیم از کاربر هم تعداد و نام ماشین ها را بگیریم + carqueue.add("Mazda"); + carqueue.add("BMW"); + carqueue.add("Benz"); + carqueue.add("Ford"); + carqueue.add("Land Cruise"); + //چاپ محتویات راه اول: + System.out.println(carqueue); + //چاپ محتویات راه دوم : + Iterator iter=carqueue.iterator(); + while(iter.hasNext()){ + Object itervalue =iter.next(); + System.out.println(itervalue + "\n"); + } + + //خارج کردن ماشین ها به ترتیب و چک کردن خالی بودن یا نبودن صف + + while(! carqueue.isEmpty()){ + Object car=carqueue.poll(); + System.out.println(car); + System.out.println(carqueue); + if(carqueue.isEmpty()){ + System.out.println("Queue is Empty\n"); + } + else{ + System.out.println("Queue is not Empty\n"); + } + + } + + + + } +} \ No newline at end of file diff --git a/Shuffle.java b/Shuffle.java new file mode 100644 index 0000000..68469f4 --- /dev/null +++ b/Shuffle.java @@ -0,0 +1,19 @@ +import java.util.Collections; +import java.util.LinkedList; +import java.util.Collections; +import java.util.Scanner; +public class Shuffle{ + public static void main(String[] args){ + LinkedList linkedList = new LinkedList<>(); + Scanner input=new Scanner(System.in); + int number=input.nextInt(); + for (int i = 0; i < number; i++) { + String in = input.next(); + linkedList.add(in); + } + System.out.println("Linked list before : " + linkedList); + Collections.shuffle(linkedList); + System.out.println("Linked List after : " + linkedList); + + } +} \ No newline at end of file diff --git a/University.java b/University.java new file mode 100644 index 0000000..9d4fb0d --- /dev/null +++ b/University.java @@ -0,0 +1,58 @@ +import java.util.Scanner; +import java.util.TreeSet; +class Student implements Comparable { + private String name; + private int id; + private double moadel; + public Student(String name , int id , double moadel){ + this.name=name; + this.id=id; + this.moadel=moadel; + } + public String getName(){ + return name; + } + public int getId(){ + return id; + } + public double getMoadel(){ + return moadel; + } + public int compareTo(Student other) { + return Integer.compare(this.id, other.id); + } + + public String toString() { + return "Name: " + name + ", id: " + id + ", Moadel: " + moadel; + } +} +public class University{ + public static void main(String args[]){ + Scanner input=new Scanner(System.in); + TreeSet studentSet=new TreeSet<>(); + int numberOfStudent = input.nextInt(); + for (int i=0 ; i + + + + + \ No newline at end of file diff --git a/out/production/Last-Assignment/.idea/modules.xml b/out/production/Last-Assignment/.idea/modules.xml new file mode 100644 index 0000000..2801bef --- /dev/null +++ b/out/production/Last-Assignment/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Last-Assignment/.idea/vcs.xml b/out/production/Last-Assignment/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/Last-Assignment/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Last-Assignment/HashCollisionChecker.class b/out/production/Last-Assignment/HashCollisionChecker.class new file mode 100644 index 0000000..a2a2658 Binary files /dev/null and b/out/production/Last-Assignment/HashCollisionChecker.class differ diff --git a/out/production/Last-Assignment/Last-Assignment.iml b/out/production/Last-Assignment/Last-Assignment.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/Last-Assignment/Last-Assignment.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Last-Assignment/README.md b/out/production/Last-Assignment/README.md new file mode 100644 index 0000000..74241a3 --- /dev/null +++ b/out/production/Last-Assignment/README.md @@ -0,0 +1,75 @@ +### کارآگاه +#### کارآگاهان زیاد کار می کنند تا یک پرونده را حل کنند. اما کدام یک کار بیشتری دارد؟ +#### سایز to-do ArrayList مربوط به هر کارآگاه را چاپ کنید. + +#### sherlocksToDos for Sherlock Holmes +#### poirotsToDos for Hercules Poirot + +#### کدام یک کار بیشتری دارد؟ نام کارآگاهی که لیست کارهایش طولانی تر است را چاپ کنید. شرلوک است یا پوآرو؟ + +----------- +### برنامه ی نرگس + +#### نرگس علاقه‌ی زیادی به بهینه بودن برنامه‌ها دارد. او می‌داند که استفاده از hash برای نگه‌داری داده‌ها در برخی مواقع نه تنها کمکی به افزایش پرفورمنس نمی‌کند، بلکه پرفورمنس برنامه را کاهش می‌دهد. یلدا که حرف نرگس را قبول ندارد، از او درخواست کدی کرده است تا میزان hash collision ها را ببیند. نرگس نیز این کار را به شما محول کرده است. + +#### در این سؤال، یک HashSet یا HashMap به شما داده می‌شود. شما باید تعداد یکتای hash code های مقادیر موجود در HashSet یا کلیدهای موجود در HashMap را محاسبه کرده و برگردانید. + +#### کلاس HashCollisionChecker +#### این کلاس شامل دو متد زیر است که باید آن‌ها را پیاده‌سازی کنید: + +#### - محاسبه‌ی تعداد یکتای hash code های موجود در یک HashSet + ``` public static int countOfUniqueHashCodes(HashSet set) ``` +#### این متد را طوری پیاده‌سازی کنید که با دریافت یک HashSet، تعداد یکتای hash code های مقادیر موجود در آن را برگرداند. + +#### - محاسبه‌ی تعداد یکتای hash code های موجود در یک HashSet +``` public static int countOfUniqueHashCodes(HashMap map) ``` + +### این متد را طوری پیاده‌سازی کنید که با دریافت یک HashMap، تعداد یکتای hash code های کلیدهای موجود در آن را برگرداند. + +#### مثال: +#### با اجرای متد main موجود در کلاس HashCollisionChecker: +``` +public static void main(String[] args) { + HashSet set = new HashSet<>(); + set.add("c#c#c#c#c#c#bBc#c#c#c#bBc#"); + set.add("abcd"); + set.add("c#c#c#c#c#c#bBc#c#c#c#c#aa"); + set.add("1234"); + set.add("c#c#c#c#c#c#bBc#c#c#c#c#bB"); + System.out.println(countOfUniqueHashCodes(set)); // 3 + + HashMap map = new HashMap<>(); + map.put("c#c#c#c#c#c#c#aaaaaaaabBbB", 14); + map.put("c#c#c#c#c#c#c#aaaaaaaac#c#", 12); + map.put("c#c#c#c#c#c#c#aaaaaaaac#cc", 16); + System.out.println(countOfUniqueHashCodes(map)); // 2 +} + +``` + +#### خروجی باید به‌صورت زیر باشد: +``` +3 +2 +``` + + +#### برای دریافت hash code آبجکت‌ها، می‌توانید از متد hashCode استفاده کنید. + +-------------------- + +### دانشگاه + +#### برنامه ای بنویسید که مشخصات چندین دانشجو (نام، شماره دانشجویی، معدل) را از کاربر دریافت کند و آنها را در یک TreeSet ذخیره کند. برنامه همچنین باید امکان جستجوی دانشجو بر اساس شماره دانشجویی و چاپ مشخصات وی را فراهم کند. + +----------------- + +### شافل! +#### برنامه ای بنویسید که اعضای یک linkedlist را shuffle میکند. + +---------------- + +### صف ماشینها +#### یک صف از ماشین ها را ایجاد کرده و سپس ماشین ها را به صف اضافه می کنیم. +#### بعد از اینکه محتویات صف را چاپ می کنیم، ماشین ها را به ترتیب از صف خارج می کنیم. در انتها، چک می کنیم که آیا صف خالی است یا نه. +#### هدف این تمرین استفاده از صف و همچنین چگونگی استفاده عملیات های اصلی صف مانند enqueue و dequeue است. diff --git a/out/production/Last-Assignment/SafEMashin.class b/out/production/Last-Assignment/SafEMashin.class new file mode 100644 index 0000000..daf1ca9 Binary files /dev/null and b/out/production/Last-Assignment/SafEMashin.class differ diff --git a/out/production/Last-Assignment/Shuffle.class b/out/production/Last-Assignment/Shuffle.class new file mode 100644 index 0000000..c556e71 Binary files /dev/null and b/out/production/Last-Assignment/Shuffle.class differ diff --git a/out/production/Last-Assignment/Student.class b/out/production/Last-Assignment/Student.class new file mode 100644 index 0000000..ba9a38c Binary files /dev/null and b/out/production/Last-Assignment/Student.class differ diff --git a/out/production/Last-Assignment/ToDos.class b/out/production/Last-Assignment/ToDos.class new file mode 100644 index 0000000..08885c1 Binary files /dev/null and b/out/production/Last-Assignment/ToDos.class differ diff --git a/out/production/Last-Assignment/University.class b/out/production/Last-Assignment/University.class new file mode 100644 index 0000000..e682719 Binary files /dev/null and b/out/production/Last-Assignment/University.class differ