Create a class called Coin, which will represent a possibly loaded coin. Each coin is characterized by its face(HEADS or TAILS) and by its headProb, the probability that a toss of the coin will change the face value to HEADS. Implement methods to simulate a toss, change the headProb, and to print its current facevalue. Test the functionality in the main method of a separate class called Coinsimulation by simulating three, differently loaded, coins over 10 tosses. Implementation steps: 1) Create the Coin class (don't include the main method). Create the Coinsimulation class (with a main method). 2) Declare the instance variables that will represent the face of the coin and its head probability. Call these variables face (String) and headProb (double). Instance variables are declared outside of any method and do not include the static keyword. Declare them as private, so they cannot be directly accessible. This will prevent any inadvertent errors in using this class. Each Coin object instance will have its own version of these face and headProb variables. 3) Define the constructor method for the class. The constructor method is a non-static method that has the exact same name as the class, but no return type. This method is called automatically whenever we create a new object instance of this class. It should take as input one double value which will be used to initialize the headProb instance variable. The constructor should also initialize the face instance variable by calling the toss method (see below). 4) Define the toss method, which should change the face value of this object (the one on which the method is called) to "HEADS", with probability of headProb. See ex. 6 from lab #2 for implementation details. The method should be declared as public, but not static, without a return value. 5) Define the toString method. This non-static method is called automatically whenever we pass the object reference of this class to the println method. This will allow us to automatically print a textual representation of the Coin object. This method must have no input parameters and be public. It should return the value of the instance variable face. 6) Write code in the main method of the CoinSimulation class that tests the functionality of your implementation by creating three Coin objects, then loop for ten iterations. In each iteration, "toss" each of the Coin objects and display their face value.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Use java and use proper code indentation.
**Exercise 5 (Coin Class)**

**Objective:** Create a class called `Coin`, representing a potentially loaded coin. Each coin is characterized by its `face` (HEADS or TAILS) and `headProb`, the probability of a toss resulting in HEADS. Implement methods for:

- Simulating a toss
- Changing the `headProb`
- Printing the current face value

Test functionality in the `main` method of a separate class `CoinSimulation` by simulating three coins over 10 tosses.

**Implementation Steps:**

1. **Create Classes:**
   - Create the `Coin` class (exclude `main` method).
   - Create the `CoinSimulation` class with a `main` method.

2. **Declare Instance Variables:**
   - Variables: `face` (String) and `headProb` (double).
   - Ensure instance variables are `private` for encapsulation. Each `Coin` instance will maintain its own `face` and `headProb`.

3. **Define Constructor:**
   - A non-static method with no return type, same name as the class.
   - Initializes the `headProb` with a `double` input and sets `face` by invoking `toss`.

4. **Define `toss` Method:**
   - Changes `face` to "HEADS" based on `headProb`.
   - Public, non-static, no return value.

5. **Define `toString` Method:**
   - Automatically provides a textual representation of the `Coin` object (`face` value).
   - Public, no parameters.

6. **Main Method in `CoinSimulation`:**
   - Test implementation by creating three `Coin` objects.
   - Loop for ten iterations to toss each `Coin` and display the `face`.
Transcribed Image Text:**Exercise 5 (Coin Class)** **Objective:** Create a class called `Coin`, representing a potentially loaded coin. Each coin is characterized by its `face` (HEADS or TAILS) and `headProb`, the probability of a toss resulting in HEADS. Implement methods for: - Simulating a toss - Changing the `headProb` - Printing the current face value Test functionality in the `main` method of a separate class `CoinSimulation` by simulating three coins over 10 tosses. **Implementation Steps:** 1. **Create Classes:** - Create the `Coin` class (exclude `main` method). - Create the `CoinSimulation` class with a `main` method. 2. **Declare Instance Variables:** - Variables: `face` (String) and `headProb` (double). - Ensure instance variables are `private` for encapsulation. Each `Coin` instance will maintain its own `face` and `headProb`. 3. **Define Constructor:** - A non-static method with no return type, same name as the class. - Initializes the `headProb` with a `double` input and sets `face` by invoking `toss`. 4. **Define `toss` Method:** - Changes `face` to "HEADS" based on `headProb`. - Public, non-static, no return value. 5. **Define `toString` Method:** - Automatically provides a textual representation of the `Coin` object (`face` value). - Public, no parameters. 6. **Main Method in `CoinSimulation`:** - Test implementation by creating three `Coin` objects. - Loop for ten iterations to toss each `Coin` and display the `face`.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY