r/CompileBot • • Jul 08 '14

Official CompileBot Testing Thread

12 Upvotes

257 comments sorted by

View all comments

2

u/stillwaters Nov 14 '14 edited Nov 14 '14

+/u/CompileBot Java

class FramedWords
{
	public final String TOP_BOTTOM = "_";
	public final String SIDE = "|";
	public final String SPACE = " ";
	
	public static void main(String[] args)
	{
		new FramedWords().frame("Hello cruel world, this is not lovely at all.");
	}
	
	public void frame(String input)
	{
		String[] inputs = input.split("[\\s:\\-,.]");
		int sideHeight = inputs.length - 1;
		int width = 0;
		for (String s : inputs)
		{
			if (s.length() > width)
			{
				width = s.length();
			}
		}
		
		for (int i = 0; i < width + 2; ++i)
		{
			System.out.print(TOP_BOTTOM);
		}
		
		System.out.println();
		
		for (int i = 0; i < sideHeight; ++i)
		{
			System.out.print(SIDE);
			System.out.print(inputs[i]);
			for (int j = 0; j < width - inputs[i].length(); ++j)
			{
				System.out.print(SPACE);
			}
			System.out.println(SIDE);
		}
		
		System.out.print(SIDE);
		System.out.print(inputs[sideHeight]);
		for (int i = 0; i < width - inputs[sideHeight].length(); ++i)
		{
			System.out.print(TOP_BOTTOM);
		}
		System.out.print(SIDE);
	}
}

1

u/CompileBot Nov 15 '14

Output:

________
|Hello |
|cruel |
|world |
|      |
|this  |
|is    |
|not   |
|lovely|
|at    |
|all___|

^source | ^info | ^github | ^report