234 Methods Chapter 6 6.13 (Affordable web design) Write an application

234 Methods Chapter 6 6.13 Write an application that simulates coin tossing. Let the program toss the coin each time the user presses the Toss button. Count the number of times each side of the coin appears. Display the results. The program should call a separate method Flip that takes no arguments and returns false for tails and true for heads. [Note: If the program realistically simulates the coin tossing, each side of the coin should appear approximately half of the time.] 6.14 Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use the Next method from an object of type Random to produce two positive one-digit integers. It should display a question in the status bar, such as How much is 6 times 7? The student should then type the answer into a TextBox. Your program should check the student s answer. If it is correct, draw the string “Verygood!” in a read-only TextBox, then ask another multiplication question. If the answer is wrong, draw the string “No. Pleasetry again.” in the same read-only TextBox, then let the student try the same question again until the student finally gets it right. A separate method should be used to generate each new question. This method should be called once when the program begins execution and each time the user answers the question correctly. 6.15 (Towers of Hanoi) Every budding computer scientist must grapple with certain classic problems and the Towers of Hanoi (Fig. 6.20) is one of the most famous. Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another. The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by decreasing size. The priests are attempting to move the stack from this peg to a second peg under the constraints that exactly one disk is moved at a time, and at no time may a larger disk be placed above a smaller disk. A third peg is available for temporarily holding disks. Supposedly, the world will end when the priests complete their task, so there is little incentive for us to facilitate their efforts. Let us assume that the priests are attempting to move the disks from peg 1 to peg 3. We wish to develop an algorithm that will print the precise sequence of peg-to-peg disk transfers. If we were to approach this problem with conventional methods, we would find ourselves hopelessly knotted up in managing the disks. However, if we attack the problem with recursion in mind, it becomes tractable. Moving n disks can be viewed in terms of moving only n 1 disks (and hence, the recursion) as follows: Fig. 6.20 The Towers of Hanoi for the case with four disks.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Leave a Reply