Conversation
walters954
left a comment
There was a problem hiding this comment.
Great Work, McKay! 🎉
Congratulations on completing Module 2! You've demonstrated a solid understanding of flow control, loops, and collections in Apex.
What You Did Well
-
Null Handling: You consistently checked for null values before processing (e.g., in
helloWorld,findMax,checkNumber). This defensive programming approach prevents runtime errors - a crucial skill in Salesforce development. -
Proper Use of Jump Statements: Your use of
continueinsumPositiveIntegersandbreakinfindWordInListshows you understand how to control loop execution effectively. -
Clean Code Practices: I noticed you used constants like
STOP_VALUEandHIGH_SALARYinstead of magic numbers. This makes your code more readable and maintainable - excellent habit! -
Good Comments: Adding explanatory comments (like noting that list indices start at 0) shows you're thinking about code clarity.
-
Collection Mastery: You correctly worked with Lists, Sets, and Maps, demonstrating understanding of when to use each collection type.
Suggestions for Growth
I've left a few inline comments with tips for optimization and alternative approaches. These aren't corrections - your solutions work perfectly! They're just professional patterns you might find useful as you continue your Salesforce journey.
Keep up the excellent work! You're building a strong foundation in Apex programming. 💪
| if (a == null) { | ||
| return 'Null'; | ||
| } else if (a == '') { | ||
| return 'Empty'; |
There was a problem hiding this comment.
Great work using String.isEmpty() alternative logic here! For future reference, Apex provides a handy String.isBlank() method that checks for both null and empty strings in one call. You could simplify this to:
if (String.isBlank(a)) {
return a == null ? 'Null' : 'Empty';
} else {
return 'Contains Text';
}That said, your current implementation is perfectly correct and clear - just a tip for the future!
| final Decimal STOP_VALUE = 40.0; | ||
| Decimal total = 0.0; | ||
| for (Decimal money : moneyInWallet){ | ||
| if(total <= STOP_VALUE){ |
There was a problem hiding this comment.
Nice use of a constant (STOP_VALUE) here - that's a professional practice that makes code more readable and maintainable!
One small optimization: you could use break to exit the loop once you've exceeded 40, rather than continuing to iterate through the remaining items:
for (Decimal money : moneyInWallet){
total += money;
if(total > STOP_VALUE){
break;
}
}This would be more efficient for larger lists since it stops processing once the condition is met. Your current solution works correctly though!
| //add strings to the set | ||
| //add strings to the set - sets cannot contain duplicate values so adding same values does not affect string | ||
| for (String input : inputList){ | ||
| stringSet.add(input); |
There was a problem hiding this comment.
Excellent use of a Set to remove duplicates! Your comment explaining that "sets cannot contain duplicate values" shows you understand the concept well.
Pro tip: You can also initialize a Set directly from a List in one line:
Set<String> stringSet = new Set<String>(inputList);This is a common Apex pattern for deduplication. Your loop approach is great for learning how Sets work though!
| Integer sum = 0; | ||
| // Loop through the list of integers | ||
| for(Integer num : numbers){ | ||
| // if the number is negative skip this iteration |
There was a problem hiding this comment.
Great job using continue to skip negative numbers! This demonstrates you understand jump statements well.
I love that you're using a for-each loop here - it's cleaner and more readable than a traditional for loop when you don't need the index.
| List<Decimal> moneyInWallet = new List<Decimal>{0.50, 10, 3.84, 24.60, 9.08, 50, 4.90}; //DO NOT CHANGE | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| final Decimal STOP_VALUE = 40.0; |
Check warning
Code scanning / PMD
The final local variable name 'STOP_VALUE' doesn't match '[a-z][a-zA-Z0-9]*' Warning
👋! GitHub Classroom created this pull request as a place for your teacher to leave feedback on your work. It will update automatically. Don’t close or merge this pull request, unless you’re instructed to do so by your teacher.
In this pull request, your teacher can leave comments and feedback on your code. Click the Subscribe button to be notified if that happens.
Click the Files changed or Commits tab to see all of the changes pushed to the default branch since the assignment started. Your teacher can see this too.
Notes for teachers
Use this PR to leave feedback. Here are some tips:
For more information about this pull request, read “Leaving assignment feedback in GitHub”.
Subscribed: @mckayhowell