|
Hour 24: Making Your Knowledge Add Up
NOTES AND CORRECTIONS
- One solution to your boss Ashley Judd's calculator assignment is contained
in MiniCalc.java, MiniCalc.class,
and CalcApplet.class (along
with the two source files below). If you're working on this project and
you've reached a sticking point, the following hints offer some guidance:
SOURCE FILES
READER QUESTIONS
- Question: In the MiniCalc solution, I am a little confused with how
part of the program works. More specifically, I would like to know more
about the following lines:
if (newText.indexOf(".") == -1)
newText += ".";
- Answer: The
indexOf() method of the String
class searches for text inside the string -- such as a "."
character in the above example. If the text is found, indexOf()
returns an integer indicating the position where it was found. If it is not
found, indexOf() returns -1. The above lines make sure that
there isn't a "." character in newText before adding one to
the string. You can find out more from Sun's official documentation for the java.lang.String
class.
ACTIVITIES
|