Skip to content

Sheffield | 26-Java-June | Hassan Osman | Sprint 4 | Prep: Streams and Optionals - #73

Open
HassanOHOsman wants to merge 25 commits into
CodeYourFuture:mainfrom
HassanOHOsman:prep/streams-and-optionals-exercises
Open

HassanOHOsman wants to merge 25 commits into
CodeYourFuture:mainfrom
HassanOHOsman:prep/streams-and-optionals-exercises

Conversation

@HassanOHOsman

Copy link
Copy Markdown

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

In this PR, I implemented solutions revolve around the use of streams with collections.

2. Git-ignore files and folders that should not be tracked.
… to print to the console all names start with A (case in-sensitive).

2. Construct a Main class with main method inside, create a StreamExercise isntance and class the printNamesStartingWithA from there.
…ass. The method returns all names start with a vowel, capitalized, and in a reverse alphabetical order.
…ass. The method returns all names start with a vowel, capitalized, and in a reverse alphabetical order.

2. Remove samples aimed for debugging and logging from the main method
…- that takes 1) a map containing shapes and their respective number of sides, and 2) the number of sides. It returns the number of shapes that has that number of sides.
…the remainders of the division of numbers from 1 -20 inclusive by any divisor (integer), comma-separated.
…the remainders of the division of numbers from 1 -20 inclusive by any divisor (integer), comma-separated.
@HassanOHOsman HassanOHOsman added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 4 Assigned during Sprint 4 of this module labels Aug 12, 2026
@jacknewman1995 jacknewman1995 self-assigned this Sep 4, 2026
@jacknewman1995 jacknewman1995 added Review in progress and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Sep 4, 2026

@jacknewman1995 jacknewman1995 left a comment

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 work, have added some relatively minor comments. Mainly just check in future that you're only pushing your java files in PRs.

Comment thread .idea/vcs.xml Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't be including these - add them to gitignore

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Likewise for other PRs not just yours, probably something good to reiterate with the group

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.

Shouldn't be including these - add them to gitignore

By bad! Sorted now. Thank you :)

.filter(name -> name.toUpperCase().startsWith("A"))
.collect(Collectors.toList());

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("^[AEIOUaeiou].*"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need the lowercase in the regex given we've said toUpperCase?

@HassanOHOsman HassanOHOsman Sep 10, 2026 •

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.

Yeah, not so intelligent from myself lol since I am already using .toUpperCase beforehand. Corrected. Thank you!

public class Remainders {

public void printRemainders(int divisor) {
String remainders = "";

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 a string the best data structure for storing numbers?

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.

It is definitely not. Again, perhaps I've misread the requirements. Anyway, I've used a List of Integers instead and updated the rest of the code block. Thank you :)


public void printRemainders(int divisor) {
String remainders = "";
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?

int remainder = i % divisor;
if (i < 20) {
remainders += remainder + ",";
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bit clunky! How can we avoid this by using more appropriate data structures?

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, changed this now.


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!


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!


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

int numOfShapesWithThatNumOfSides = (int) shapesToSides.values().stream()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why the cast?

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.

For some reason by brains defaults to "int". Anyway, since the stream operation gives a long, I've updated the code block by removing the casting to "int" parts. Also, changed the type to "long" in the method signature.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like a load of .class files have been committed here? Should be just .java as .class is the compiled bytecode which I may struggle to read..!

@HassanOHOsman HassanOHOsman Sep 11, 2026 •

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.

I am really sorry Jack! I've run terminal commands and all the .class file in this branch are untracked. I however now added them specifically into my .gitignore. Please let me know if this is still an issue. I am really sorry.

@jacknewman1995 jacknewman1995 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 4, 2026
@HassanOHOsman

Copy link
Copy Markdown
Author

Nice work, have added some relatively minor comments. Mainly just check in future that you're only pushing your java files in PRs.

Hi Jack! Thank you for taking the time to review my work. I've changed my code as per your request. please review and let me know if there's anything else you want me to fix.

On a side note, as per my checks all .class files are not git-tracked. I don't know why they still show. Anyway, I've now added .class specifically inside my .gitignore file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 4 Assigned during Sprint 4 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants