Skip to content

Pull request #9

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 7 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
26 changes: 26 additions & 0 deletions CarQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.LinkedList;
import java.util.Queue;

public class CarQueue {
public static void main(String[] args) {
Queue<String> carQueue = new LinkedList<>();

carQueue.add("BMW");
carQueue.add("Toyota");
carQueue.add("Honda");

System.out.println("Queue: " + carQueue);
String firstCar = carQueue.poll();
System.out.println("Queue: " + carQueue);
String secondCar = carQueue.poll();
System.out.println("Queue: " + carQueue);
String thirdCar = carQueue.poll();
System.out.println("Queue: " + carQueue);

if (carQueue.isEmpty()) {
System.out.println("Empty.");
} else {
System.out.println("Not Empty.");
}
}
}
14 changes: 10 additions & 4 deletions HashCollisionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

public class HashCollisionChecker {
public static <T> int countOfUniqueHashCodes(HashSet<T> set) {
// TODO: Implement
return 0;
HashSet<Integer> hashCodes = new HashSet<>();
for (T item : set) {
hashCodes.add(item.hashCode());
}
return hashCodes.size();
}

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

public static void main(String[] args) {
Expand Down
17 changes: 17 additions & 0 deletions ShuffleLinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Collections;
import java.util.LinkedList;

public class ShuffleLinkedList {
public static void main(String[] args) {
LinkedList<Object> list = new LinkedList<>();
list.add(45);
list.add("GFG");
list.add(2.56f);
list.add(3.14);
list.add("Ali");
list.add(true);
System.out.println("Before: " + list.toString());
Collections.shuffle(list);
System.out.println("After: " + list.toString());
}
}
12 changes: 10 additions & 2 deletions Detective.java → ToDos.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import java.util.ArrayList;

class ToDos {
public class ToDos {

public static void main(String[] args) {

Expand All @@ -25,10 +25,18 @@ public static void main(String[] args) {
poirotsToDos.add("reveal the truth of the crime");

// Print the size of each ArrayList below:

System.out.println("Sherlock: " + sherlocksToDos.size());
System.out.println("Poirot: " + poirotsToDos.size());


// Print the name of the detective with the larger to-do list:
if (sherlocksToDos.size() > poirotsToDos.size()) {
System.out.println("Sherlock.");
} else if (sherlocksToDos.size() < poirotsToDos.size()) {
System.out.println("Poirot.");
} else {
System.out.println("Equal.");
}

}

Expand Down
61 changes: 61 additions & 0 deletions University.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import java.util.TreeSet;

class Student implements Comparable<Student> {
private int id;
private String name;
private double moadel;

public Student(int id, String name, double moadel) {
this.id = id;
this.name = name;
this.moadel = moadel;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public double getMoadel() {
return moadel;
}

@Override
public int compareTo(Student other) {
return Integer.compare(this.id, other.id);
}
}

public class University {
private TreeSet<Student> students;

public University() {
students = new TreeSet<>();
}

public void addStudent(int id, String name, double moadel) {
students.add(new Student(id, name, moadel));
}

public String searchStudentById(int id) {
for (Student student : students) {
if (student.getId() == id) {
return "Name: " + student.getName() + ", Moadel: " + student.getMoadel();
}
}
return "Student not found.";
}

public static void main(String[] args) {
University university = new University();
university.addStudent(1, "Hasan", 3.5);
university.addStudent(2, "Shima", 3.8);
university.addStudent(3, "Amir", 3.9);

System.out.println(university.searchStudentById(2));
System.out.println(university.searchStudentById(4));
}
}