Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ed9f927
Answer the automated testing reflection questions
HassanOHOsman Jul 22, 2026
f4c8d0e
Create StudentGrades class class with 3 fields (arrays) and a constru…
HassanOHOsman Aug 1, 2026
f4626c5
Create a method getDistinctFirstNames that returns ONLY unique first …
HassanOHOsman Aug 1, 2026
1f7b594
Create a method getDistinctFirstNamesInAlphabeticalOrder that returns…
HassanOHOsman Aug 1, 2026
53f7bf1
Create a method getLastNameToGrade that returns last names and grades…
HassanOHOsman Aug 1, 2026
5ce0ade
1. Update getDistinctFirstNames methods by using HashSet constructor …
HassanOHOsman Aug 2, 2026
8993c8d
1. Correct getLastNameToGrade to use HashMap instead and then loop th…
HassanOHOsman Aug 2, 2026
245d1f1
Answer the reflection question from exercise 2.1
HassanOHOsman Aug 2, 2026
3d1dba7
Create a Student class with fields firstName and lastName
HassanOHOsman Aug 2, 2026
fd81f97
Add a constructor, and getters.
HassanOHOsman Aug 2, 2026
c2457bf
1.Correct the fields of Student to the correct data type (arrays of s…
HassanOHOsman Aug 2, 2026
d97c3c7
1. implement getStudentToGrade method.
HassanOHOsman Aug 2, 2026
bc957e4
1. Copy the solution (so far) of exercise 2.2 to me merged with exerc…
HassanOHOsman Aug 2, 2026
18e7ebf
Update data sets (arrays)
HassanOHOsman Aug 2, 2026
942d30a
Correct the fields in the Student class to be Strings and not arrays …
HassanOHOsman Aug 2, 2026
1e57066
Override the hashCode() and equals() methods so that this map to work…
HassanOHOsman Aug 2, 2026
1db9cf9
Override the toString() method in order to get a meaningful and reada…
HassanOHOsman Aug 2, 2026
16a838b
exercise 2.3: Call each of the methods already created and assign the…
HassanOHOsman Aug 2, 2026
e147b51
Correct some variables names and data types
HassanOHOsman Aug 2, 2026
edd083b
Modify each of the collections created to include the new student and…
HassanOHOsman Aug 2, 2026
0d92343
1. Update the collections adding a new student.
HassanOHOsman Aug 2, 2026
70f9168
Modify the collections that handle grades to update the grade from th…
HassanOHOsman Aug 2, 2026
09a3428
Answer all reflection questions to exercise 3.2
HassanOHOsman Aug 3, 2026
990ad78
Answer all reflection questions to exercise 2.3 (not 3.2)
HassanOHOsman Aug 3, 2026
7006396
Add statements to help find the highest and lowest grades.
HassanOHOsman Aug 3, 2026
846af64
Add statements to help find the first and last names of the student w…
HassanOHOsman Aug 3, 2026
896db5d
Add statements to help find duplicate first names.
HassanOHOsman Aug 3, 2026
437461f
Create .gitignore file, containting all the files and folders to be u…
HassanOHOsman Sep 11, 2026
cf37b7b
untrack .idea folder and its content
HassanOHOsman Sep 11, 2026
f5a553a
update .gitignore
HassanOHOsman Sep 11, 2026
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# IntelliJ
.idea/
*.iml

# IntelliJ build output
out/

# Compiled class files
*.class

# Maven build output
target/
17 changes: 17 additions & 0 deletions Exercises/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>2</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>26</maven.compiler.source>
<maven.compiler.target>26</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
80 changes: 80 additions & 0 deletions Exercises/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.example;


import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
String[] firstNames = {"Anuket", "Eryn", "Filip", "Raquel", "Eryn", "Ali", "Sam"};
String[] lastNames = {"Hassan", "Doe", "Pappas", "Clarke", "Jones", "Hassan", "Clarke"};
int[] grades = {22, 45, 35, 22, 41, 48, 39};

StudentGrades studentGrades = new StudentGrades(firstNames, lastNames, grades);

System.out.println(Arrays.toString(studentGrades.getFirstNames()));
System.out.println(studentGrades.getDistinctFirstNames(firstNames));
System.out.println(studentGrades.getDistinctFirstNamesInAlphabeticalOrder(firstNames));
System.out.println(studentGrades.getLastNameToGrade(lastNames, grades));

System.out.println(studentGrades.getStudentToGrade());


List<String> firstNamesList = new ArrayList<>(Arrays.asList(studentGrades.getFirstNames()));
Set<String> distinctFirstNamesSet = studentGrades.getDistinctFirstNames(firstNames);
Set<String> distinctFirstNamesInAlphabeticalOrderSet = studentGrades.getDistinctFirstNamesInAlphabeticalOrder(firstNames);
Map<String, Integer> lastNamesToGradesMap = studentGrades.getLastNameToGrade(lastNames, grades);
Map<Student, Integer> studentToGradeMap = studentGrades.getStudentToGrade();


firstNamesList.add("Patrick");
distinctFirstNamesSet.add("Patrick");
distinctFirstNamesInAlphabeticalOrderSet.add("Patrick");
lastNamesToGradesMap.put("Smith", 49);
studentToGradeMap.put(new Student("Patrick", "Smith"), 49);

firstNamesList.remove("Patrick");
distinctFirstNamesSet.remove("Patrick");
distinctFirstNamesInAlphabeticalOrderSet.remove("Patrick");
lastNamesToGradesMap.remove("Smith", 49);
studentToGradeMap.remove(new Student("Patrick", "Smith"), 49);

lastNamesToGradesMap.replace("Smith", 49, 0);
studentToGradeMap.replace(new Student("Patrick", "Smith"), 49, 0);

int highestGrade = Arrays.stream(grades).max().getAsInt();
System.out.println(highestGrade); // Highest grade is 48

int lowestGrade = Arrays.stream(grades).min().getAsInt();
System.out.println(lowestGrade); // Lowest grade is 22



Student highestGradeStudent = studentToGradeMap.entrySet()
.stream()
.max(Map.Entry.comparingByValue())
.get()
.getKey();

System.out.println(highestGradeStudent.getFirstName());
System.out.println(highestGradeStudent.getLastName());




Set<String> duplicateFirstNames = firstNamesList.stream()
.filter(firstName -> Collections.frequency(firstNamesList, firstName) > 1)
.collect(Collectors.toSet());

System.out.println(duplicateFirstNames);


}


}


50 changes: 50 additions & 0 deletions Exercises/src/main/java/org/example/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.example;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class Student {
private String firstName;
private String lastName;

public Student(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}

Student student = (Student) object;

return firstName.equals(student.firstName) && lastName.equals(student.lastName);
}

@Override
public int hashCode() {
return Objects.hash(firstName, lastName);
}

@Override
public String toString(){
return firstName + " " + lastName;

}


}
109 changes: 109 additions & 0 deletions Exercises/src/main/java/org/example/StudentGrades.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.example;

import java.util.*;

public class StudentGrades {
private String[] firstNames;
private String[] lastNames;
private int[] grades;

public StudentGrades(String[] firstNames, String[] lastNames, int[] grades) {
this.firstNames = firstNames;
this.lastNames = lastNames;
this.grades = grades;
}

public String[] getFirstNames() {
return firstNames;
}

public String[] getLastNames() {
return lastNames;
}

public int[] getGrades() {
return grades;
}

public Set<String> getDistinctFirstNames(String[] firstNames) {
Set<String> set = new HashSet<>();
set.addAll(Arrays.asList(firstNames));
return set;
}

public Set<String> getDistinctFirstNamesInAlphabeticalOrder(String[] firstNames) {
Set<String> set = new TreeSet<>();
set.addAll(Arrays.asList(firstNames));
return set;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in order?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.



}

public Map<String, Integer> getLastNameToGrade(String[] lastNames, int[] grades) {
Map<String, Integer> map = new HashMap<>();

for (int i = 0; i < lastNames.length; i++) {
map.put(lastNames[i], grades[i]);
}
return map;
}


public Map<Student, Integer> getStudentToGrade() {
Map<Student, Integer> map = new HashMap<>();

for (int i = 0; i < firstNames.length; i ++) {
Student student = new Student(firstNames[i], lastNames[i]);
map.put(student, grades[i]);
}
return map;
}

}

/*
Reflection - Exercise 2.1

Question: Suppose there are a set of twins in the class, so there are some duplicate lastNames. Can we still build a
map of students to their grades?

Answer: perhaps we might need a 4th array that provide unique values that could be associated with each student.
Something like an array of student's ID numbers can work. Otherwise, maybe there's a way for the key to be
customized to include both the first and last names of each student in such cases.



Reflections - Exercise 2.3
Think about the following questions, make notes and be prepared to talk through your thoughts in the workshop.

Q1. Would it have been possible to use Arrays to model the same data?
A1. Yes, it would.

Q2. Would it have been easier, harder or the same? Why?
A2. It would have been harder. This is because arrays are not dynamic, they are of fixed size, therefore, adding and
removing elements would have been more challenging.

Q3. What was your thought process when deciding which data structure was most appropriate for modelling particular data?
What things did you consider?
A3. If the goal was to have data represented in key-value pair, then I'd use HashMap (other implementations of Map
interface can work. If the goal was to have data as distinct values, then I'd use HashSet (other Set interface
implementations can work), and if order mattered, then I'd go for TreeSet instead. If the data insertion order and
storing order matters, then, I'd go for an ArrayList (other List implementation can work).

Q4. Suppose the initial data set was input incorrectly and the same student’s name and grade was input twice. How would
your Map<Student, Grade> handle this? Why?
A4. Since Student is key here, and Student class has implemented both equals() and hashCode() methods, then they will
consider duplicate student objects as the same object. Therefore, Map<Student, Grade> treats them as the same key.

Q5. What is the difference between variables: a) List firstNames, b) List<String> firstNames,
c) ArrayList<String> firstNames ? Which is preferable? Bonus: how about List<?> firstNames ?
A5. a) is a list interface that may contain different data types
b) is a list interface of Strings ONLY
c) is an array list - implementing the List interface - and cntains Strings only

I prefer List<String> firstNames because interfaces are more flexible, allowing loose coupling and multiple
inheritance. Also having the input type - String - explicitly stated ensure that no other data type can be passed.

Regarding List<?> firstNames perhaps it's a list of certain type which is yet to be confirmed.

*/