Hello, I’m working on this task:
We are prototyping a robot that refills glasses during dinner. Every glass holds 200 milliliters. During dinner, people either drink water or juice, and as soon as there is less than 100 ml left in the glass, the robot refills it back to 200 ml.
Create a class Glass with one public int field LiquidLevel and methods public Drink(int milliliters) that takes the amount of liquid that a person drank and public Refill() that refills the glass to be 200 ml full. Both methods should not return any value. Initially set LiquidLevel to 200.
In the Main method create an object of class Glass and read commands from the screen until the user terminates the program (see next). Don’t forget to refill the glass when needed! Commands are:
- drink followed by a number. It indicates that the person drank that amount of milliliters from the glass. You can use string. Split(’ ') to separate the word and the number.
- print - you need to output to the screen how much liquid is in the glass in the format “This glass contains …ml of liquid.”
- stop - program should quit.
Example 1:
>drink 37
>drink 12
>print
This glass contains 151ml of liquid.
>stop
Example 2:
>drink 50
>drink 51
>print
This glass contains 200ml of liquid.
>stop
Here is my code:
namespace ClassAndObject
{
/* Declare class here */
public class Glass
{
public int LiquidLevel;
public void Drink(int milliliters)
{
}
public void Refill()
{
}
}
public class RefillMyGlass
{
public static void Main()
{
/* Create object and read commands here */
var drinker=new Glass();
drinker.LiquidLevel="200";
Console.Write("drink ")
while(drinker.LiquidLevel==200)
{
drinker.Drink(Console.ReadLine());
}
Console.WriteLine($"This glass contains {drinker.LiquidLevel} ml of liquid");
Console.WriteLine("stop");
}
}
}
Can anyone please help me to solve it?