6.31 LAB: Flip a coin

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

6.31 LAB: Flip a coin

Post by answerhappygod »

6.31 LAB: Flip a coin
6 31 Lab Flip A Coin 1
6 31 Lab Flip A Coin 1 (80.03 KiB) Viewed 73 times
6.31 LAB: Flip a coin Instructor note: : GOOD ADVICE: Watch out for white space Test your code. Test it again. Define a method named coinFlip that takes a Random object and returns "Heads" or "Tails" according to a random value 1 or 0. Assume the value 1 represents "Heads and represents Tails". Then, write a main program that reads the desired number of coin flips as an input, calls method coinFlipo) repeatedly according to the number of coin flips, and outputs the results. Assume the input is a value greater than 0. Ex: If the random object is created with a seed value of 2 and the input is 3 the output is. Heads Tails Ileads Note: For testing purposes, a Random object is created in the main() method using a pseudo-random number generator with a fixed seed value. The program uses a seed value of 2 during development, but when submitted a different seed value may be used for each test case. The program must define and call the following method: public static String coinFlip(Random rand) 30bobby LAB ACTIVITY 6.31.1: LAB: Flip a coin 0/10 LabProgram.java Load default template 1 import java.util.Scanner; 2 import java.util.Random; 3 A public class LabProgram 5 6 /* Define your method here 2 8 8 public static void main(String[] args) { 9 Scanner scor - new Scanner(System.in); 19 Random rand - new Random(2); // Seed used in develop mode 11 // Add more variables as needed 12 13 /* Type your code here. 14 3 15) 16 9 Develop mode Submit mode Run your program as often as you'd like, before submitting for grading, Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box Enter program input (optional) 3 Run program Input (from above) - LabProgram.java (Your program) Output (shown below)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply