Created
March 24, 2017 16:06
-
-
Save leihuagh/5c68c985ae1fe102b45eb6edce6e7cfe to your computer and use it in GitHub Desktop.
Java Project: Envelope (4) - Envelope with Sender and Receiver Info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package envelope; | |
| public class EnvelopeWithContents { | |
| public static void main(String[] args) { | |
| int row = 12, column = 50; | |
| for (int i=0; i<row; i++) { | |
| switch(i) { | |
| case 0: | |
| case 11: | |
| printRow(column, '+', '-'); | |
| break; | |
| case 1: | |
| printContentWith(column, '|', ' ', "Lei Hua", 1); | |
| break; | |
| case 2: | |
| printContentWith(column, '|', ' ', "419 Bedford Street", 1); | |
| break; | |
| case 3: | |
| printContentWith(column, '|', ' ', "Lexington, MA 02420", 1); | |
| break; | |
| case 6: | |
| printContentWith(column, '|', ' ', "Jack Ngo", 24); | |
| break; | |
| case 7: | |
| printContentWith(column, '|', ' ', "419 Bedford Street", 24); | |
| break; | |
| case 8: | |
| printContentWith(column, '|', ' ', "Lexington, MA 02420", 24); | |
| break; | |
| default: | |
| printRow(column, '|', ' '); | |
| break; | |
| } | |
| } | |
| } | |
| private static void printContentWith(int column, char side, char general, String content, int start) { | |
| char[] row = new char[column]; | |
| int i = 0; | |
| for (i=0; i<column; i++) { | |
| switch(i) { | |
| case 0: | |
| case 49: | |
| row[i] = side; | |
| break; | |
| default: | |
| row[i] = general; | |
| break; | |
| } | |
| } | |
| char[] contentCharArray = content.toCharArray(); | |
| int max = contentCharArray.length; | |
| i = start; | |
| for (int j = 0; j<max; j++) { | |
| row[i] = contentCharArray[j]; | |
| i++; | |
| } | |
| System.out.println(String.valueOf(row)); | |
| } | |
| private static void printRow(int column, char side, char general) { | |
| char[] row = new char[column]; | |
| int last = column - 1; | |
| for (int i=0; i<column; i++) { | |
| if ((i==0) || (i==last)) { | |
| row[i] = side; | |
| } | |
| else { | |
| row[i] = general; | |
| } | |
| } | |
| System.out.println(String.valueOf(row)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment