Write a program that demonstrates the coin class

Assignment Help Computer Engineering
Reference no: EM13322705

Write a Java class named Coin. The Coin class should have the following field:

A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up.

The Coin class should have the following methods:

A no-argument constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly. [note: constructors are described in the early part of Chapter 11 of the Farrell book]

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 times. 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.

Reference no: EM13322705

Questions Cloud

Explain strongest reducing agent to weakest reducing agent : Given the hypothetical redox reactions involving substances A, B, and C: A + B+ g? A+ + B C + A+ g? C+ + A B + C+ g? no reaction What is the arrangement of the substances in their order from strongest reducing agent to weakest reducing agent
Design a to perform various matrix operations : Design a to perform various matrix operations. class A matrix is a set of numbers arranged in rows and columns. Therefore, every element of a matrix has a row position and a column position.
Calculate the change in length of the aluminum rod : A straight rod consists of a 2cm long piece of aluminum attached to a 3cm long piece of steel. calculate the change in length of the aluminum rod
Calculate the power input to the pump in kw : A 60 MW Rankine steam power cycle in Iceland uses reheat. The system is comprised of a single adiabatic pump, a boiler using geothermal energy, two adiabatic turbine stages and a condenser.
Write a program that demonstrates the coin class : 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.
Explain what is the final volume of the gas : The pressure of 6.0 L of an ideal gas in a flexible container is decreased to one-sixth of its original pressure, and its absolute temperature is decreased to one-forth of the original. What is the final volume of the gas
Create a class called song that has 3 attributes-title : Create a class called Song that has 3 attributes-title, artist, and price (which will be entered later as either 0.99 or 1.49). It should contain 2 constructor methods, all the necessary set and get methods, and a "toString" method that prints the..
What is the tension in the right cable : A 200-N beam is held horizontally by a vertical steel cable at each end. The beam is 18 m long. A 650-N box sits 3.0 m from the left end. What is the tension in the right cable
Advertising to children in school is morally objectionable : Advertising to children in school is morally objectionable to many people. Some of the reasons used to criticize the practice include the following: First, children at school are a captive audience. Second, children are not yet autonomous and a..

Reviews

Write a Review

Computer Engineering Questions & Answers

  How do css, javascript, or framesets come into play

Visit two sites that you feel meet qualifications of being "usable", and two that you find confusing, How do Javascript, CSS, or Framesets come into play on the sites.

  Developing the fsm diagram

Develop the FSM diagram showing how to identify a DOS-like file name containing an optional leading drive letter and a colon, followed by an optional backslash, zero or more directory name isolated by the backslashes.

  How inheritance improve a programmer''s productivity

define the difference between robustness and reliability and how design affects these characteristics.

  Compare the role and impact of a computing technology

information on understanding an inner workings of digital downloads and digital compression. I need to follow the outline below. I'm running out of information. I need to compare the role and impact of a computing technology on society.

  Explain some benefits of code citations

What is an instance of how one would re-use a C# object. At the same time, one must avoid code plagiarism. How does one reconcile the two? Describe some benefits of code citations in addition to avoiding plagiarism.

  Organizational information processing theory

What is organizational information processing theory, explain its concepts and what do you meant by creating the slack resource, make the lateral relationship.

  Define contrasting two major enterprise resource planning

recognize two major segments ERP systems. define contrasting two major Enterprise Resource Planning.

  Find out the length of the string

In the absence of three consecutive erroneous input attempts, your user should have the opportunity to continue running the program until directly deciding to terminate.

  Describe where sequential file processing might be used

Develop an case to illustrate your definition. (The example does not have to be as elaborate. Just a record with a simple explanation)

  Make use the vb.net programming to write statement

imagine that the array has a data type of frmMdiChildList having subscripts from 0 to 9. Configure the forms so that they appear as child forms of the MDI parent form named frmMdiParent.

  Which is true of today''s cios

The traditional set of IS responsibilities includes all of the following except.

  Write down a big-inteter calculator program

note down a big-inteter calculator program that allows the user to enter two large integers and the operation to be performed and that calls the appropriate function to carry out the designated operation.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd