Hello, I’m working on this task:
Users of your glass-refilling program were quite happy, but their feedback indicates that they dislike the raw math figures. Using your previous program as a basis, instead of printing a message to the screen when the user inputs print, draw a glass using ASCII art. Represent the glass as a vertical bar (see example) and fill it with ‘#’ symbols proportional to how much liquid it has. The height of the glass should be 4 symbols, the width 4 symbols, and all empty space inside the glass should be filled with spaces.
Example 1:
>drink 37
| |
|##|
|##|
|##|
>stop
Example 2:
>drink 145
>print
|##|
|##|
|##|
|##|
>stop
Here is my code:
namespace ClassAndObjectAndAsciiArt
{
class Glass
{
public int LiquidLevel;
public void Drink(int millilitres)
{
LiquidLevel=LiquidLevel-millilitres;
}
public void Refill()
{
LiquidLevel=200;
}
public void Visualise()
{
for (int i = 0; i < 4 - LiquidLevel/50; i++)
{
Console.WriteLine("| |");
}
for (int i = 0; i < LiquidLevel/50; i++)
{
Console.WriteLine("|##|");
}
}
}
public class LackOfVisualization
{
public static void Main()
{
var glass = new Glass();
glass.LiquidLevel=200;
var input=string.Empty;
while(input != "stop")
{
input=Console.ReadLine();
var splitInput = input.Split(' ');
switch(splitInput[0])
{
case ("drink"):
glass.Drink(int.Parse(splitInput[1]));
if(glass.LiquidLevel<100)
glass.Refill();
break;
case ("stop"):
return;
case ("print"):
glass.Visualise();
break;
}
}
}
}
}
Can anyone please help me to solve it?