Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ed9f927
Answer the automated testing reflection questions
HassanOHOsman Jul 22, 2026
dd93b7a
1. Get rid of irrelevant files from previous exercises.
HassanOHOsman Aug 8, 2026
24bb271
Add TestStreamsExercise class and its parent class - ExerciseTest.
HassanOHOsman Aug 10, 2026
d0765af
Add TestStreamsExercise class and its parent class - ExerciseTest.
HassanOHOsman Aug 10, 2026
0f368f8
get rid of previous exercises
HassanOHOsman Aug 10, 2026
02528ae
Add a .gitignore file and add all files and folders in it that should…
HassanOHOsman Aug 10, 2026
f835778
Create a class StreamExercise and start implementing printNamesStarti…
HassanOHOsman Aug 11, 2026
172fe39
1. Complete implementing the printNamesStartingWithA method that aims…
HassanOHOsman Aug 11, 2026
5f3f7ab
Update the class name from StreamsExercise to NameFinder to comply wi…
HassanOHOsman Aug 11, 2026
2a06823
Implement vowelNamesCapitalisedDescending method inside NameFinder cl…
HassanOHOsman Aug 11, 2026
2c027c0
Implement vowelNamesCapitalisedDescending method inside NameFinder cl…
HassanOHOsman Aug 11, 2026
9169d0a
Inside ShapeCounter class, implement a method - countShapesWithSides …
HassanOHOsman Aug 11, 2026
a230588
Construct Remainders class and start implementing printRemainders met…
HassanOHOsman Aug 11, 2026
a545bc3
Complete implementing printRemainders method to successfully log out …
HassanOHOsman Aug 11, 2026
12fae81
Complete implementing printRemainders method to successfully log out …
HassanOHOsman Aug 12, 2026
7650ddc
Complete implementing remainderGroups method.
HassanOHOsman Aug 12, 2026
2e3f3b2
Complete implementing remainderGroups method.
HassanOHOsman Aug 12, 2026
347a47e
Untrack .idea directory, already covered by .gitignore
HassanOHOsman Sep 9, 2026
06d4b8b
Untrack out/ build directory, already covered by .gitignore
HassanOHOsman Sep 9, 2026
abeb206
update printNamesStartingWithA method by printing the streamed data w…
HassanOHOsman Sep 10, 2026
69d6a15
Update vowelNamesCapitalisedDescending by removing lowercase vowels f…
HassanOHOsman Sep 10, 2026
d2f23f7
Update printRemainders where remainder is changed to List<Integer> a …
HassanOHOsman Sep 11, 2026
5569886
Ensure that it's remainders and not remainder for all the references …
HassanOHOsman Sep 11, 2026
a34ed07
update countShapesWithSides signature so the return is long instead o…
HassanOHOsman Sep 11, 2026
de9cf83
Added .class specifically inside .gitignore file.
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# IntelliJ
.idea/
*.iml

# IntelliJ build output
out/

# Compiled class files
*.class
25 changes: 25 additions & 0 deletions exercise/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>exercise</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>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
</dependencies>

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

import java.util.List;
import java.util.stream.Collectors;

public class NameFinder {

public void printNamesStartingWithA(List<String> listOfNames) {
List<String> namesStartsWithA = listOfNames.stream()
.filter(name -> name.toUpperCase().startsWith("A"))
.forEach(System.out::println);

System.out.println(namesStartsWithA);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice! Can you do the printing without needing to create the list or any other variable?

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, we can. I don't know for whatever reason I presumed that the stream out should be packaged back into a list.


}


public void vowelNamesCapitalisedDescending(List<String> listOfNames) {
List<String> namesStartsWithVowel = listOfNames.stream()
.filter(name -> name.toUpperCase().matches("^[AEIOU].*"))
.collect(Collectors.toList()).reversed();

System.out.println(namesStartsWithVowel);
}



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

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Remainders {

public void printRemainders(int divisor) {
List<Integer> remainders = new ArrayList<>();
for (int i = 1; i <= 20; i ++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How come we aren't streaming here?

remainders.add(i % divisor);
}
String output = remainders.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));

System.out.println(output);

}



public Map<Integer, List<Integer>> remainderGroups(int divisor) {

Map<Integer, List<Integer>> result = IntStream.rangeClosed(1, 20)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice!

.boxed()
.collect(Collectors.groupingBy(number -> number % divisor));

return result;
}



public Map<Integer, Long> remainderCounts(int divisor) {

Map<Integer, Long> result = IntStream.rangeClosed(1, 20)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice!

.boxed()
.collect(Collectors.groupingBy(number -> number % divisor, Collectors.counting()));

return result;

}


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

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ShapeCounter {

public long countShapesWithSides(Map<String, Integer> shapesToSides, int numberOfSides) {

return shapesToSides.values().stream()
.filter(value -> value == numberOfSides)
.count();

}
}