Last active
November 4, 2025 08:33
-
-
Save JessWingerden/526fdc5cb751a5f8596eb647e49e7d9d to your computer and use it in GitHub Desktop.
Week 2 Homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CommentingOnCodeExercise { | |
| public static void cartValues() { | |
| //Declaring and Initialising a variable. Datatype = Integer. Variable name = CartValue and assigning the minimum number value of 50. | |
| Integer minimumCartValue = 50; | |
| // Declaring and Initialising the variables. | |
| Integer itemA = 10; | |
| Integer itemB = 20; | |
| Integer itemC = 45; | |
| // Calculating the assigned variables itemA + itemB = 30 | |
| Integer cartValue = itemA + itemB; | |
| //Formula calculating if the to either true of false based on 30 >= 50. In this instance, cartMinimumMet would be false. | |
| Boolean cartMinimumMet = cartValue >= minimumCartValue; | |
| //Printing out your variables to the debug log. Have we reached the minimum: false | |
| System.debug('Have we reached the minimum: ' + cartMinimumMet); | |
| //New calculation: cartValue (30) + itemC (45) | |
| cartValue = cartValue + itemC; | |
| //Formula calculating if the to either true of false based on 75 >= 50. In this instance, cartMinimumMet would be true. | |
| cartMinimumMet = cartValue >= minimumCartValue; | |
| //Printing out your variables to the debug log. How about now?: true | |
| System.debug('How about now? : ' + cartMinimumMet); | |
| } | |
| public static void conditionalsExercise() { | |
| Boolean result; | |
| //You do this part! | |
| // 1. Write a comparison statement that evaluates to false and assign the result to our result variable | |
| //Don't forget to maintain indentation! | |
| Integer totalValue = 75; | |
| Integer optionOne = 25; | |
| Integer optionTwo = 10; | |
| Integer optionThree = 3; | |
| Integer calcTotalValue = optionOne * optionTwo; | |
| // 2. Declare another boolean variable and write a comparison that evaluates to true, assign it to your variable | |
| Integer secondValue = 40; | |
| Integer choiceOne = 4; | |
| Integer choiceTwo = 23; | |
| Integer choiceThree = 10; | |
| Integer calcSecondValue = choiceOne * choiceThree; | |
| } | |
| public static void listsExercise() { | |
| //You do this part! | |
| //1. Declare a list of Strings called myStringList | |
| List<String> myStringList = new List <String>(); | |
| //2. Add three string values to your list and print it out in the debug log | |
| myStringList.add('Cake'); | |
| myStringList.add('Ice Cream'); | |
| myStringList.add('Fruit'); | |
| //3. Print out the third value in your list of strings using list indexing. | |
| System.debug('Value of 2 Index:' + myStringList[2]); | |
| //4. Declare a list of integers and add the values 1,2,3,4,5 all in one line | |
| List<Integer> step4FourIntegers = new List<Integer>{1,2,3,4,5}; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great job with the lists exercise and your comments! For the conditionals exercise, you just missed one of the steps to use the comparison operators and assign the value back to the boolean
resultvariable. Do you want to give this one another try after we review in class today?