Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WelcomeMessage {
- /**
- * Program: WelcomeMessage.java
- * Purpose: Display custom welcome message in command prompt window
- * Creator: Chris Clarke
- * Created: 12.08.2014
- */
- public static void main(String[] args) {
- final int BOX_WIDTH = 80; // width of welcome message box = DOS command prompt width
- final int BOX_HEIGHT = 9; // height of welcome message box
- Scanner scan = new Scanner(System.in);
- String message;
- char symbol = '#';
- int leadingSpaces, trailingSpaces;
- do {
- System.out.print("Enter your welcome message: ");
- message = scan.nextLine();
- if (message.length() > BOX_WIDTH-4) {
- System.out.println("Message too long!");
- } // end if
- if (message.length() < 1) {
- System.out.println("No message!");
- } // end if
- } while (message.length() > BOX_WIDTH-4 || message.length() < 1);
- System.out.println("\n");
- leadingSpaces = (BOX_WIDTH / 2) - (message.length() / 2);
- trailingSpaces = (BOX_WIDTH - (leadingSpaces+message.length()));
- for (int row = 0; row<BOX_HEIGHT; row++) {
- if (row==0 || row==BOX_HEIGHT-1) { // first and last rows
- for (int col=0; col<BOX_WIDTH; col++) {
- System.out.print(symbol);
- } // end for col
- } else if (row==BOX_HEIGHT/2) { // middle row
- System.out.print(symbol);
- for (int sp = 1; sp<leadingSpaces; sp++) {
- System.out.print(" ");
- } // end for
- System.out.print(message);
- for (int sp = 1; sp<trailingSpaces; sp++) {
- System.out.print(" ");
- } // end for
- System.out.print(symbol);
- } else { // other rows
- System.out.print(symbol);
- for (int sp = 1; sp<BOX_WIDTH-1; sp++) {
- System.out.print(" ");
- } // end for
- System.out.print(symbol);
- } // end if row
- } // end for row
- } // end main()
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement