-
Notifications
You must be signed in to change notification settings - Fork 0
Feedback #1
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
base: feedback
Are you sure you want to change the base?
Feedback #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| * in flow control, loops, and collections. By mastering these concepts, developers will be able to write more | ||
| * efficient and effective code in their Salesforce projects. | ||
| * | ||
| * @author Your Name | ||
| * @author McKay Howell | ||
| */ | ||
|
|
||
| public with sharing class FlowControlLoopsCollections { | ||
|
|
@@ -29,7 +29,10 @@ | |
| * @return "Hello World!" if x greater than y, otherwise return null. | ||
| */ | ||
| public static String helloWorld(Integer x, Integer y) { | ||
| return null; // Replace null with the variable you used to store the result | ||
| if (x == null || y == null || x <= y) { | ||
| return null; | ||
| } | ||
| return 'Hello World!'; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -42,7 +45,7 @@ | |
| * @return true if the person is eligible to vote, false otherwise. | ||
| */ | ||
| public static Boolean votingEligibility(Integer age) { | ||
| return null; // Replace null with the variable you used to store the result | ||
| return (age >= 18); // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -55,10 +58,11 @@ | |
| * @return The maximum of the two numbers, or null if either number is null. | ||
| */ | ||
| public static Integer findMax(Integer num1, Integer num2) { | ||
| // Initialize largestNum as null | ||
| Integer largestNum = null; | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| if ( num1 == null || num2 == null) { | ||
| return null; | ||
| } | ||
| Integer largestNum = Math.max(num1, num2); | ||
| return largestNum; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -71,7 +75,15 @@ | |
| * @return A string indicating whether the number is "Positive", "Negative", or "Zero", or null if the number is null. | ||
| */ | ||
| public static String checkNumber(Integer a) { | ||
| return null; // Replace null with the variable you used to store the result | ||
| if (a == null) { | ||
| return null; | ||
| } else if (a > 0) { | ||
| return 'Positive'; | ||
| } else if (a < 0) { | ||
| return 'Negative'; | ||
| } else { | ||
| return 'Zero'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -83,7 +95,13 @@ | |
| * @return A string indicating whether the number is "Even" or "Odd", or null if the number is null. | ||
| */ | ||
| public static String checkEvenOdd(Integer a) { | ||
| return null; // Replace null with the variable you used to store the result | ||
| if(a == null) { | ||
| return null; | ||
| } else if (Math.mod(a, 2) == 0) { | ||
| return 'Even'; | ||
| } else { | ||
| return 'Odd'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,7 +112,11 @@ | |
| * @return A string indicating whether the input is "Empty", "Null", or "Contains Text". | ||
| */ | ||
| public static String checkString(String a) { | ||
| return null; // Replace null with the variable you used to store the result | ||
| if (String.isBlank(a)) { | ||
| return a == null ? 'Null' : 'Empty'; | ||
| } else { | ||
| return 'Contains Text'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -110,7 +132,17 @@ | |
| * @return The grade for the given score. | ||
| */ | ||
| public static String determineGrade(Integer score) { | ||
| return null; // Replace null with the variable you used to store the result | ||
| if (score >= 90) { | ||
| return 'A'; | ||
| } else if (score >= 80) { | ||
| return 'B'; | ||
| } else if (score >= 70) { | ||
| return 'C'; | ||
| } else if (score >= 60) { | ||
| return 'D'; | ||
| } else { | ||
| return 'F'; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -122,13 +154,11 @@ | |
| * @return The sum of all integers up to the limit. | ||
| */ | ||
| public static Integer sumUpToLimit(Integer intLimit) { | ||
| /* | ||
| for (){ | ||
|
|
||
| } | ||
| */ | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| Integer sum = 0; | ||
| for (Integer index = 1; index <= intLimit; index++){ | ||
| sum += index; | ||
| } | ||
| return sum; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -139,15 +169,13 @@ | |
| */ | ||
| public static String returnHelloWorld() { | ||
| // Initialize the result String | ||
|
|
||
| String result = ''; | ||
| // Use a for loop to append 'Hello World!;' to the result string three times | ||
| /* | ||
| for (){ | ||
|
|
||
| } | ||
| */ | ||
| for (Integer index = 1; index <= 3; index++){ | ||
| result += 'Hello World!; '; | ||
| } | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| return result; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -162,17 +190,19 @@ | |
| */ | ||
| public static String repeatString(String inputString, Integer repeatCount) { | ||
| // Initialize the result String | ||
| String result = ''; | ||
|
|
||
| // Use a for loop to append the inputString to the result string repeatCount times | ||
| /* | ||
| for () { | ||
|
|
||
| for (Integer index = 1; index <= repeatCount; index++) { | ||
| result += inputString; | ||
| // If it is not the last iteration, add a semicolon to separate the strings | ||
| if (index != repeatCount) { | ||
| result += '; '; | ||
| } | ||
| } | ||
| */ | ||
|
|
||
| // Return the final result string | ||
| return null; // Replace null with the variable you used to store the result | ||
| return result; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -183,14 +213,14 @@ | |
| */ | ||
| public static List<Integer> createAndPopulateList() { | ||
| // Create a new list of integers | ||
|
|
||
| List<Integer> intList = new List<Integer>{1, 2, 3}; | ||
| // Add the integers 1, 2, and 3 to the list | ||
| // add 1 | ||
| // add 2 | ||
| // add 3 | ||
|
|
||
| // Return the populated list | ||
| return null; // Replace null with the variable you used to store the result | ||
| return intList; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -203,10 +233,11 @@ | |
| // Create a new list of integers and add numbers 1 to 5 | ||
| List<Integer> numberList = new List<Integer>{1, 2, 3, 4, 5}; //DO NOT CHANGE | ||
|
|
||
| // Remove the 3rd element (number 3) from the list | ||
| // Remove the 3rd element (number 3) from the list; index values start with 0, so the third element has index 2 | ||
| numberList.remove(2); | ||
|
|
||
| // Return the updated list | ||
| return null; // Replace null with the variable you used to store the result | ||
| return numberList; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -218,14 +249,13 @@ | |
| */ | ||
| public static List<Integer> createIntegerList(Integer n) { | ||
| // Create a new list of integers | ||
|
|
||
| /* | ||
| for() { | ||
| //add integer to the list | ||
| List<Integer> intList = new List<Integer>(); | ||
|
|
||
| for(Integer index = 1; index <= n; index++){ | ||
| intList.add(index); | ||
| } | ||
| */ | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| return intList; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -237,12 +267,9 @@ | |
| * @return A Set of unique strings. | ||
| */ | ||
| public static Set<String> createStringSet(List<String> inputList) { | ||
| // Create a new Set of strings | ||
| Set<String> stringSet = new Set<String>(); | ||
|
|
||
| //add strings to the set | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| // Create a new Set of strings with values initialized from the inputList (deduplicated) | ||
| Set<String> stringSet = new Set<String>(inputList); | ||
| return stringSet; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -254,11 +281,19 @@ | |
| public static Integer sumPositiveIntegers() { | ||
| List<Integer> numbers = new List<Integer>{-1, 2, -3, 4, -5, 6}; //DO NOT CHANGE | ||
|
|
||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job using 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. |
||
| if(num < 0){ | ||
| continue; | ||
| } | ||
| sum += num; | ||
| } | ||
|
|
||
|
||
|
|
||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| return sum; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -271,11 +306,18 @@ | |
| */ | ||
| public static Integer findWordInList(String wordToFind, List<String> words) { | ||
| // The variable to store the index of the word | ||
| Integer index = -1; | ||
|
|
||
| // Loop through the list of words | ||
| for (String word : words){ | ||
| // If the current word is the word to find, exit the loop | ||
| if(word.equals(wordToFind)){ | ||
| index = words.indexOf(word); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| return index; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -289,7 +331,15 @@ | |
| // The list of money in the wallet, represented in dollars and cents | ||
| 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; | ||
|
||
| Decimal total = 0.0; | ||
| for (Decimal money : moneyInWallet){ | ||
| total += money; | ||
| if(total > STOP_VALUE){ | ||
| break; | ||
| } | ||
| } | ||
| return total; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -300,15 +350,21 @@ | |
| */ | ||
| public static Map<String, Integer> addItemsToMap() { | ||
| // Initialize an empty Map | ||
| Map<String, Integer> fruits = new Map<String,Integer>(); | ||
|
|
||
| // Add key-value pairs to the Map | ||
| // add Apples => 5 | ||
| fruits.put('Apples', 5); | ||
| // add Oranges => 10 | ||
| fruits.put('Oranges', 10); | ||
| // add Bananas => 15 | ||
| fruits.put('Bananas', 15); | ||
| // add Pears => 20 | ||
| fruits.put('Pears', 20); | ||
| // add Grapes => 25 | ||
| fruits.put('Grapes', 25); | ||
|
|
||
| return null; // Replace null with the variable you used to store the result | ||
| return fruits; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -322,17 +378,23 @@ | |
| */ | ||
| public static Integer getSalary(String employeeName) { | ||
| // Initialize a Map | ||
| Map<String, Integer> employees = new Map<String, Integer>(); | ||
|
|
||
| // Add key-value pairs to the Map | ||
| // add John Doe => 50000 | ||
| employees.put('John Doe', 50000); | ||
| // add Jane Smith => 60000 | ||
| employees.put('Jane Smith', 60000); | ||
| // add Sam Brown => 55000 | ||
| employees.put('Sam Brown', 55000); | ||
| // add Alice Johnson => 65000 | ||
| employees.put('Alice Johnson', 65000); | ||
|
|
||
| // Get the salary of the employee | ||
| Integer salary = employees.get(employeeName); | ||
|
|
||
| // Return the salary of the employee, or null if the employee is not found in the Map | ||
| return null; // Replace null with the variable you used to store the result | ||
| return salary; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -349,20 +411,31 @@ | |
| // Initialize a Map | ||
| Map<String, Integer> employeeSalaries = new Map<String, Integer>(); | ||
|
|
||
| // Add key-value pairs to the Map | ||
| // add John Doe => 50000 | ||
| employeeSalaries.put('John Doe', 50000); | ||
| // add Jane Smith => 60000 | ||
| employeeSalaries.put('Jane Smith', 60000); | ||
| // add Sam Brown => 55000 | ||
| employeeSalaries.put('Sam Brown', 55000); | ||
| // add Alice Johnson => 65000 | ||
| employeeSalaries.put('Alice Johnson', 65000); | ||
|
|
||
| // Initialize a list to store the names of high paid employees | ||
| List<String> highPaidEmployees = new List<String>(); | ||
|
|
||
| final Integer HIGH_SALARY = 55000; | ||
Check warningCode scanning / PMD The final local variable name 'HIGH_SALARY' doesn't match '[a-z][a-zA-Z0-9]*' Warning
The final local variable name 'HIGH_SALARY' doesn't match '[a-z][a-zA-Z0-9]*'
|
||
| // Iterate over the Map using a for loop | ||
| for(String name : employeeSalaries.keySet()){ | ||
| // Check if the salary of the employee is more than 55000 | ||
| Integer salary = employeeSalaries.get(name); | ||
| if(salary > HIGH_SALARY){ | ||
| // Add the employee to the list of high paid employees | ||
| highPaidEmployees.add(name); | ||
| } | ||
| } | ||
|
|
||
| // Return the list of high paid employees | ||
| return null; // Replace null with the variable you used to store the result | ||
| return highPaidEmployees; // Replace null with the variable you used to store the result | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.