diff --git a/Car.java b/Car.java new file mode 100644 index 0000000..08b78ef --- /dev/null +++ b/Car.java @@ -0,0 +1,34 @@ +import java.util.*; +public class Car { + public static void main(String[] args) { + Queue carQueue = new LinkedList<>(); + + enqueue(carQueue, "landcruiser"); + enqueue(carQueue, "porsche"); + enqueue(carQueue, "hilux"); + enqueue(carQueue, "lexus lc"); + + printQueueContents(carQueue); + + while (!carQueue.isEmpty()) { + String removedCar = dequeue(carQueue); + System.out.println(removedCar+" Removed "); + } + + if (carQueue.isEmpty()) { + System.out.println("The queue is empty."); + } else { + System.out.println("The queue is not empty."); + } + } + public static void enqueue(Queue queue, String car) { + queue.add(car); + } + public static String dequeue(Queue queue) { + return queue.poll(); + } + public static void printQueueContents(Queue queue) { + System.out.println("The queue: " + queue); + } +} + diff --git a/Detective.java b/Detective.java index 5707416..cd35d2c 100644 --- a/Detective.java +++ b/Detective.java @@ -26,10 +26,15 @@ public static void main(String[] args) { // Print the size of each ArrayList below: - + System.out.println(poirotsToDos.size()); + System.out.println(sherlocksToDos.size()); // Print the name of the detective with the larger to-do list: - + if (poirotsToDos.size() > sherlocksToDos.size()){ + System.out.println("Poirot"); + }else { + System.out.println("Holmes"); + } } } diff --git a/HashCollisionChecker.java b/HashCollisionChecker.java index 80631a7..3d244bc 100644 --- a/HashCollisionChecker.java +++ b/HashCollisionChecker.java @@ -3,12 +3,23 @@ public class HashCollisionChecker { public static int countOfUniqueHashCodes(HashSet set) { // TODO: Implement - return 0; - } + Set 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/Shaffel.java b/Shaffel.java new file mode 100644 index 0000000..def4e39 --- /dev/null +++ b/Shaffel.java @@ -0,0 +1,17 @@ +import java.util.*; +public class Shaffel { + 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( linkedList); + Collections.shuffle(linkedList); + System.out.println( linkedList); + + } +} + diff --git a/Uni.java b/Uni.java new file mode 100644 index 0000000..bad40f6 --- /dev/null +++ b/Uni.java @@ -0,0 +1,77 @@ +import java.util.*; + +class Vorodi implements Comparable { + private String name; + private int code; + private double moadel; + + public void setName(String n) { + this.name = n; + } + + public String getName() { + return name; + } + + public void setCode(int c) { + this.code = c; + } + + public int getCode() { + return code; + } + + public void setMoadel(double m) { + this.moadel = m; + } + + public double getMoadel() { + return moadel; + } + + public int compareTo(Vorodi other) { + return Integer.compare(this.code, other.code); + } + + public Vorodi(String n, int c, double m) { + setName(n); + setCode(c); + setMoadel(m); + } + + public String d() { + return ("[" + getName() + "," + getCode() + "," + getMoadel() + "]"); + } +} + +public class Uni { + public static void main(String[]args) { + TreeSet studentSet = new TreeSet<>(); + Scanner s = new Scanner(System.in); + int tedad = s.nextInt(); + + + for (int i = 0; i < tedad; i++) { + String n = s.next(); + int c = s.nextInt(); + double m = s.nextDouble(); + Vorodi student = new Vorodi(n, c, m); + studentSet.add(student); + } + + int searchId = s.nextInt(); + boolean found = false; + for (Vorodi i : studentSet) { + if (searchId == i.getCode()) { + System.out.println("Student Found"); + System.out.println("name :" + i.getName() + "\nId : " + i.getCode() + "\nmoadel :" + i.getMoadel()); + found = true; + } + } + + if (!found) { + System.out.println("Student not Found"); + } + } + +} \ No newline at end of file