6.
• Examine FlipCoin.java:
– Execute the following program and observe the random numberthat chance generated.
– If chance < 0.5, record the result as “heads”; else recordthe result as “tails.”
– Repeat this many time.
import java.util.Random;
public class FlipCoin {
public static void main(String[] args) {
// 50% chance heads,50% chance tails
Random rand = newRandom();
double chance =rand.nextDouble();
System.out.println(chance);
}
}
Exercise 2
• Examine RockPaperScissor.java.
– Perform the following:
– Simulate the RockPaperScissor game by generating a randominteger number in the range of 0 to 3.
– Compare the generated number with the following numbers:
– if number=0 : “rock”
– if number=1: “paper”
– if number=2: “scissors”
– Record the result
PayPal Gateway not configured
PayPal Gateway not configured