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.
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...
Related questions
Question
Use java and use proper code indentation.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY