Write a program that simulates tossing a coin.  //Prompt the user for how many times to toss the coin.  //Code a method with no parameters that randomly returns either the String "heads"or the string "tails". //Call this method in main as many times as requested and report the results.

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

// Sharissa Sullivan 
// COP 2250
// Chapter 6 Method
// Method with No permeters 
package sullivan4;

import java.util.*;

public class Sullivan4_2 {    
// Define a method for the flip of a coin - heads or tails 
    class main {
        public static String toss()
        {
// Create Random Number object for heads/tails toss 
        Random randomNumber = new Random();
// Generate a random number: heads = 0, tails = 1 
        int flip = randomNumber.nextInt(2);
// If statement to flag flips with heads or tails         
        if (flip == 0)
        return "heads";
        else
        return "tails";
        }
// Define the main method 
        public main(final String[] args) {  //   public static void main(String[] args)
// Create Scanner object 
        Scanner userinput = new Scanner(System.in);
// Prompt the user to enter how many times they want the coin to be tossed
        System.out.println("How many times should I toss the coin ?");
// Scan the value the user enters 
        int scan = userinput.nextInt();

// Declare variables 
        int heads = 0;
        int tails =0;
        int count;
// Create loop for coin toss 
        for (count = 1; count <= scan ; count++) 
        {
// toss the coin 
        String result = toss();
// If statement for toss = heads add 1 to heads count 
        if (result.equals("heads"))
        heads++;
// Else add 1 to tails count 
        else 
        tails++;
    }
// Print the totals of heads and tails 
        System.out.println( "Results of "+ scan + "tosses. Heads:" + heads + ",Tails:" + tails);
    }
    
}
}

 

 

//Write a program that simulates tossing a coin. 
//Prompt the user for how many times to toss the coin. 
//Code a method with no parameters that randomly returns either the String "heads"or the string "tails".
//Call this method in main as many times as requested and report the results. See Example outputs below.

 

***I am getting an error message saying ...Error: Main method not found in class sullivan4.Sullivan4_2, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application  *********

 

 

*****What is wrong with my code ?

### Error Message in Java Console

**Error Message:**

```
Error: Main method not found in class sullivan4.Sullivan4_2, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
```

**Explanation:**

This error message indicates that the Java Virtual Machine (JVM) could not find the `main` method in the specified class `sullivan4.Sullivan4_2`. In Java applications, the `main` method serves as the entry point of the application. It must be defined exactly as `public static void main(String[] args)` for a standard Java program.

Alternatively, if this is meant to be a JavaFX application, the class should extend `javafx.application.Application`.

**Steps to Resolve:**

1. **Define the Main Method:**
   - If you're creating a console-based application, make sure the `main` method is correctly defined in your class:
     ```java
     public static void main(String[] args) {
         // Your code here
     }
     ```

2. **JavaFX Application:**
   - If this is a JavaFX application, ensure your class extends `javafx.application.Application` and includes the `start` method:
     ```java
     import javafx.application.Application;
     import javafx.stage.Stage;

     public class Sullivan4_2 extends Application {
         @Override
         public void start(Stage primaryStage) {
             // Your code here
         }

         public static void main(String[] args) {
             launch(args);
         }
     }
     ```

Make the necessary changes to your class based on the type of application you intend to create. If this error persists, verify your classpath and confirm that you are running the correct Java file.
Transcribed Image Text:### Error Message in Java Console **Error Message:** ``` Error: Main method not found in class sullivan4.Sullivan4_2, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application ``` **Explanation:** This error message indicates that the Java Virtual Machine (JVM) could not find the `main` method in the specified class `sullivan4.Sullivan4_2`. In Java applications, the `main` method serves as the entry point of the application. It must be defined exactly as `public static void main(String[] args)` for a standard Java program. Alternatively, if this is meant to be a JavaFX application, the class should extend `javafx.application.Application`. **Steps to Resolve:** 1. **Define the Main Method:** - If you're creating a console-based application, make sure the `main` method is correctly defined in your class: ```java public static void main(String[] args) { // Your code here } ``` 2. **JavaFX Application:** - If this is a JavaFX application, ensure your class extends `javafx.application.Application` and includes the `start` method: ```java import javafx.application.Application; import javafx.stage.Stage; public class Sullivan4_2 extends Application { @Override public void start(Stage primaryStage) { // Your code here } public static void main(String[] args) { launch(args); } } ``` Make the necessary changes to your class based on the type of application you intend to create. If this error persists, verify your classpath and confirm that you are running the correct Java file.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
void method
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