Elon's Toys

in #ita2 months ago

using System;

class RemoteControlCar
{
private int meters=0; // default wäre auch 0
private int percentage=100;

  public RemoteControlCar()
{
   
}
 public RemoteControlCar(int meters, int percentage)
{
    this.meters = meters; 
    this.percentage = percentage;
}
public static RemoteControlCar Buy()
{
   RemoteControlCar car1 = new RemoteControlCar();
   return car1;
}

public string DistanceDisplay()
{
    return "Driven " +meters+  " meters";
}

public string BatteryDisplay()
{
    if(percentage==0)
    return "Battery empty";
    else return "Battery at " + percentage+ "%";
}

public void Drive()
{
  if(percentage!=0)
  {
   percentage -= 1;
   meters+=20; 
  }   
}

}