Problem 4: Car Engine And Tires C# Advanced
Здравейте колеги. Моля за малко помощ....judge ми дава 66/100 а не мисля че имам разлики от инстрикциите които са дадени в документа със самата задача
Class Startup:
namespace CarManufacturer
{
public class StartUp
{
static void Main(string[] args)
{
Tire[] tires = new Tire[4]
{
new Tire(1, 2.5),
new Tire(1, 2.1),
new Tire(2, 0.5),
new Tire(2, 2.3)
};
Engine engine = new Engine(560, 6300);
Car car = new Car("Lamborghini", "Urus", 2010, 250, 9, engine, tires);
}
}
}
Class Car:
using System.Text;
namespace CarManufacturer
{
public class Car
{
public Car()
{
this.Make = "VW";
this.Model = "Golf";
this.Year = 2025;
this.FuelQuantity = 200;
this.FuelConsumption = 10;
}
public Car(string make, string model, int year)
:this()
{
this.Make = make;
this.Model = model;
this.Year = year;
}
public Car(string make, string model, int year, double fuelQuantity, double fuelConsumption)
:this(make, model, year)
{
this.FuelQuantity = fuelQuantity;
this.FuelConsumption = fuelConsumption;
}
public Car(string make, string model, int year, double fuelQuantity, double fuelConsumption, Engine engine, Tire[] tires)
:this(make, model, year, fuelQuantity, fuelConsumption)
{
this.Engine = engine;
this.Tires = tires;
}
private string make;
private string model;
private int year;
private double fuelQuantity;
private double fuelConsumption;
private Engine engine;
private Tire[] tires;
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public double FuelQuantity { get; set; }
public double FuelConsumption { get; set; }
public Engine Engine { get; set; }
public Tire[] Tires { get; set; }
public void Drive(double distance)
{
bool fuelIsEnough = FuelQuantity - distance * (FuelConsumption / 100) >= 0;
if (fuelIsEnough)
{
FuelQuantity -= distance * (FuelConsumption / 100);
}
else
{
System.Console.WriteLine("Not enough fuel to perform this trip!");
}
}
public string WhoAmI()
{
//return $"Make: {this.Make}\nModel: {this.Model}\nYear: {this.Year}\nFuel: {this.FuelQuantity:F2}L";
var carInfo = new StringBuilder();
carInfo.AppendLine($"Make: {this.Make}");
carInfo.AppendLine($"Model: {this.Model}");
carInfo.AppendLine($"Year: {this.Year}");
carInfo.Append($"Fuel: {this.FuelQuantity:F2}L");
return carInfo.ToString();
}
}
}
Class Engine:
namespace CarManufacturer
{
public class Engine
{
public Engine(int horsePower, double cubicCapacity)
{
this.HorsePower = horsePower;
this.CubicCapacity = cubicCapacity;
}
private int horsepower;
private double cubicCapacity;
public int HorsePower { get; set; }
public double CubicCapacity { get; set; }
}
}
Class Tire:
namespace CarManufacturer
{
public class Tire
{
public Tire(int year, double presure)
{
this.Year = year;
this.Presure = presure;
}
private int year;
private double presure;
public int Year { get; set; }
public double Presure { get; set; }
}
}