Skip to content

Develop #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions Detective.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {

// Poirot
ArrayList<String> poirotsToDos = new ArrayList<String>();

poirotsToDos.add("visit the crime scene");
poirotsToDos.add("interview suspects");
poirotsToDos.add("let the little grey cells do their work");
Expand All @@ -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("Sherlock has more things to do");
}else 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");
}

}

}
14 changes: 12 additions & 2 deletions HashCollisionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
public class HashCollisionChecker {
public static <T> int countOfUniqueHashCodes(HashSet<T> set) {
// TODO: Implement
return 0;
HashSet<Integer> hashcode = new HashSet<>();
for(T i : set){
hashcode.add(i.hashCode());

}
return hashcode.size();
}

public static <K, V> int countOfUniqueHashCodes(HashMap<K, V> map) {
// TODO: Implement
return 0;
HashSet<Integer> hashcode = new HashSet<>();
for(K i : map.keySet()){
hashcode.add(i.hashCode());

}
return hashcode.size();
}

public static void main(String[] args) {
Expand Down
11 changes: 11 additions & 0 deletions Last-Assignment.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
40 changes: 40 additions & 0 deletions SafEMashin.java
Original file line number Diff line number Diff line change
@@ -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<Object> carqueue= new LinkedList<>();
// برای صف ماشین ها میتوانیم از کاربر هم تعداد و نام ماشین ها را بگیریم
carqueue.add("Mazda");
carqueue.add("BMW");
carqueue.add("Benz");
carqueue.add("Ford");
carqueue.add("Land Cruise");
//چاپ محتویات راه اول:
System.out.println(carqueue);
//چاپ محتویات راه دوم :
Iterator<Object> 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");
}

}



}
}
19 changes: 19 additions & 0 deletions Shuffle.java
Original file line number Diff line number Diff line change
@@ -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<Object> 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);

}
}
58 changes: 58 additions & 0 deletions University.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.Scanner;
import java.util.TreeSet;
class Student implements Comparable<Student> {
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<Student> studentSet=new TreeSet<>();
int numberOfStudent = input.nextInt();
for (int i=0 ; i<numberOfStudent ; i++){
String name=input.next();
int id=input.nextInt();
double moadel=input.nextDouble();
Student student=new Student(name, id , moadel);
studentSet.add(student);
}

//سرچ از روی id
int searchId=input.nextInt();
boolean found=false;
for(Student i: studentSet){
if(searchId==i.getId()){
System.out.println("Student Found");
System.out.println("name :" + i.getName()+ "\nId : "+ i.getId()+"\nmoadel :" + i.getMoadel());
found=true;
}

}
if(found==false){
System.out.println("Student not Found");
}

}
}
3 changes: 3 additions & 0 deletions out/production/Last-Assignment/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/Last-Assignment/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions out/production/Last-Assignment/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/Last-Assignment/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
11 changes: 11 additions & 0 deletions out/production/Last-Assignment/Last-Assignment.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
75 changes: 75 additions & 0 deletions out/production/Last-Assignment/README.md
Original file line number Diff line number Diff line change
@@ -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 <T> int countOfUniqueHashCodes(HashSet<T> set) ```
#### این متد را طوری پیاده‌سازی کنید که با دریافت یک HashSet، تعداد یکتای hash code های مقادیر موجود در آن را برگرداند.

#### - محاسبه‌ی تعداد یکتای hash code های موجود در یک HashSet
``` public static <K, V> int countOfUniqueHashCodes(HashMap<K, V> map) ```

### این متد را طوری پیاده‌سازی کنید که با دریافت یک HashMap، تعداد یکتای hash code های کلیدهای موجود در آن را برگرداند.

#### مثال:
#### با اجرای متد main موجود در کلاس HashCollisionChecker:
```
public static void main(String[] args) {
HashSet<String> 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<String, Integer> 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 است.
Binary file added out/production/Last-Assignment/SafEMashin.class
Binary file not shown.
Binary file added out/production/Last-Assignment/Shuffle.class
Binary file not shown.
Binary file added out/production/Last-Assignment/Student.class
Binary file not shown.
Binary file added out/production/Last-Assignment/ToDos.class
Binary file not shown.
Binary file added out/production/Last-Assignment/University.class
Binary file not shown.