Reading: Chapter 4, sections 4.4-4.5
computeSum()
that
receives two integers from its calling program and returns the
sum of those two integers back to the calling program. Use the computeSequenceSum()
method from the text as a model. You should be able to compute
1+1 by calling your method using the invocation computeSum(1,
1)
and get the correct answer (which happens to be 2 by the
way!).
lfmi()
that receives
three String arguments (a first, middle and last name) and
returns a string representing the name in "last, first
middle initial" format. i.e. lmfi("Kinsey",
"Henrietta", "Callen")
should return the string
"Callen, Kinsey H." Note that you can use the charAt()
method
to get the first character in a string.
computeSum()
, drawSquare()
and lfmi()
methods you wrote above and then use
driver programs to run your new methods on your test cases.
Consider the boundary cases (e.g., adding 0, negative or really
huge numbers; drawing squares at the edge or off the canvas;
rendering a name with a one-character middle name). Testing is an
art, a destructive art perhaps, for which some people have
particular gifts - perhaps you’re one of those people.
computeSequenceSum()
. Be
devious; good test engineers do the unexpected; they push the
limits; they find errors in code that others considered
unbreakable.
Consider the following program. Study it first before running it and try to predict what it will print on the console:
int a = 1; void setup() { int a = 2; println(a); }
draw()
method to the end of the given program:
What happens now (and why!)?void draw() { println(a); stop(); }
int i = 2;
statement from
the setup()
method. What happens now?
By the way, this is a terrible piece of code that we’ve written for demonstration purposes only.
Consider the following code segment. Study it first before running it and try to predict what it will print out:
int a = 1; void setup() { int a = 2; println(a); myMethod(a); println(a); } void myMethod(int a) { a = a + 1; println(a); }
a
refer to in this program? And what is
the scope of each?
myMethod(a)
, does
the execution of the method change the value of the a
declared in setup()
?
This also is a terrible piece of code that we’ve written for demonstration purposes only. (-: We forbid you to ever write code that looks like this! :-)