17. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field: • A String named sideUp. The sideUp field will hold either "heads" ing the side of the coin that is facing up. or "tails" indicat- The Coin class should have the following methods: . A no-arg constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly. . A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ("heads" or "tails") and sets the sideUp field accordingly. • A method named getSideUp that returns the value of the sideUp field. Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 20 tímes. Each time the coin is tossed, display the side that is facing up. The program should keep count of the number of times heads is facing up and the number of times tails is facing up, and display those values after the loop finishes.

Question

# 17 and Java Program

17. Coin Toss Simulator
Write a class named Coin. The Coin class should have the following field:
• A String named sideUp. The sideUp field will hold either "heads"
ing the side of the coin that is facing up.
or "tails" indicat-
The Coin class should have the following methods:
. A no-arg constructor that randomly determines the side of the coin that is facing up
("heads" or "tails") and initializes the sideUp field accordingly.
. A void method named toss that simulates the tossing of the coin. When the toss
method is called, it randomly determines the side of the coin that is facing up ("heads"
or "tails") and sets the sideUp field accordingly.
• A method named getSideUp that returns the value of the sideUp field.
Write a program that demonstrates the Coin class. The program should create an instance
of the class and display the side that is initially facing up. Then, use a loop to toss the coin
20 tímes. Each time the coin is tossed, display the side that is facing up. The program should
keep count of the number of times heads is facing up and the number of times tails is facing
up, and display those values after the loop finishes.
Expand
Transcribed Image Text

17. Coin Toss Simulator Write a class named Coin. The Coin class should have the following field: • A String named sideUp. The sideUp field will hold either "heads" ing the side of the coin that is facing up. or "tails" indicat- The Coin class should have the following methods: . A no-arg constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly. . A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ("heads" or "tails") and sets the sideUp field accordingly. • A method named getSideUp that returns the value of the sideUp field. Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 20 tímes. Each time the coin is tossed, display the side that is facing up. The program should keep count of the number of times heads is facing up and the number of times tails is facing up, and display those values after the loop finishes.

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Consider the bank database of Figure 5.21. Write an SQL trigger to carry outthe following action: On...

A:  On delete of an account, for each customer-owner of theaccount, check if the owner has any remainin...

Q: Write and test a MIPS assembly language program that reads in a positiveinteger using the SPIM syste...

A: .datastr:  .asciiz "Please input some number."str0:  .asciiz "Zero "str1:  .asciiz "One "str2:  .asc...

Q: 5. Convert the following Statements into Predicate logic statements: a. Everyone is a CS major b. So...

A: Predicate logic is an extension of propositional logic.Allows this structure of fact and sentence to...

Q: Do all please. (a) Provide an example of a constructor method being overridden? (b) Describe Dynami...

A: a. Constructor method overriding is not possible. Overriding occurs when the method with the same na...

Q: Each level k in a binary tree contains a. 2^k+1 b. 2k c. 2^k - 1   ...Python / Data Structures

A: Each level K in a binary tree contains 2k-1.

Q: Draw the graph of a differential Manchester scheme using the data stream 01100101

A: Actually, data stream is used to transmit and receives the data.

Q: "chmod" is a well known command line utility, that is used for manually managing the access and perm...

A: After execution of the given command: The command “chmod” is used for changing the access permissio...

Q: How many squares are drawn if foo(0,0,5,2) is called?

A: Given, drawSquare (double x, double y, double halfLen) draws a square with each side of length 2×hal...

Q: Explain why incremental development is the most effective approach for developing business software ...

A: Actually, system engineering is a field of engineering that focus on how to design.

Q: What are the quality assurance practices used for preparing components models?

A: Component models are used to define certain properties satisfied by components, and other methods. F...

Q: The language is Java

A: Introduction of the Program: The Java Program takes the decimal number from the user as input then t...

Q: need this done in c++

A: The program with the nested if decision structure will be created as follows: Create two Boolean va...

Q: a. Write a Boolean Product of Sum (POS) expression for this truth table b. then simplify that expres...

A: Click to see the answer

Q: Can you write this in Java code and add comments

A: Please find the answer below :

Q: What is the difference between a min heap and a max heap?

A: Step 1:- Heap is a non-linear data structure. The data structure is defined as a way to arrange the ...

Q: . If R1 = 0xEF00DE12, R2 = 0x0456123F, R5 = 4, R6 = 28; Find the values of the destination registe...

A: Shifters :- 1.Logical Shift Left(LSL):-  In 32 bit register, it shift left for specified number of ...

Q: C++

A: The while loop gets executed until the condition specified in while loop executes to false while(con...

Q: A class called Book is designed (as shown in the class diagram) to model a book written by one autho...

A: Actually, java is a object oriented programming language.

Q: Anthony, Shirley and Jennifer belong to the Dancer Club. Every member of the Dancer Club is either a...

A: Click to see the answer

Q: In this lab, you create a programmer-defined class and then use it in a C++ program. The program sho...

A: using namespace std;class Rectangle{   public:      void setWidth(double);      void setLength(doubl...

Q: What is the difference between industrial spying and the gathering of competitive intelligence? Is t...

A: Click to see the answer

Q: PYTHON!!!!! A group of statisticians at a local college has asked you to create a set of functions t...

A: Program Approach: First creating three function for calculating mean, mode and median. Median funct...

Q: Explain the term TSR? State reason why there is a need to make a program TSR? What code you have to ...

A: Answer in step2  

Q: Make a class Person, with instance variable name, age, and gender. Make a class Employee inheritfrom...

A: class Person{ String name; int age; String gender;  public Person(String name, int age, String gende...

Q: Create a class named Pet (similar to the one discussed in this chapter), which has the following pro...

A: The main objective of the program is to create a class called Pet and its test application in window...

Q: 1. Write a program that opens an output file with the filename my_name.txt, Writes your name to the ...

A: Note: Here you didn't mention any programming language So We are solving this problem in C++ Program...

Q: What is the outcome if foo(0,0) is called?

A: PROGRAM: //Defining class class Main {        //Defining foo()   public static int foo(int a, int b)...

Q: Suppose you are given a relation grade_points(grade, points) that provides a conversion from letter ...

A:  Search the student's total grades of ID 12345, All of the student's courses. Choose sum (* points) ...

Q: Plaz solve

A: Module Module1     Sub Main()        Dim num1 As Integer         Console.Write("Enter your Age: ")  ...

Q: THE PROGRAM SHOULD BE WRITTEN USING C++    Checkpoints    Absolutely no arrays or structures. The pr...

A: Objective: This program computes the monthly budget and total cost of the water bill for a family. P...

Q: Suppose that longitude is assigned to the first column of an array and latitude is assigned to the s...

A: import java.util.Scanner; public class Main{ public static void main(String[] args)  {     Scanner s...

Q: What are the 8 steps of the operation of a CPU? For a given binary number 1101111 what is it in deci...

A: The 8 steps of the operation of a CPU are as follows: A sequence of instructions is stored in memor...

Q: Design an algorithm that produces a binary expression tree from a given postfix expression. You can ...

A: Algorithm for the given question is in Step 2.

Q: Question 5 Discuss Five steps that organizations should take into account for a successful software ...

A: Building business cases They take into consideration their Pain point. Come up with a solution Cond...

Q: python: a function that counts the number of occurrences of given character in a given string. For e...

A: def count(c, s):     n = 0     c = c.lower() # Converting the character to be searched to lower case...

Q: The Land Transportation Franchising andRegulatory Board wanted to implement a newjeepney fare matrix...

A: Conditional statement is the ability to test a variable against a value and act in one way if the co...

Q: PrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will n...

A: A number is said to be prime number if it has factors 1 and itself A number is said to be factor if ...

Q: Define the following terms: a) Starvation    b) Aging    c) I/O- bound process   d) Deadlock

A: a.) Starvation : Starvation or indefinite blocking is phenomenon associated with the Priority schedu...

Q: What are the short words that are used in assembly language called?

A: in assembly language, each instruction can be written as a short word, called a mnemonic each mnemon...

Q: 11 Compute the binary representation of the following mips instruction:      a) addi $s3, $t3, 7    ...

A:     instruction: addi $s3, $t3, 7 Binary : 00100001011100110000000000000111  

Q: Explain the difference between an extent, a segment, and a table. Give an example of how the three a...

A: ANS: - Extent: - It is the logical unit of the database storage space allocation made up of a numb...

Q: Why would you choose (static and dynamic) one over another

A: Step 1:-We are talking about static and dynamic regarding the computer.The computer is an electronic...

Q: The administrators of Tiny College are so pleased with your design and implementation of their stude...

A: Entity Relational (ER) diagram: The following figure illustrates the ER diagram for given business r...