|
@@ -1,3 +1,66 @@
|
1
|
1
|
# Saturday-Exercises
|
2
|
2
|
|
3
|
|
-some simpler exercises for IFs and loops.
|
|
3
|
+some simpler exercises for IFs and loops.
|
|
4
|
+
|
|
5
|
+# Happy 1st Saturday, Newbies!
|
|
6
|
+
|
|
7
|
+Yes, I am writing these on my phone, from I-70west in Ohio. No, I am not currently driving.
|
|
8
|
+
|
|
9
|
+Some extra (easier) exercises.
|
|
10
|
+
|
|
11
|
+Use them to practice writing both pseudo code and Java. Write each one in both Strive to feel good about the practice as you complete each one.
|
|
12
|
+
|
|
13
|
+I suggest you write them into a notebook or onto paper. Once, you written them all, go thru them and type them into this file. You can use “atom” for that.
|
|
14
|
+
|
|
15
|
+Then, if you’d like comments on your work, do a Pull Request and make the title of the PR “comments please”.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+## IFs
|
|
19
|
+
|
|
20
|
+Write an IF statement that checks “player1.isAlive()” and if that’s false, calls “displayGameOver(player1)”
|
|
21
|
+
|
|
22
|
+Write an IF statement that checks the “temperature(room)” and if that check is less than 70, calls “heatOn()” else calls “coolOn()”
|
|
23
|
+
|
|
24
|
+Write an IF statement that checks “outsideTemp()” is less than 50 AND “insideTemp()” is less than 62, calls “startAFire(fireplace1)”
|
|
25
|
+
|
|
26
|
+Write an IF statement that checks “fuelLevel” and if that check is less than 0.08, calls “refuel()”
|
|
27
|
+
|
|
28
|
+## Loops
|
|
29
|
+
|
|
30
|
+For each loop you write, print “Hello” on each loop iteration.
|
|
31
|
+
|
|
32
|
+Write a FOR loop that counts from 1 to 10.
|
|
33
|
+
|
|
34
|
+Write a FOR loop that makes 10 iterations, start at 21
|
|
35
|
+
|
|
36
|
+Write a FOR loop that counts down from 100 to 0
|
|
37
|
+
|
|
38
|
+Write a FOR loop from 0 to 32 by 2s
|
|
39
|
+
|
|
40
|
+Write a FOR loop from 1 to less than 5001 by 11s.
|
|
41
|
+
|
|
42
|
+Write a nested FOR loop(s), where one counts from 0 to less than 20 and the inner one counts from 0 to 4.
|
|
43
|
+
|
|
44
|
+Write a FOR loop that counts from 5 to 105. Put an IF statement inside the loop that checks the loop index counter and if it’s greater than 51, prints “Hello Zipcode” instead on “hello”
|
|
45
|
+
|
|
46
|
+Write a WHILE loop that checks “gps.currentLocation()” and if that is not equal to “Home” then and it calls “driveSomeMore()”. After the loop is done, print “Honey, I’m Home!”
|
|
47
|
+
|
|
48
|
+First set “highestScore” to 0. Then set “currentScore” to “game.nextScore()”. Then write a WHILE loop that checks “currentScore” is greater than “highestScore” and if it is, sets “highestScore” to “currentScore” and then sets “currentScore” to “game.nextScore()”.
|
|
49
|
+
|
|
50
|
+Rewrite the previous WHILE loop as a REPEAT..UNTIL loop. Notice how the “currentScore” variable usage is different.
|
|
51
|
+
|
|
52
|
+Write a WHILE loop that checks “server.isRunning()” and if true calls “waitFor(5)”
|
|
53
|
+After the loop, write an IF and check “server.isRunning()” is false, and if so, call “sendEmergencyText(“Help!”, admin.iPhoneNumber)” and also calls “tryServerRestart()”
|
|
54
|
+
|
|
55
|
+Declare an “int” i. Set i to 7. Write a WHILE loop that checks “i” is less than 50, and if it is, add 7 to “i”
|
|
56
|
+
|
|
57
|
+Given an array voteTallies[], write a FOR loop that prints out each value in the array.
|
|
58
|
+
|
|
59
|
+Given an array voteTallies[], write a WHILE loop that prints out each value in the array. You should declare and use an index “idx” to keep track of where you are.
|
|
60
|
+
|
|
61
|
+Ponder this: can all FOR loops be rewritten as WHILE loops?
|
|
62
|
+
|
|
63
|
+Ponder this: can all WHILE loops be rewritten as FOR loops?
|
|
64
|
+
|
|
65
|
+Set “yardNeedsMowed” to true. Write WHILE loop that checks for “isSummer()”. inside the loop, write an IF that checks “yardNeedsMowed” and if true calls “yellAtJunior(chores.mowLawn())”
|
|
66
|
+After loop, call “sendJuniorToSchool(onTime)”
|