COS126 Conditionals and Loops Activity - Section 1.31. Look up Program 1.2.5. RandomInt.java (p.33)Web Exercise 1.3.1. Write RollDie.java to simulate the toss of a fair six-sided die.Use casting to get a random integer, as in RandomInt.java./***/public class RollDie {public static void main(String[] args) {// how many sides on the die?_____________ SIDES = ___________________;// roll should be 1 through SIDESint roll = ________________________________________________________// print result___________________________________________________________________}}2. Look up Program 1.3.1. Flip.java (p.49)Web Exercise 1.3.2. Write RollLoadedDie.java to simulate the toss of a loaded six-sided die where where the 1, 2, 3, 4, and 5 appear with probability 1/8 and 6 appearswith probablity 3/8. Use if - else as in Flip.java (but there will be more choices)./***/public class RollLoadedDie {public static void main(String[] args) {// generate random double in the range [0.0, 1.0)_________________ r = __________________________________________;// compute the roll with desired probabilitiesint roll;if (________________________________________) roll = _______;else if (else if (else if (else if (else// print the roll}}13. Find PowersOfTwo.java in your book or on the website. It uses a while loop. Rewriteit to use a for loop. (answer on p. 57)/***/public class PowersOfTwo {public static void main(String[] args) {}}4. Write FiniteSum.java which takes one integer command-line argument N, and printsthe sum (1 + 2 + ... + N ). (Answer on p.57)/****/public class FiniteSum {public static void main(String[] args) {}}• Recommended Exercises: 1.3.7, 1.3.13,
View Full Document