Problem 6

Letter to Someone

Write a program that displays a name and address on the screen as if it were a letter. Your output should look something like that below.

Since this will be uploaded to GitHub, do NOT use your personal information.

As always, create folder for this problem in the pbd-solutions directory.

$/.../pbd-solutions/06$ java LetterToSomeone

+---------------------------------------------------------+
|                                                    #### |
|                                                    #### |
|                                                    #### |
|                                                         |
|                                                         |
|                              Bill Gates                 |
|                              1 Microsoft Way            |
|                              Redmond, WA 98104          |
|                                                         |
+---------------------------------------------------------+

Frequently-Asked Questions

Does my letter have to look exactly like yours?

No, but it does have to look roughly like a letter, including the box around the outside and the stamp.

Do I use my real address?

NO!!!

How to I get a | to show up on the screen?

The | character is called a “pipe”. Assuming you are using a normal US keyboard, it is Shift + backslash (\). The backslash key is usually located between the Backspace and Enter keys.

Why doesn’t my letter line up when I run the program?!? Everything looks perfect in the code!

You probably used a mixture of tabs and spaces between the quotes in your println() statements. Many text editors / IDEs will only move the cursor 4 spaces when you press TAB. But when your program runs, any tabs embedded inside the quotes will take up 8 spaces, not 4. If you delete ALL the tabs between the quotes and replace them with spaces, things should look the same in your code and when you run the program.


◄ 5: Comments and Slashes 7: Your Initials ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.