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 ?

Console X Sullivan3.java
<terminated > Sullivan4_2 [Java Application]
Error: Main method not found in class sullivan4. Sullivan4_2, please define the main method as:
Sullivan3_3.java
Test.java
Sullivan4_1.java
Sullivan4_2.java
XX AS
C:\Users\shari\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.4.v20221004-1257\jre\bin\javaw.exe (Nov 6, 2022, 3:16:26 PM - 3:16:27 PM) [pid: 368]
public static void main(String[] args)
or a JavaFX application class must extend javafx.application. Application
Transcribed Image Text:Console X Sullivan3.java <terminated > Sullivan4_2 [Java Application] Error: Main method not found in class sullivan4. Sullivan4_2, please define the main method as: Sullivan3_3.java Test.java Sullivan4_1.java Sullivan4_2.java XX AS C:\Users\shari\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.4.v20221004-1257\jre\bin\javaw.exe (Nov 6, 2022, 3:16:26 PM - 3:16:27 PM) [pid: 368] public static void main(String[] args) or a JavaFX application class must extend javafx.application. Application
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
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