Skip to content

Commit b884d9a

Browse files
committed
Updated return types and to align with method return types and included logic to align with comments and annotations.
1 parent 96254b6 commit b884d9a

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

force-app/main/default/classes/VariablesDataTypesOperators.cls

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public with sharing class VariablesDataTypesOperators {
3232
* @return The sum of the two numbers, or null if either number is null.
3333
*/
3434
public static Integer addition(Integer a, Integer b) {
35-
return null; // Replace null with the variable you used to store the result
35+
if(a == null || b == null){
36+
return null;
37+
}
38+
39+
Integer sum = a + b;
40+
return sum; // Replace null with the variable you used to store the result
3641
}
3742

3843
/**
@@ -44,7 +49,8 @@ public with sharing class VariablesDataTypesOperators {
4449
* @return The difference between the two numbers.
4550
*/
4651
public static Integer subtraction(Integer a, Integer b) {
47-
return null; // Replace null with the variable you used to store the result
52+
Integer difference = a -b;
53+
return difference; // Replace null with the variable you used to store the result
4854
}
4955

5056
/**
@@ -56,7 +62,8 @@ public with sharing class VariablesDataTypesOperators {
5662
* @return The product of the two numbers.
5763
*/
5864
public static Integer multiplication(Integer a, Integer b) {
59-
return null; // Replace null with the variable you used to store the result
65+
Integer product = a * b;
66+
return product; // Replace null with the variable you used to store the result
6067
}
6168

6269
/**
@@ -69,7 +76,12 @@ public with sharing class VariablesDataTypesOperators {
6976
* @return The quotient of the division, or 0 if the denominator is zero.
7077
*/
7178
public static Double division(Double a, Double b) {
72-
return null; // Replace null with the variable you used to store the result
79+
if(b == 0){
80+
return 0;
81+
}
82+
83+
Double quotient = a / b;
84+
return quotient; // Replace null with the variable you used to store the result
7385
}
7486

7587
/**
@@ -83,7 +95,8 @@ public with sharing class VariablesDataTypesOperators {
8395
* @return True if the number is even, False otherwise.
8496
*/
8597
public static Boolean isEven(Integer num) {
86-
return null; // Replace null with the variable you used to store the result
98+
Boolean isEven = Math.mod(num, 2) == 0;
99+
return isEven; // Replace null with the variable you used to store the result
87100
}
88101

89102
/**
@@ -94,7 +107,8 @@ public with sharing class VariablesDataTypesOperators {
94107
* @return true if the number is positive, false otherwise.
95108
*/
96109
public static Boolean isPositive(Integer num) {
97-
return null; // Replace null with the variable you used to store the result
110+
Boolean isPositive = num > 0;
111+
return isPositive; // Replace null with the variable you used to store the result
98112
}
99113

100114
/**
@@ -106,7 +120,8 @@ public with sharing class VariablesDataTypesOperators {
106120
* @return The concatenated string.
107121
*/
108122
public static String concatenateStrings(String str1, String str2) {
109-
return null; // Replace null with the variable you used to store the result
123+
String jointString = str1 + str2;
124+
return jointString; // Replace null with the variable you used to store the result
110125
}
111126

112127
/**
@@ -121,7 +136,8 @@ public with sharing class VariablesDataTypesOperators {
121136
* @return The complete sentence as a single String.
122137
*/
123138
public static String createSentence(String noun, String verb, String endingPunctuation) {
124-
return null; // Replace null with the variable you used to store the result
139+
String completeSentence = 'The ' + noun + ' is ' + verb + endingPunctuation;
140+
return completeSentence; // Replace null with the variable you used to store the result
125141
}
126142

127143
/**
@@ -134,7 +150,8 @@ public with sharing class VariablesDataTypesOperators {
134150
* @return True if the date is in the past, False otherwise.
135151
*/
136152
public static Boolean isDateInPast(Date dt) {
137-
return null; // Replace null with the variable you used to store the result
153+
Boolean dateInThePast = dt < System.Today();
154+
return dateInThePast; // Replace null with the variable you used to store the result
138155
}
139156

140157
/**
@@ -147,7 +164,8 @@ public with sharing class VariablesDataTypesOperators {
147164
* @return True if the date is today or in the future, False otherwise.
148165
*/
149166
public static Boolean isDateTodayOrFuture(Date dt) {
150-
return null; // Replace null with the variable you used to store the result
167+
Boolean dateIsTodayOrLater = dt >= System.Today();
168+
return dateIsTodayOrLater; // Replace null with the variable you used to store the result
151169
}
152170

153171
/**
@@ -159,10 +177,11 @@ public with sharing class VariablesDataTypesOperators {
159177
* @param minutes The number of minutes.
160178
* @return The number of milliseconds equivalent to the given number of minutes.
161179
*/
162-
Integer MILLISECONDS_PER_MINUTE = null; // Make this value a constant
180+
Static Integer MILLISECONDS_PER_MINUTE = 60000; // Make this value a constant
181+
163182
public static Integer convertMinutesToMilliseconds(Integer minutes) {
164-
Integer milliseconds;
165-
return null; // Replace null with the variable you used to store the result
183+
Integer millisecond = minutes * MILLISECONDS_PER_MINUTE;
184+
return millisecond; // Replace null with the variable you used to store the result
166185
}
167186

168187
/**
@@ -176,7 +195,8 @@ public with sharing class VariablesDataTypesOperators {
176195
* @return The average of the three numbers.
177196
*/
178197
public static Double averageOfThreeNumbers(Integer a, Integer b, Integer c) {
179-
return null; // Replace null with the variable you used to store the result
198+
Double mean = (a + b + c) / 3;
199+
return mean; // Replace null with the variable you used to store the result
180200
}
181201

182202
/**
@@ -191,10 +211,10 @@ public with sharing class VariablesDataTypesOperators {
191211
*/
192212
public static Integer adjustOrderOfOperations1(Integer a, Integer b, Integer c) {
193213
// Add parentheses around the addition operation so that it is performed before multiplication
194-
Integer result = a + b * c;
214+
Integer result = (a + b) * c;
195215

196216
// Return the result
197-
return null; // Replace null with the variable you used to store the result
217+
return result; // Replace null with the variable you used to store the result
198218
}
199219

200220
/**
@@ -206,8 +226,8 @@ public with sharing class VariablesDataTypesOperators {
206226
// Add parentheses in the below expression to change the result.
207227
// The result of the expression as it is right now is 43.
208228
// You should add parentheses so that the result of the expression becomes 8.
209-
Integer answer = 48 - 15 + 5 * 2;
210-
return null; // Replace null with the variable you used to store the result
229+
Integer answer = 48 - (15 + 5) * 2;
230+
return answer; // Replace null with the variable you used to store the result
211231
}
212232

213233
/**
@@ -226,9 +246,9 @@ public with sharing class VariablesDataTypesOperators {
226246
*/
227247
public static Double complexOrderOfOperations(Integer a, Integer b, Integer c, Integer d, Integer e) {
228248
// Add parentheses around the multiplication and subtraction operations so that they are performed before division and addition
229-
Double result = a * b - c / (Double) d + e;
249+
Double result = (a * b - c) / (Double) d + e;
230250

231-
return null; // Replace null with the variable you used to store the result
251+
return result; // Replace null with the variable you used to store the result
232252
}
233253

234254
/**
@@ -242,8 +262,10 @@ public with sharing class VariablesDataTypesOperators {
242262
final Double SUBTRACT_FACTOR = 32.0;
243263
final Double MULTIPLY_FACTOR = 5.0;
244264
final Double DIVIDE_FACTOR = 9.0;
265+
266+
Double celciusTemp = (fahrenheit - SUBTRACT_FACTOR) * (MULTIPLY_FACTOR / DIVIDE_FACTOR);
245267

246-
return null; // Replace null with the variable you used to store the result
268+
return celciusTemp; // Replace null with the variable you used to store the result
247269
}
248270

249271

@@ -259,11 +281,11 @@ public with sharing class VariablesDataTypesOperators {
259281
*/
260282
public static Integer performDivisionAndCast(Double a, Double b) {
261283
// Perform the division and cast (round down) off the result.
262-
Double divisionResult = null;
284+
Double divisionResult = a / b;
263285

264286
// Write the code for type casting the divisionResult to an Integer
265-
Integer roundedResult = null;
266-
return null; // Replace null with the variable you used to store the result
287+
Integer roundedResult = (Integer) divisionResult;
288+
return roundedResult; // Replace null with the variable you used to store the result
267289
}
268290

269291
/**
@@ -277,7 +299,8 @@ public with sharing class VariablesDataTypesOperators {
277299
*/
278300
public static Decimal calculateWeeklyPaycheck(Decimal hourlyRate, Double numberOfHours) {
279301
// Calculate the weekly paycheck using the formula: rate multiplied by hours
280-
return null; // Replace null with the variable you used to store the result
302+
Decimal weeklyPaycheck = hourlyRate * numberOfHours;
303+
return weeklyPaycheck; // Replace null with the variable you used to store the result
281304
}
282305

283306
/**
@@ -291,7 +314,8 @@ public with sharing class VariablesDataTypesOperators {
291314
* @return A Decimal representing the monthly paycheck.
292315
*/
293316
public static Decimal calculateMonthlyPaycheck(Decimal hourlyRate, Double numberOfHours) {
294-
return null; // Replace null with the variable you used to store the result
317+
Decimal monthlyPaycheck = hourlyRate * numberOfHours * 4;
318+
return monthlyPaycheck; // Replace null with the variable you used to store the result
295319
}
296320

297321
/**
@@ -305,6 +329,7 @@ public with sharing class VariablesDataTypesOperators {
305329
* @return The total cost after applying the sales tax.
306330
*/
307331
public static Decimal calculateTotalCost(Decimal pricePerUnit, Integer numberOfUnits, Decimal salesTaxRate) {
308-
return null; // Replace null with the variable you used to store the result
332+
Decimal totalCostWithTax = (pricePerUnit * numberOfUnits) * (1 + salesTaxRate);
333+
return totalCostWithTax; // Replace null with the variable you used to store the result
309334
}
310335
}

0 commit comments

Comments
 (0)