Skip to content

Last Assignment #13

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
22 changes: 22 additions & 0 deletions Cars.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.*;
public class Main {
public static void main(String[] args) {
Queue<String> Cars = new LinkedList<>();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++){
Cars.add(sc.next());
}

for (int i = 0; i < n; i++){
System.out.println(Cars.poll());
}

if (Cars.isEmpty()) {
System.out.println("is empty");
}
else {
System.out.println("is not empty");
}
}
}
71 changes: 40 additions & 31 deletions Detective.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@

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:



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

}


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 Sherlock = sherlocksToDos.size();
int Poirot = poirotsToDos.size();
System.out.println(Sherlock);
System.out.println(Poirot);


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

if(Sherlock > Poirot) {
System.out.println("Sherlock");
}
else {
System.out.println("Poirot");
}

}

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

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

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

public static void main(String[] args) {
HashSet<String> set = new HashSet<>();
Expand All @@ -18,12 +24,12 @@ public static void main(String[] args) {
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
System.out.println(HashCollisionChecker.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
System.out.println(HashCollisionChecker.countOfUniqueHashCodes(map)); // 2
}
}
13 changes: 13 additions & 0 deletions Shuffle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.util.LinkedList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
LinkedList<Integer> linkedList = new LinkedList<>();
linkedList.add(1);
linkedList.add(2);
linkedList.add(3);
linkedList.add(4);
Collections.shuffle(linkedList);
System.out.println(linkedList);
}
}
73 changes: 73 additions & 0 deletions University.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
public class Student implements Comparable<Student> {
private String Name;
private int ID;
private Double GPA;
public Student (String Name, int ID, Double GPA){
this.Name = Name;
this.ID = ID;
this.GPA = GPA;
}
public String getName() {
return Name;
}
public void setName(String Name){
this.Name = Name;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public Double getGPA() {
return GPA;
}
public void setGPA(Double GPA) {
this.GPA = GPA;
}

public int compareTo(Student other) {
return Integer.compare(this.ID, other.ID);
}
public String toString() {
return "Name: " + Name + ", Student ID: " + ID + ", GPA: " + GPA;
}
}

import java.util.Scanner;
import java.util.TreeSet;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TreeSet<Student> students = new TreeSet<>();

System.out.println("Enter number of students:");
int numberOfStudents = sc.nextInt();
sc.nextLine();
for (int i = 0; i < numberOfStudents; i++) {
System.out.println("Student " + (i + 1) + ":");
System.out.print("Name: ");
String Name = sc.nextLine();
System.out.print("Student ID: ");
int ID = sc.nextInt();
System.out.print("GPA: ");
double GPA = sc.nextDouble();
sc.nextLine();

students.add(new Student(Name, ID, GPA));
}

System.out.print("Enter student ID to search: ");
int searchID = sc.nextInt();
Student searchStudent = new Student("", searchID, 0.0);

Student result = students.ceiling(searchStudent);

if (result != null && result.getID() == searchID) {
System.out.println("Student found: " + result);
} else {
System.out.println("Student not found.");
}
}
}