From cd759328c264489077001a62683069c7f149f094 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Mon, 8 Jun 2026 17:48:27 +0000 Subject: [PATCH 1/3] Setting up GitHub Classroom Feedback From 12d6e86a34de3b0fbe3db99191220b6f4028ad0b Mon Sep 17 00:00:00 2001 From: cathancock Date: Wed, 1 Jul 2026 18:32:23 -0400 Subject: [PATCH 2/3] Completed Module3 ClassesObjectsMethods --- .../default/classes/ClassesObjectsMethods.cls | 315 ++++++++++++------ 1 file changed, 215 insertions(+), 100 deletions(-) diff --git a/force-app/main/default/classes/ClassesObjectsMethods.cls b/force-app/main/default/classes/ClassesObjectsMethods.cls index af5b8d8..5473d78 100644 --- a/force-app/main/default/classes/ClassesObjectsMethods.cls +++ b/force-app/main/default/classes/ClassesObjectsMethods.cls @@ -4,7 +4,7 @@ * * This class introduces developers to the concept of creating and manipulating objects in Apex. It discusses * how to define classes, create methods, and use objects. This class uses two example classes - Person and Book. - * + * * Topics covered in this class include: * - Understanding how to define a class in Apex. * - Understanding how to create methods in Apex. @@ -13,20 +13,20 @@ * * Users of this class can expect to gain a strong understanding of Object Oriented Programming in Apex and * be prepared for more advanced topics in Salesforce development. - * + * * The Person class is a simple representation of a person with properties like name and age, and a method * that allows the person to introduce themselves. - * + * * The Book class is a simple representation of a book with properties like title and author, and methods * to read and close the book. - * + * * Resources: * String class: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm * Date class: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_date.htm * Math class: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_math.htm * Classes: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_understanding.htm * - * @author Your Name + * @author Catherine Hancock */ public with sharing class ClassesObjectsMethods { @@ -40,19 +40,32 @@ public with sharing class ClassesObjectsMethods { */ public static List practiceStringMethods() { // Initialize a String with 'Hello, Salesforce!' + String myString = 'Hello, Salesforce!'; + + // Get the length of the String + Integer myLength = myString.length(); - // Get the length of the String // Get a substring of the String of the first 5 characters + String mySubstring = myString.substring(0, 5); + // Convert the String to lower case + String lowerStr = myString.toLowerCase(); // Return the list with the string data + List result = new List(); + // In the first position add the string length + result.add(String.valueOf(myLength)); + // In the second position add the substring + result.add(String.valueOf(mySubstring)); + // In the third position add the string in lower case - - return null; // Replace null with the variable you used to store the result + result.add(lowerStr); + + return result; // Replace null with the variable you used to store the result } - + /** * Question 2 * Check if the input string starts with 'Sales', ends with 'Force', and contains 'Awesome'. @@ -62,16 +75,20 @@ public with sharing class ClassesObjectsMethods { */ public static List checkStringContent(String input) { // Initialize a list to store the results + List result = new List(); // Check if the string starts with 'Sales' + result.add(input.startsWith('Sales')); // Check if the string ends with 'Force' + result.add(input.endsWith ('Force')); // Check if the string contains 'Awesome' + result.add(input.contains('Awesome')); - 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 } - + /** * Question 3 * Take a sentence then remove any duplicate words, and return the sentence with only unique words. @@ -81,39 +98,51 @@ public with sharing class ClassesObjectsMethods { */ public static String removeDuplicateWords(String sentence) { // Split the sentence into words - + List words = sentence.split(' '); //<- '' splits the string everywhere there is a space. + // Create a set to store the unique words - + Set separateWords = new Set(); + // Add each word to the set - + for (String word : words) { + separateWords.add(word); + } // Join the unique words back into a sentence - + String result = String.join(new List(separateWords), ' '); + // Return the sentence with unique words - 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 } - + /** * Question 4 * This method takes a string as a parameter, and calculates the number of vowels in the string. * For simplicity, we will consider only five vowels: 'a', 'e', 'i', 'o', 'u', and we will ignore case. * Example: countVowels("Hello World!") should return 3 - * @param s The string in which to count vowels. + * @param str The string in which to count vowels. * @return The number of vowels in the string. */ public static Integer countVowels(String str) { // Initialize the result Integer - + Integer result = 0; + /* for () { // get individual characters from the string - hint use substring or split // check if the character is a vowel // if it is a vowel, increment the result Integer } - */ - - return null; // Replace null with the variable you used to store the result + */ + for( Integer i = 0; i < str.length(); i++){ + String letter = str.substring(i, i + 1).toLowerCase(); + if ('aeiouA'.contains(letter)) { + result++;} + + } + + return result; // Replace null with the variable you used to store the result } - + /** * Question 5 * Given a list of scientist names, combine their names together with a comma if it contains the letter 'g'. @@ -123,21 +152,39 @@ public with sharing class ClassesObjectsMethods { */ public static String findTheScientist() { // The list of scientists' names - List scientistNames = new List{'Tim Berners-Lee', 'Alan Turing', 'Grace Hopper', 'Donald Knuth', 'Guido van Rossum', 'Ken Thompson', 'Stephen Hawking'}; - + List scientistNames = new List{ + 'Tim Berners-Lee', + 'Alan Turing', + 'Grace Hopper', + 'Donald Knuth', + 'Guido van Rossum', + 'Ken Thompson', + 'Stephen Hawking' + }; + // The variable to store the concatenated string - + String result = ''; + // Loop through the list of scientists' names - - // If the name doesn't contain the letter 'G', skip this iteration - + for (String name : scientistNames) { + + // If the name doesn't contain the letter 'g', skip this iteration + if (!name.toLowerCase().contains('g')) { + continue; + } + // Add the name to the result string, followed by a comma - + result += name + ','; + } + // Remove the last comma from the result string - - return null; // Replace null with the variable you used to store the result + if (result.length() > 0) { + result = result.substring(0, result.length() - 1); + } + + return result; } - + /** * Question 6 * This method calculates the absolute value of the difference between of two input numbers that are raised to the 2nd power. @@ -148,13 +195,15 @@ public with sharing class ClassesObjectsMethods { */ public static Double calculateDifferenceOfSquares(Double a, Double b) { // Square the input numbers using the Math.pow() function - + Double squaredA = Math.pow(a, 2); + // Calculate the absolute difference using Math.abs() function - + Double difference = Math.abs(squaredA - Math.pow(b, 2)); + // Return the result - return null; // Replace null with the variable you used to store the result + return difference; // Replace null with the variable you used to store the result } - + /** * Question 7 * Generate a random number between 50 and 100 @@ -163,11 +212,12 @@ public with sharing class ClassesObjectsMethods { */ public static Integer generateRandomNumber() { // Use Math class to generate number between 50 and 100 - + Integer randomNumber = Math.mod(Crypto.getRandomInteger(), 51) + 50; + // Return the random integer - return null; // Replace null with the variable you used to store the result + return randomNumber; // Replace null with the variable you used to store the result } - + /** * Question 8 * Format the current date in the current user locale format. @@ -176,13 +226,15 @@ public with sharing class ClassesObjectsMethods { */ public static String getCurrentDate() { // Get the todays date - + Date today = Date.today(); + // Format the current date - + String formattedDate = today.format(); + // Return the result - return null; // Replace null with the variable you used to store the result + return formattedDate; // Replace null with the variable you used to store the result } - + /** * Question 9 * Given a date time return the day of the week in number format @@ -191,17 +243,27 @@ public with sharing class ClassesObjectsMethods { */ public static String getDayOfWeek(DateTime dt) { // Define a map of day of the week as a key and day number as the value - // Monday = 1, Tuesday = 2, etc. - + Map dayMap = new Map (); + // Monday = 1, Tuesday = 2, etc. ->"new Map ();" starts with empty list and uses .put method vs "{}" Not sure which map syntax to use and why? Researching it looks like one is fully initializing "{}" and one is just an empty map and populating it "()"? + dayMap.put ('Monday', 1); + dayMap.put ('Tuesday', 2); + dayMap.put ('Wednesday', 3); + dayMap.put ('Thursday', 4); + dayMap.put ('Friday', 5); + dayMap.put ('Saturday', 6); + dayMap.put ('Sunday', 7); + // Get the day name using .format('EEEE'); - + String dayName = dt.format('EEEE'); + // Get the day number from the map using the day name - + Integer dayNumber = dayMap.get(dayName); + // Return the result as a string - return null; // Replace null with the variable you used to store the result + return String.valueOf (dayNumber); // Replace null with the variable you used to store the result } - - + + /** * Question 10 * Calculate the difference between the years of two dates @@ -212,38 +274,48 @@ public with sharing class ClassesObjectsMethods { * @return The a positive number years between the two dates, or null if either date is null. */ public static Integer calculateYearDifference(Date d1, Date d2) { - + //check for null first. + if (d1 == null || d2 == null) { + return null; + } // Subtract the difference in years - - return null; // Replace null with the variable you used to store the result + Integer yearDifference = Math.abs(d1.year() - d2.year()); //Math.abs() returns the absolute value and removes the negative sign. + + return yearDifference; // Replace null with the variable you used to store the result } - + /** * Question 11 - * The Book class represents a book in a library. + * The Book class represents a book in a library. * Each Book object has a title and an author, and methods to return these details. * This class can be used in the context of a library management system, bookstore, etc. * where you need to manipulate and manage book information. */ public class Book { - // Declare three public instance variables - title, author, pages + // Declare three public instance variables - title, author, pages. Instance variable is a variable that belongs to each object you create from the class. Each object has its own copy of the instance variable. // title // author // pages - + public String title; + public String author; + public Integer pages; + // Book constructor to initialize the title and author - public Book() { + public Book(String title, String author) { // Initialize the title and author + this.title = title; + this.author = author; } - + // Method that returns the details of the book public String getBookDetails() { // return A string containing the details of the book in the format "Title: , Author: <author>" - return null; // Replace null with the variable you used to store the result + String bookDetails = 'Title: ' + this.title + ', Author: ' + this.author; + return bookDetails; // Replace null with the variable you used to store the result } } - + /** * Question 12 * Create a Book object and returns the details of the book. @@ -252,13 +324,15 @@ public with sharing class ClassesObjectsMethods { */ public static String createAndGetBookDetails() { // Create a Book object with title "A Brief History of Time" and author "Stephen Hawking" - + Book myBook = new Book ('A Brief History of Time', 'Stephen Hawking'); + // Call the getBookDetails method on the book object to get the details of the book - + String bookDetails = myBook.getBookDetails(); + // Return the details of the book - return null; // Replace null with the variable you used to store the result + return bookDetails; // Replace null with the variable you used to store the result } - + /** * Question 13 * Create and update two Book objects and returns the books. @@ -270,21 +344,27 @@ public with sharing class ClassesObjectsMethods { */ public static List<Book> generateBookList(Book myBook1) { // Create a list of books - + List<Book> bookList = new List<Book>(); + // Update the title and author of myBook1 - + myBook1.title = 'Harry Potter and the Chamber of Secrets'; + myBook1.author = 'J.K. Rowling'; // Update the pages for myBook1 to 352 - + myBook1.pages = 352; + // Create a new Book object with title "A Brief History of Time" and author "Stephen Hawking" - + Book myBook2 = new Book('A Brief History of Time', 'Stephen Hawking'); // Update the pages for A Brief History of Time to 256 - + myBook2.pages = 256; + // Add the book to the list + bookList.add(myBook1); + bookList.add(myBook2); - return null; // Replace null with the variable you used to store the result + return bookList; // Replace null with the variable you used to store the result } - - + + /** * Question 14 * The Person class represents a person. @@ -294,43 +374,70 @@ public with sharing class ClassesObjectsMethods { */ public class Person { // Declare private two instance variables - (TEXT) name and (Number) age - + private String name; + private Integer age; // Constructor to initialize the name and age - - // Method introduceYourself that returns the details of the person - // Return a string in the format "Hello, my name is <name> and I am <age> years old." + public Person(String name, Integer age) { + this.name = name; + this.age = age; + } + + // Method introduceYourself that returns the details of the person + public String introduceYourself () { + // Return a string in the format "Hello, my name is <name> and I am <age> years old." + return 'Hello, my name is ' + this.name + ' and I am ' + String.valueOf(this.age) + ' years old.'; //<= "string.valueOf(this.age)" is type conversion. + } // For example, introduceYourself() should return a string like "Hello, my name is John Doe and I am 28 years old." - + // Getter method that returns the name of the person - + public String getName() { + return this.name; + } + // Getter method that returns the age of the person - + public Integer getAge() { + return this.age; + } + // Setter method that sets the name of the person - + public void setName(String name) { + this.name = name; + } + // Setter method that sets the age of the person + public void setAge(Integer age) { + this.age = age; + } } - + /** * Question 15 * Create a Person object and returns the details of the person. * For example, personDetails() should return a list like ["Hello, my name is John Doe and I am 28 years old.", "John Doe", "28"]. * @return A string containing the details of the person. */ - + public static List<String> personDetails() { List<String> results = new List<String>(); // Create a new instance of Person class + Person person = new Person ('John Doe', 28); + // Name the person 'John Doe' and set the age to 28 + person.setName('John Doe'); + person.setAge(28); // Add the details of the person using the introduceYourself method + results.add(person.introduceYourself()); // Get the name of the person using the getter method and add it to the list - + results.add(person.getName()); + // Get the age of the person using the getter method and add it to the list + results.add(String.valueOf(person.getAge())); - return null; // Replace null with the variable you used to store the result + return results; // Replace null with the variable you used to store the result } - + /** * Question 16 * Create a Person object with the provided name and age. @@ -340,33 +447,37 @@ public with sharing class ClassesObjectsMethods { */ public static Person createPerson(String name, Integer age) { // Create a new instance of the Person class using the provided name and age + Person newPerson = new Person(name, age); // Return the new instance of the Person class - return null; // Replace null with the variable you used to store the result + return newPerson; // Replace null with the variable you used to store the result } - + /** * Question 17 * Create a method that constructs multiple Person objects. * You are to create a new Person object for each name in the provided List<String> of names, - * using the same age for all Person objects. The method should return a List<Person> of all the Person objects created. + * using the same age for all Person objects. The method should return a List<Person> of all the Person objects created. * @param names A list of names. * @param age The age to be set for all the Person objects. * @return A list of new Person objects. */ public static List<Person> createMultiplePersons(List<String> names, Integer age) { + List<Person> people = new List<Person>(); // Loop through each name in the provided list of names - // Create a new Person object for each name - - // Add the new Person object to the list of Person objects - - + for (String name : names) { + // Create a new Person object for each name + Person newPerson = new Person(name, age); + people.add(newPerson); + } + // Add the new Person object to the list of Person objects // Return the list of Person objects - return null; // Replace null with the variable you used to store the result - } - - + return people; // Replace null with the variable you used to store the result. Remember to keep the return statement outside of the loop. + } + + + /** * Question 18 * Compare two Person objects based on their ages. @@ -378,6 +489,10 @@ public with sharing class ClassesObjectsMethods { * @return The Person object of the older person. */ public static Person getOlderPerson(Person person1, Person person2) { - return null; // Replace null with the variable you used to store the result + if (person1.getAge() >= person2.getAge()) { + return person1; + }else { + return person2; // Replace null with the variable you used to store the result + } } } \ No newline at end of file From 2515a463c5896ff842f9bb83656d87dc7351f5bd Mon Sep 17 00:00:00 2001 From: cathancock <cat.hancock082703@yahoo.com> Date: Wed, 1 Jul 2026 19:06:42 -0400 Subject: [PATCH 3/3] Recommitting to attempt to resolve feedback scratchorg error. --- force-app/main/default/classes/ClassesObjectsMethods.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/main/default/classes/ClassesObjectsMethods.cls b/force-app/main/default/classes/ClassesObjectsMethods.cls index 5473d78..57a9272 100644 --- a/force-app/main/default/classes/ClassesObjectsMethods.cls +++ b/force-app/main/default/classes/ClassesObjectsMethods.cls @@ -486,7 +486,7 @@ public with sharing class ClassesObjectsMethods { * * @param person1 The first Person object. * @param person2 The second Person object. - * @return The Person object of the older person. + * @return The Person object of the older person. Adding extra comment for new commit... */ public static Person getOlderPerson(Person person1, Person person2) { if (person1.getAge() >= person2.getAge()) {