diff --git a/force-app/main/default/classes/VariablesDataTypesOperators.cls b/force-app/main/default/classes/VariablesDataTypesOperators.cls index a212d74..8569b86 100644 --- a/force-app/main/default/classes/VariablesDataTypesOperators.cls +++ b/force-app/main/default/classes/VariablesDataTypesOperators.cls @@ -32,7 +32,12 @@ public with sharing class VariablesDataTypesOperators { * @return The sum of the two numbers, or null if either number is null. */ public static Integer addition(Integer a, Integer b) { - return null; // Replace null with the variable you used to store the result + if(a == null || b == null){ + return null; + } + + Integer sum = a + b; + return sum; // Replace null with the variable you used to store the result } /** @@ -44,7 +49,8 @@ public with sharing class VariablesDataTypesOperators { * @return The difference between the two numbers. */ public static Integer subtraction(Integer a, Integer b) { - return null; // Replace null with the variable you used to store the result + Integer difference = a -b; + return difference; // Replace null with the variable you used to store the result } /** @@ -56,7 +62,8 @@ public with sharing class VariablesDataTypesOperators { * @return The product of the two numbers. */ public static Integer multiplication(Integer a, Integer b) { - return null; // Replace null with the variable you used to store the result + Integer product = a * b; + return product; // Replace null with the variable you used to store the result } /** @@ -69,7 +76,12 @@ public with sharing class VariablesDataTypesOperators { * @return The quotient of the division, or 0 if the denominator is zero. */ public static Double division(Double a, Double b) { - return null; // Replace null with the variable you used to store the result + if(b == 0){ + return 0; + } + + Double quotient = a / b; + return quotient; // Replace null with the variable you used to store the result } /** @@ -83,7 +95,8 @@ public with sharing class VariablesDataTypesOperators { * @return True if the number is even, False otherwise. */ public static Boolean isEven(Integer num) { - return null; // Replace null with the variable you used to store the result + Boolean isEven = Math.mod(num, 2) == 0; + return isEven; // Replace null with the variable you used to store the result } /** @@ -94,7 +107,8 @@ public with sharing class VariablesDataTypesOperators { * @return true if the number is positive, false otherwise. */ public static Boolean isPositive(Integer num) { - return null; // Replace null with the variable you used to store the result + Boolean isPositive = num > 0; + return isPositive; // Replace null with the variable you used to store the result } /** @@ -106,7 +120,8 @@ public with sharing class VariablesDataTypesOperators { * @return The concatenated string. */ public static String concatenateStrings(String str1, String str2) { - return null; // Replace null with the variable you used to store the result + String jointString = str1 + str2; + return jointString; // Replace null with the variable you used to store the result } /** @@ -121,7 +136,8 @@ public with sharing class VariablesDataTypesOperators { * @return The complete sentence as a single String. */ public static String createSentence(String noun, String verb, String endingPunctuation) { - return null; // Replace null with the variable you used to store the result + String completeSentence = 'The ' + noun + ' is ' + verb + endingPunctuation; + return completeSentence; // Replace null with the variable you used to store the result } /** @@ -134,7 +150,8 @@ public with sharing class VariablesDataTypesOperators { * @return True if the date is in the past, False otherwise. */ public static Boolean isDateInPast(Date dt) { - return null; // Replace null with the variable you used to store the result + Boolean dateInThePast = dt < System.Today(); + return dateInThePast; // Replace null with the variable you used to store the result } /** @@ -147,7 +164,8 @@ public with sharing class VariablesDataTypesOperators { * @return True if the date is today or in the future, False otherwise. */ public static Boolean isDateTodayOrFuture(Date dt) { - return null; // Replace null with the variable you used to store the result + Boolean dateIsTodayOrLater = dt >= System.Today(); + return dateIsTodayOrLater; // Replace null with the variable you used to store the result } /** @@ -159,10 +177,11 @@ public with sharing class VariablesDataTypesOperators { * @param minutes The number of minutes. * @return The number of milliseconds equivalent to the given number of minutes. */ - Integer MILLISECONDS_PER_MINUTE = null; // Make this value a constant + Static Integer MILLISECONDS_PER_MINUTE = 60000; // Make this value a constant + public static Integer convertMinutesToMilliseconds(Integer minutes) { - Integer milliseconds; - return null; // Replace null with the variable you used to store the result + Integer millisecond = minutes * MILLISECONDS_PER_MINUTE; + return millisecond; // Replace null with the variable you used to store the result } /** @@ -176,7 +195,8 @@ public with sharing class VariablesDataTypesOperators { * @return The average of the three numbers. */ public static Double averageOfThreeNumbers(Integer a, Integer b, Integer c) { - return null; // Replace null with the variable you used to store the result + Double mean = (a + b + c) / 3; + return mean; // Replace null with the variable you used to store the result } /** @@ -191,10 +211,10 @@ public with sharing class VariablesDataTypesOperators { */ public static Integer adjustOrderOfOperations1(Integer a, Integer b, Integer c) { // Add parentheses around the addition operation so that it is performed before multiplication - Integer result = a + b * c; + Integer result = (a + b) * c; // Return the result - 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 } /** @@ -206,8 +226,8 @@ public with sharing class VariablesDataTypesOperators { // Add parentheses in the below expression to change the result. // The result of the expression as it is right now is 43. // You should add parentheses so that the result of the expression becomes 8. - Integer answer = 48 - 15 + 5 * 2; - return null; // Replace null with the variable you used to store the result + Integer answer = 48 - (15 + 5) * 2; + return answer; // Replace null with the variable you used to store the result } /** @@ -226,9 +246,9 @@ public with sharing class VariablesDataTypesOperators { */ public static Double complexOrderOfOperations(Integer a, Integer b, Integer c, Integer d, Integer e) { // Add parentheses around the multiplication and subtraction operations so that they are performed before division and addition - Double result = a * b - c / (Double) d + e; + Double result = (a * b - c) / (Double) d + e; - 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 } /** @@ -242,8 +262,10 @@ public with sharing class VariablesDataTypesOperators { final Double SUBTRACT_FACTOR = 32.0; final Double MULTIPLY_FACTOR = 5.0; final Double DIVIDE_FACTOR = 9.0; + + Double celciusTemp = (fahrenheit - SUBTRACT_FACTOR) * (MULTIPLY_FACTOR / DIVIDE_FACTOR); - return null; // Replace null with the variable you used to store the result + return celciusTemp; // Replace null with the variable you used to store the result } @@ -259,11 +281,11 @@ public with sharing class VariablesDataTypesOperators { */ public static Integer performDivisionAndCast(Double a, Double b) { // Perform the division and cast (round down) off the result. - Double divisionResult = null; + Double divisionResult = a / b; // Write the code for type casting the divisionResult to an Integer - Integer roundedResult = null; - return null; // Replace null with the variable you used to store the result + Integer roundedResult = (Integer) divisionResult; + return roundedResult; // Replace null with the variable you used to store the result } /** @@ -277,7 +299,8 @@ public with sharing class VariablesDataTypesOperators { */ public static Decimal calculateWeeklyPaycheck(Decimal hourlyRate, Double numberOfHours) { // Calculate the weekly paycheck using the formula: rate multiplied by hours - return null; // Replace null with the variable you used to store the result + Decimal weeklyPaycheck = hourlyRate * numberOfHours; + return weeklyPaycheck; // Replace null with the variable you used to store the result } /** @@ -291,7 +314,8 @@ public with sharing class VariablesDataTypesOperators { * @return A Decimal representing the monthly paycheck. */ public static Decimal calculateMonthlyPaycheck(Decimal hourlyRate, Double numberOfHours) { - return null; // Replace null with the variable you used to store the result + Decimal monthlyPaycheck = hourlyRate * numberOfHours * 4; + return monthlyPaycheck; // Replace null with the variable you used to store the result } /** @@ -305,6 +329,7 @@ public with sharing class VariablesDataTypesOperators { * @return The total cost after applying the sales tax. */ public static Decimal calculateTotalCost(Decimal pricePerUnit, Integer numberOfUnits, Decimal salesTaxRate) { - return null; // Replace null with the variable you used to store the result + Decimal totalCostWithTax = (pricePerUnit * numberOfUnits) * (1 + salesTaxRate); + return totalCostWithTax; // Replace null with the variable you used to store the result } }