Hello, I’m working on this task: President is even more weird
It’s look like code should work, but I can’t pass the validation.
Please, help me find what I did wrong.
Here is my code:
namespace Static
{
static class TextFramePretifierTwo
{
private static int _textsPretified;
static TextFramePretifierTwo()
{
_textsPretified = 0;
}
public static void Prettify(string text, int frameWidth)
{
string temp="";
string[] strArray = text.Split(" ");
_textsPretified++;
Console.WriteLine($"Processing text: {_textsPretified}");
for (int i = 0; i < frameWidth; i++)
{
Console.Write("*");
}
Console.WriteLine("");
for (int j=0; j<strArray.Length-1; j++)
{
if ((strArray[j].Length + temp.Length) < frameWidth - 4)
{
temp =temp+strArray[j] + " ";
} else
{
temp=temp.Trim().PadRight(frameWidth-4);
Console.WriteLine($"* {temp} *");
temp = strArray[j]+" ";
}
}
if ((strArray[strArray.Length-1].Length + temp.Length) > frameWidth - 4)
{
temp=temp.Trim().PadRight(frameWidth-4);
Console.WriteLine($"* {temp} *");
Console.WriteLine($"* {strArray[strArray.Length-1].Trim().PadRight(frameWidth-4)} *");
} else {
temp =temp+strArray[strArray.Length-1] + " ";
temp=temp.Trim().PadRight(frameWidth-4);
Console.WriteLine($"* {temp} *");
}
for (int i = 0; i < frameWidth; i++)
{
Console.Write("*");
}
Console.WriteLine("");
}
};
class PresidentIsEvenMoreWeird
{
public static void Main()
{
int frameWidth = Convert.ToInt32(Console.ReadLine());
string text = Console.ReadLine();
while (text != "exit")
{
TextFramePretifierTwo.Prettify(text, frameWidth);
text = Console.ReadLine();
}
// Write your code here
}
}
}
Can anyone please help me to solve it?