|
|
||
| You are here: | ||
|
This is quite a long Applet and involves many Classes which have been developed in previous pages. It will repay some study. If you can modify the Applet successfully you will learn a lot.
Nothing new here, just a bit longer than usual.
Call the method that generates a question.
Notice that the main logical structure is put here, the actual processing parts are handled by separate methods for convenience.
Answered is a flag or sentinel - an SL mastery aspect.
Use a try block because the BinaryTextFiedl will throw an exception if the String typed into it is not a valid binary byte.
We can then use our custom exception messages.
We've used a method here because it will make it easier to extend the example to Binary Decimal conversions or mixtures of both.
Start with an empty String
Generate random number 0 - 499 3/5 of the numbers will be 1's on average.
Math.random returns a long primitive in the range 0 >= x > 1.0 (int) is a cast used to convert a long to an int.
|
import java.awt.*; /** Exercise: The quiz needs improvement in the following areas:
Related: [ Java Home | previous:Inheritance ] |
Applet that runs a binary conversion quiz. You have to enter a valid , 8-bit binary byte . For example , if you are asked to convert 2, enter 00000010, not just 10. |
|
|
|||
|
Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified: May 31, 2009 |