Please help me with the task: Lack of visualization

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
>print
| |
|##|
|##|
|##|
>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?

This code works when run elsewhere, so I don’t understand why the codeeasy lesson tells me it is wrong?

Hi @eliza1 ,

Great job on the solution! It is correct, and when you call it, CodeEasy says

  • Method ‘Drink’ does not exist, has the wrong return type, access modifiers, or arguments.

Taking a closer look at your drink method, I noticed that the name of the parameter is not milliliters millilitres

Once you fix this, the solution is treated as “correct”. And yes, if you argue that this is not important, I would agree, but unfortunately, this is how our system works at the moment, and sometimes it is more strict than it should be.

Happy coding!

1 Like