Except where otherwise noted, the contents of this document are Copyright 2013 Stuart Reges and Marty Stepp.
lab document created by Marty Stepp, Stuart Reges and Whitaker Brand
Goals for today:
Recall the syntax for writing a static method. Methods are useful for representing a program's structure and capturing common code to avoid redundancy:
public static void name() { statements; }
Example:
public static void song() { System.out.println("This is the song that never ends,"); System.out.println("Yes, it goes on and on, my friends."); }
Spikey
Spikey
that produces the following output:
\/ \\// \\\/// ///\\\ //\\ /\
(Use only the material we have learned so far. You can check your output on the Output Comparison Tool web page.)
Lanterns
Lanterns
that produces the
following output. Use static methods to capture structure and remove
redundancy. (Check your output on the Comparison Tool.)
***** ********* ************* ***** ********* ************* * | | | | | * ************* ***** ********* ************* ***** ********* ************* ***** * | | | | | * * | | | | | * ***** *****
M M IIIII SSSSS PPPPPP MM MM I S S P P M M M M I S P P M M M I SSSSS PPPPPP M M I S P M M I S S P M M IIIII SSSSS P
The giant letters should flow vertically. Use methods to avoid redundancy when the same giant letter appears multiple times in your name. (Use only the material from Chapter 1.)
FightSong
Go, team, go! You can do it. Go, team, go! You can do it. You're the best, In the West. Go, team, go! You can do it. Go, team, go! You can do it. You're the best, in the West. Go, team, go! You can do it. Go, team, go! You can do it.
The following program produces the output at left, but it has poor structure and redundancy. Download it and open it in jGRASP, then add at least two static methods.
continued on the next slide...
FightSong
, cont'dGo, team, go! You can do it.
Go, team, go! You can do it. You're the best, In the West. Go, team, go! You can do it.
Go, team, go! You can do it. You're the best, In the West. Go, team, go! You can do it.
Go, team, go! You can do it.
Did you choose your methods well? Avoid the following pitfalls:
println
statement occur more than once in your code?
println
statements in the main
method?
main
method a good summary of the overall program? (If main
is only 1-2 lines long, it is not a good summary.)
Compare your method choice with your neighbor's. Discuss any different decisions you made and ask a TA if you have questions about them.