Banner Learn programming Java

Lesson:

Arrays, Structures and Strings


Exercise:

Banner 19


Objetive:

Create a java program to imitate the basic Unix SysV "banner" utility, able to display big texts.


Code:

import java.util.*;
public class Main
{
	static void main(String[] args)
	{
		string[] esqueleto =  
        {  
            "         ###  ### ###  # #   ##### ###   #  ##     ###  ", 
            "         ###  ### ###  # #  #  #  ## #  #  #  #    ###  ", 
            "         ###   #   # ########  #   ### #    ##      #   ", 
            "          #            # #   #####    #    ###     #    ", 
            "                     #######   #  #  # ####   # #       ", 
            "         ###           # #  #  #  # #  # ##    #        ", 
            "         ###           # #   ##### #   ### #### #       ", 
            "   ##    ##                                            #", 
            "  #        #   #   #    #                             # ", 
            " #          #   # #     #                            #  ", 
            " #          # ####### #####   ###   #####           #   ", 
            " #          #   # #     #     ###           ###    #    ", 
            "  #        #   #   #    #      #            ###   #     ", 
            "   ##    ##                   #             ###  #      ", 
            "  ###     #    #####  ##### #      ####### ##### #######", 
            " #   #   ##   #     ##     ##    # #      #     ##    # ", 
            "#     # # #         #      ##    # #      #          #  ", 
            "#     #   #    #####  ##### #    # ###### ######    #   ", 
            "#     #   #   #            ########      ##     #  #    ", 
            " #   #    #   #      #     #     # #     ##     #  #    ", 
            "  ###   ##### ####### #####      #  #####  #####   #    ", 
            " #####  #####    #     ###      #           #     ##### ", 
            "#     ##     #  ###    ###     #             #   #     #", 
            "#     ##     #   #            #     #####     #        #", 
            " #####  ######         ###   #                 #     ## ", 
            "#     #      #   #     ###    #     #####     #     #   ", 
            "#     ##     #  ###     #      #             #          ", 
            " #####  #####    #     #        #           #       #   ", 
            " #####    #   ######  ##### ###### ############## ##### ", 
            "#     #  # #  #     ##     ##     ##      #      #     #", 
            "# ### # #   # #     ##      #     ##      #      #      ", 
            "# # # ##     ####### #      #     ######  #####  #  ####", 
            "# #### ########     ##      #     ##      #      #     #", 
            "#      #     ##     ##     ##     ##      #      #     #", 
            " ##### #     #######  ##### ###### ########       ##### ", 
            "#     #  ###        ##    # #      #     ##     ########", 
            "#     #   #         ##   #  #      ##   ####    ##     #", 
            "#     #   #         ##  #   #      # # # ## #   ##     #", 
            "#######   #         ####    #      #  #  ##  #  ##     #", 
            "#     #   #   #     ##  #   #      #     ##   # ##     #", 
            "#     #   #   #     ##   #  #      #     ##    ###     #", 
            "#     #  ###   ##### #    # ########     ##     ########", 
            "######  ##### ######  ##### ########     ##     ##     #", 
            "#     ##     ##     ##     #   #   #     ##     ##  #  #", 
            "#     ##     ##     ##         #   #     ##     ##  #  #", 
            "###### #     #######  #####    #   #     ##     ##  #  #", 
            "#      #   # ##   #        #   #   #     # #   # #  #  #", 
            "#      #    # #    # #     #   #   #     #  # #  #  #  #", 
            "#       #### ##     # #####    #    #####    #    ## ## ", 
            "#     ##     ######## ##### #       #####    #          ", 
            " #   #  #   #      #  #      #          #   # #         ", 
            "  # #    # #      #   #       #         #  #   #        ", 
            "   #      #      #    #        #        #               ", 
            "  # #     #     #     #         #       #               ", 
            " #   #    #    #      #          #      #               ", 
            "#     #   #   ####### #####       # #####        #######", 
            "  ###                                                   ", 
            "  ###     ##   #####   ####  #####  ###### ######  #### ", 
            "   #     #  #  #    # #    # #    # #      #      #    #", 
            "        ###### #    # #      #    # #      #      #  ###", 
            "    #   #    # #####  #      #    # #####  #####  #     ", 
            "        #    # #    # #    # #    # #      #      #    #", 
            "        #    # #####   ####  #####  ###### #       #### ", 
            "                                                        ", 
            " #    #    #        # #    # #      #    # #    #  #### ", 
            " #    #    #        # #   #  #      ##  ## ##   # #    #", 
            " ######    #        # ####   #      # ## # # #  # #    #", 
            " #    #    #        # #  #   #      #    # #  # # #    #", 
            " #    #    #   #    # #   #  #      #    # #   ## #    #", 
            " #    #    #    ####  #    # ###### #    # #    #  #### ", 
            "                                                        ", 
            " #####   ####  #####   ####   ##### #    # #    # #    #", 
            " #    # #    # #    # #         #   #    # #    # #    #", 
            " #    # #    # #    #  ####     #   #    # #    # #    #", 
            " #####  #  # # #####       #    #   #    # #    # # ## #", 
            " #      #   #  #   #  #    #    #   #    #  #  #  ##  ##", 
            " #       ### # #    #  ####     #    ####    ##   #    #", 
            "                       ###     #     ###   ##    # # # #", 
            " #    #  #   # ###### #        #        # #  #  # # # # ", 
            "  #  #    # #      #  #        #        #     ## # # # #", 
            "   ##      #      #  ##                 ##        # # # ", 
            "   ##      #     #    #        #        #        # # # #", 
            "  #  #     #    #     #        #        #         # # # ", 
            " #    #    #   ######  ###     #     ###         # # # #"
    };


	System.out.print("Tell a string:");
	String Entry = new Scanner(System.in).nextLine();

	byte j = 1;
	char Letra;
	int[] CodigoAscii = new int[Entry.length()];

	for (int i = 0; i < Entry.length(); i++)
	{
		Letra = (char)Entry.substring(i, i + j);
		CodigoAscii[i] = (int)Letra;
	}

	int AnchoLetras = 7,AltoLetra = 7;
	int numeroAscii = 32;
	int countLineas = 0, countLetras = 0,countPosiciones = 0;
	boolean LetraEncontrada = false;
	String[] cadena = new String[AltoLetra];

	for (int i = 0; i < CodigoAscii.length; i++)
	{
		// Recorro todos las filas del esqueleto de letras
		for (int row = 0; row < esqueleto.length; row++)
		{
			if (countLetras == 8)
			{
				row += AltoLetra - 1;
				countLetras = 0;
				countPosiciones = 0;
			}
			//Si no la encuentro tengo que ir aumento la posicion y el numero ascii 
			while ((!LetraEncontrada) && (countLetras < 8))
			{
				if (CodigoAscii[i] == numeroAscii)
				{
					LetraEncontrada = true;
				}
				else
				{
					numeroAscii++;
					countPosiciones += AnchoLetras;
					countLetras++;
				}
			}
			//Si la e encontrado y no tengo las 7 lineas de la letra
			if ((LetraEncontrada) && (countLineas < 7))
			{
				if (i > 0)
				{
					cadena[countLineas] = cadena[countLineas] + esqueleto[row].substring(countPosiciones, countPosiciones + AnchoLetras);
				}
				else
				{
					cadena[countLineas] = esqueleto[row].substring(countPosiciones, countPosiciones + AnchoLetras);
				}
				countLineas++;
			}
		}
		countLineas = 0;
		numeroAscii = 32;
		LetraEncontrada = false;
		countPosiciones = 0;
		countLetras = 0;
	}

	//Muestro
	for (int i = 0; i < cadena.length; i++)
	{
	System.out.println(cadena[i]);
	}
	}
}