Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# Only please Create the following methods. You will need to create a console a

ID: 3740079 • Letter: C

Question

C# Only please

Create the following methods. You will need to create a console application that can execute all of the following

methods, drawing different types of boxes.


1. Create the static method DrawBox that displays a solid square of asterisks whose side length is 5.
2. Overload the static method DrawBox that displays a solid square (the same number of rows and columns) of
asterisks whose side length is specified in the integer parameter side.
3. Overload the method DrawBox that displays a solid square (the same number of rows and columns) of the
character fillCharacter (char) whose side length is specified in the integer parameter side.
4. Overload the method DrawBox that displays a solid rectangle of asterisks whose row’s length and column’s
length is specified in the integer parameters, rows and cols.
5. Overload the method DrawBox that displays a solid rectangle of the character fillCharacter (char) whose
row’s length and column’s length is specified in the integer parameters, rows and cols.
6. Can you consolidate all the functions in 1—5 using default / optional arguments into one big method?
Hint: use the expression char.Parse(Console.ReadLine()) to read a character from the user. A variable of
type char can store a single character’s value.
We will assume that all inputs are valid. That is, we will assume that all the values of the side, the rows, and the
cols are positive.

Explanation / Answer

//Code to copy

//program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shapes
{
public class ShapeDrawer
{
static void Main(string[] args)
{
int rows;
int cols;
int side;
char fillChar;

while (true)
{
/**Calling menu function*/
int ch = menu();

switch (ch)
{
case 1:
/**Calling DrawBox*/
DrawBox();
break;

case 2:
//prompt for height and width value
Console.WriteLine("Enter the side of Box :");
side = Convert.ToInt32(Console.ReadLine());
/**Calling DrawBox*/
DrawBox(side);
break;

case 3:

//prompt for side of square
Console.WriteLine("Enter the side of Box :");
side = Convert.ToInt32(Console.ReadLine());
//prompt for fill character
Console.WriteLine("Enter the fill character of Box :");
fillChar = char.Parse(Console.ReadLine());
DrawBox(side, fillChar);
break;

case 4:
//prompt for rows
Console.WriteLine("Enter the rows of Box :");
rows = Convert.ToInt32(Console.ReadLine());
//prompt for rows
Console.WriteLine("Enter the cols of Box :");
cols = Convert.ToInt32(Console.ReadLine());
//Calling DrawBox with rows and cols
DrawBox(rows, cols);
break;


case 5:
//prompt for rows
Console.WriteLine("Enter the rows of Box :");
rows = Convert.ToInt32(Console.ReadLine());
//prompt for rows
Console.WriteLine("Enter the cols of Box :");
cols = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the fill character of Box :");
fillChar = char.Parse(Console.ReadLine());

DrawBox(rows, cols, fillChar);
break;

case 6:
Environment.Exit(0);
break;
}

}

  

Console.ReadKey();
}


public static int menu()
{

string choice;
int ch;
do
{
Console.WriteLine("1.DrawBox ");
Console.WriteLine("2.DrawBox(side) ");
Console.WriteLine("3.DrawBox(side,fillChar)");
Console.WriteLine("4.DrawBox(rows,cols) ");
Console.WriteLine("5.DrawBox(rows,cols,fillChar) ");
Console.WriteLine("6.Exit ");
Console.WriteLine("Enter your choice [1-6] : ");
choice = Console.ReadLine();
int.TryParse(choice, out ch);

} while (ch < 1 || ch > 6);


return ch;
}


/**The method takes rows and cols and fill char as input
and print the box*/
public static void DrawBox(int rows, int cols,char fillChar)
{
char symbol = fillChar;
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
Console.Write("{0}", symbol);

Console.WriteLine();
}

Console.WriteLine();
}


/**The method takes rows and cols as input
and prints box */
public static void DrawBox(int rows, int cols)
{
char symbol = '*';
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
Console.Write("{0}", symbol);

Console.WriteLine();
}

Console.WriteLine();
}


/**The method print the box with side as input*/
public static void DrawBox(int side)
{
char symbol = '*';
for (int row = 0; row < side; row++)
{
for (int col = 0; col < side; col++)
Console.Write("{0}", symbol);

Console.WriteLine();
}

Console.WriteLine();
}


/**The method takes side and fill char and creates
the box and */
public static void DrawBox(int side, char fillChar)
{
char symbol =fillChar ;
for (int row = 0; row < side; row++)
{
for (int col = 0; col < side; col++)
Console.Write("{0}", fillChar);

Console.WriteLine();
}

Console.WriteLine();
}

/**The method prints the box with side
* as lenght and width*/
public static void DrawBox()
{
char symbol = '*';
for (int row = 0; row < 5; row++)
{
for (int col = 0; col < 5; col++)
Console.Write("{0}", symbol);

Console.WriteLine();
}

Console.WriteLine();
}
}
}

-------------------------------------------------------------------------------

Sample Output :

1.DrawBox
2.DrawBox(side)
3.DrawBox(side,fillChar)
4.DrawBox(rows,cols)
5.DrawBox(rows,cols,fillChar)
6.Exit
Enter your choice [1-6] :
1
*****
*****
*****
*****
*****

1.DrawBox
2.DrawBox(side)
3.DrawBox(side,fillChar)
4.DrawBox(rows,cols)
5.DrawBox(rows,cols,fillChar)
6.Exit
Enter your choice [1-6] :
2
Enter the side of Box :
5
*****
*****
*****
*****
*****

1.DrawBox
2.DrawBox(side)
3.DrawBox(side,fillChar)
4.DrawBox(rows,cols)
5.DrawBox(rows,cols,fillChar)
6.Exit
Enter your choice [1-6] :
3
Enter the side of Box :
5
Enter the fill character of Box :
*
*****
*****
*****
*****
*****

1.DrawBox
2.DrawBox(side)
3.DrawBox(side,fillChar)
4.DrawBox(rows,cols)
5.DrawBox(rows,cols,fillChar)
6.Exit
Enter your choice [1-6] :
4
Enter the rows of Box :
5
Enter the cols of Box :
4
****
****
****
****
****

1.DrawBox
2.DrawBox(side)
3.DrawBox(side,fillChar)
4.DrawBox(rows,cols)
5.DrawBox(rows,cols,fillChar)
6.Exit
Enter your choice [1-6] :
5
Enter the rows of Box :
4
Enter the cols of Box :
5
Enter the fill character of Box :
+
+++++
+++++
+++++
+++++

1.DrawBox
2.DrawBox(side)
3.DrawBox(side,fillChar)
4.DrawBox(rows,cols)
5.DrawBox(rows,cols,fillChar)
6.Exit
Enter your choice [1-6] :