Java Reference
In-Depth Information
12. Write a Java program that generates the following output. Use static methods to show structure and eliminate redun-
dancy in your solution.
_______
/ \
/ \
\ /
\_______/
_______
/ \
/ \
\ /
\_______/
+-------+
_______
/ \
/ \
| STOP |
\ /
\_______/
+-------+
13. Write a program that prints the following line of output 1000 times:
A ll work and no play makes Jack a dull boy.
You should not write a program that uses 1000 lines of source code; use methods to shorten the program. What is the
shortest program you can write that will produce the 1000 lines of output, using only the material from this chapter?
Programming Projects
1. Write a program to spell out MISSISSIPPI using block letters like the following (one per line):
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
2. Sometimes we write similar letters to different people. For example, you might write to your parents to tell them
about your classes and your friends and to ask for money; you might write to a friend about your love life, your
classes, and your hobbies; and you might write to your brother about your hobbies and your friends and to ask for
money. Write a program that prints similar letters such as these to three people of your choice. Each letter should
have at least one paragraph in common with each of the other letters. Your main program should have three method
calls, one for each of the people to whom you are writing. Try to isolate repeated tasks into methods.
3. Write a program that produces as output the lyrics of the song, “There Was an Old Lady.” Use methods for each
verse and the refrain. Here are the song's complete lyrics:
There was an old lady who swallowed a fly.
I don't know why she swallowed that fly,
Perhaps she'll die.
Search WWH ::




Custom Search