I need help fixing a java program that meets its requirements described in the image, over the code below.                            import java.util.Scanner; import java.util.Random; public class LabProgram {    public static String coinFlip(Random rand) {       int randomValue = rand.nextInt(2); // Generates a random value 0 or 1       if (randomValue == 1) {          return "Heads";       } else {          return "Tails";       }    }    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);       Random rand = new Random(2); // Seed used in develop mode       int numFlips = scnr.nextInt(); // Read the desired number of coin flips              for (int i = 0; i < numFlips; i++) {          String result = coinFlip(rand); // Call coinFlip method          System.out.print(result + " "); // Output the result       }    } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help fixing a java program that meets its requirements described in the image, over the code below.                         
  import java.util.Scanner;
import java.util.Random;

public class LabProgram {

   public static String coinFlip(Random rand) {
      int randomValue = rand.nextInt(2); // Generates a random value 0 or 1
      if (randomValue == 1) {
         return "Heads";
      } else {
         return "Tails";
      }
   }

   public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);
      Random rand = new Random(2); // Seed used in develop mode

      int numFlips = scnr.nextInt(); // Read the desired number of coin flips
      
      for (int i = 0; i < numFlips; i++) {
         String result = coinFlip(rand); // Call coinFlip method
         System.out.print(result + " "); // Output the result
      }
   }
}

**Transcription of Coin Flip Simulation Results**

**Test 1:**

- **Input:** 3
- **Your Output:** Heads, Tails, Heads
- **Expected Output:** Heads, Tails, Heads

**Unit Test 2:**

- **Function:** `coinFlip()` with input 1 (seed value is 15)
- **Test Feedback:** 
  - The test uses a pseudo-random number generator with a seed value of 15.
  - `coinFlip()` with input 1 correctly returned: Heads

**Unit Test 3:**

- **Function:** `coinFlip()` with input 5 (seed value is 1024)
- **Test Feedback:** 
  - The test uses a pseudo-random number generator with a seed value of 1024.
  - `coinFlip()` with input 5 correctly returned: 
    - Heads
    - Tails
    - Heads
    - Heads
    - Heads
Transcribed Image Text:**Transcription of Coin Flip Simulation Results** **Test 1:** - **Input:** 3 - **Your Output:** Heads, Tails, Heads - **Expected Output:** Heads, Tails, Heads **Unit Test 2:** - **Function:** `coinFlip()` with input 1 (seed value is 15) - **Test Feedback:** - The test uses a pseudo-random number generator with a seed value of 15. - `coinFlip()` with input 1 correctly returned: Heads **Unit Test 3:** - **Function:** `coinFlip()` with input 5 (seed value is 1024) - **Test Feedback:** - The test uses a pseudo-random number generator with a seed value of 1024. - `coinFlip()` with input 5 correctly returned: - Heads - Tails - Heads - Heads - Heads
Expert Solution
Step 1: Providing algorithm of code.


1. Input: rand (a Random object for generating random numbers)
2. Generate a random integer randomValue using rand.nextInt(2), which results in 0 or 1.
3. If randomValue is equal to 1:
4. Return "Heads".
5. Else:
6. Return "Tails".

7. Create a Scanner object scnr to read input from the user.

8. Create a Random object rand with a seed value (e.g., 2).
9. Read the desired number of coin flips (numFlips) from the user.

10. For i from 0 to numFlips - 1:
 11.  Call the coinFlip method with rand to get the result of a coin flip and store it in the variable result.
12. Output the result with a newline character by using System.out.println(result).
13. End of the loop.

Execution starts with main().

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education