Skip to content

Negin Ahamadi #11

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 1 commit 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> queue = new LinkedList<>();

queue.add("Car 1");
queue.add("Car 2");
queue.add("Car 3");
queue.add("Car 4");

System.out.println(queue);

while (!queue.isEmpty()) {
String removedCar = queue.poll();
System.out.println("delete: " + removedCar);
}

if (queue.isEmpty()) {
System.out.println("queue is empty.");
} else {
System.out.println("queue isn't empty.");
}
}
}
32 changes: 21 additions & 11 deletions Detective.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@

import java.util.ArrayList;

class ToDos {

public static void main(String[] args) {

// Sherlock
ArrayList<String> sherlocksToDos = new ArrayList<String>();

sherlocksToDos.add("visit the crime scene");
sherlocksToDos.add("play violin");
sherlocksToDos.add("interview suspects");
sherlocksToDos.add("solve the case");
sherlocksToDos.add("apprehend the criminal");

// 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");
poirotsToDos.add("trim mustache");
poirotsToDos.add("call all suspects together");
poirotsToDos.add("reveal the truth of the crime");

// Print the size of each ArrayList below:
int a = sherlocksToDos.size();
System.out.println("Sherlock's : " + a);

int b = poirotsToDos.size();
System.out.println("Poirot's : " + b);



// Print the name of the detective with the larger to-do list:

if (a > b) {
System.out.println("Sherlock");
} else if (a < b) {
System.out.println("Poirot");
} else {
System.out.println("Sherlock and Poirot");
}

}

}
24 changes: 20 additions & 4 deletions HashCollisionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@

public class HashCollisionChecker {
public static <T> int countOfUniqueHashCodes(HashSet<T> set) {
// TODO: Implement
return 0;
HashSet<Integer> h_c = new HashSet<>();

for (T element : set) {
int hashCode = element.hashCode();
if (!h_c.contains(hashCode))
h_c.add(hashCode);

}

return h_c.size();
}

public static <K, V> int countOfUniqueHashCodes(HashMap<K, V> map) {
// TODO: Implement
return 0;
HashSet<Integer> h_c = new HashSet<>();

for (K key : map.keySet()) {
int hashCode = key.hashCode();

if (!h_c.contains(hashCode))
h_c.add(hashCode);

}
return h_c.size();
}

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

public class Shuffle {
public static void main(String[] args) {

LinkedList<Integer> linkedList = new LinkedList<>();
linkedList.add(1);
linkedList.add(2);
linkedList.add(3);
linkedList.add(4);
linkedList.add(5);

System.out.println(linkedList);

shuffleLinkedList(linkedList);

System.out.println(linkedList);
}

public static void shuffleLinkedList(LinkedList<Integer> linkedList) {
Collections.shuffle(linkedList);
}
}
88 changes: 88 additions & 0 deletions Uni.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import java.util.*;

class Student implements Comparable<Student> {
private String name;
private String studentId;
private double gpa;

public Student(String name, String studentId, double gpa) {
this.name = name;
this.studentId = studentId;
this.gpa = gpa;
}

public String getName() {
return name;
}

public String getStudentId() {
return studentId;
}

public double getGpa() {
return gpa;
}

@Override
public int compareTo(Student other) {
return this.studentId.compareTo(other.studentId);
}

@Override
public String toString() {
return "Name: " + name + ", ID: " + studentId + ", GPA: " + gpa;
}
}

public class Uni {

private static TreeSet<Student> studentSet = new TreeSet<>();

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("\nMenu:");
System.out.println("1. Add Student");
System.out.println("2. Search Student by ID");
System.out.println("3. Exit");

int choice = scanner.nextInt();
scanner.nextLine();

switch (choice) {
case 1:
System.out.println("Enter student's name:");
String name = scanner.nextLine();
System.out.println("Enter student's ID:");
String studentId = scanner.nextLine();
System.out.println("Enter student's GPA:");
double gpa = scanner.nextDouble();
Student student = new Student(name, studentId, gpa);
studentSet.add(student);
System.out.println("Student added successfully.");
break;
case 2:
System.out.println("Enter student's ID to search:");
String idToSearch = scanner.nextLine();
boolean found = false;
for (Student s : studentSet) {
if (s.getStudentId().equals(idToSearch)) {
System.out.println("Student found: " + s);
found = true;
break;
}
}
if (!found) {
System.out.println("Student not found.");
}
break;
case 3:
System.out.println("Exiting...");
return;
default:
System.out.println("Invalid choice. Please enter 1, 2, or 3.");
}
}
}
}