}
System.out.println(“result “ + result);
}
}
class
Puzzle4b
{
int ivar;
public int
doStuff(int
factor
) {
if (ivar > 100) {
return
ivar * factor;
} else {
return
ivar * (5 - factor);
}
}
}
Output
Answer to the 5-minute mystery...
Jai knew that Buchanan wasn’t the sharpest pencil in the box. When Jai
heard
Buchanan talk about his code, Buchanan never mentioned his
instance variables. Jai suspected that while Buchanan
did in fact handle his
methods correctly, he failed to
mark his instance variables
private
. That
slip up could have easily cost Leveler thousands.
Extra-Strength Methods
Let’s put some muscle in our methods.
We dabbled with variables,
played
with a few objects, and wrote a little code. But we were weak. We need
more tools. Like
operators
. We need
more operators so we can do
something a little more interesting than, say,
bark
. And
loops
. We need
loops, but what’s with the wimpy
while
loops? We need
Do'stlaringiz bilan baham: