Hello, I’m working on this task:
The president was happy with your implementation of the TextFramePretifier… for one day. Then he decided that he wants to control the width of the frame. Take the code of the previous task and modify it to take an integer that represents the width of the frame and then print a message in the frame as you did in previous task, but using the given width this time. Write as many words as you can in each line; if there is an empty space, fill it with spaces. The number of words in a message will not exceed 100. All words are guaranteed to be shorter than (frameWidth - 4). Treat spaces as word separators and all other symbols, such as commas or question marks, as part of the word they’re connected to. The text is guaranteed to have only single spaces.
For example:
>15
>You look great today, sir!
Processing text: 1
***************
* You look *
* great *
* today, sir! *
***************
>A zebra does not change its spots.
Processing text: 2
***************
* A zebra *
* does not *
* change its *
* spots. *
***************
>exit
Here is my code:
namespace Static
{
static class TextFramePretifier
{
private static int _textsPretified;
static TextFramePretifier()
{
_textsPretified=0;
}
public static void Prettify(string text, int width)
{
_textsPretified++;
Console.WriteLine($"Processing text: {_textsPretified}");
char[] widthArray= new char[width];
char[] textArray= new char[text.Length];
var line ="*";
var poo=false;
for(var j=1; j<width; j++)
{
line=line+"*";
}
Console.WriteLine(line);
for(var i=0; i<width; i++)
{
while(poo==true)
{
string write =new string(widthArray);
Console.WriteLine(write);
poo=false;
}
if(i==0)
widthArray[i]='*';
else if(i==1)
widthArray[i]=' ';
else if (i>=(width-4)&&i!=width)
widthArray[i]=' ';
else if (i==width)
{
widthArray[i]='*';
poo=true;
i=0;
}
else if (i!=width&&i!=0&&i!=1&&i<(width-4))
widthArray[i]=textArray[i-2];
}
Console.WriteLine(line);
}
}
class PresidentIsWeird
{
public static void Main()
{
var Width =int.Parse(Console.ReadLine());
var text=Console.ReadLine();
while(text !="exit")
{
TextFramePretifier.Prettify(text, Width);
text=Console.ReadLine();
}
}
}
}
Can anyone please help me to solve it?