I'm storing the following information about a small car:
max speed = 100
fuel efficiency = 50
mpg = 30
reliability factor = 7
I have a class SmallCar that inherits a IVehicle interface. I'm stuck on how to add the constructors. Can someone please help:
[code]
namespace Assets.Classes
{
public interface IVehicle
{
int MaxSpeed { get; set;}
int FuelEfficiency {get; set;}
double ReliabilityFactor { get; set; }
double LifeSpan { get; set; }
}
public class SmallCar : IVehicle
{
protected int maxSpeed { get; set; }
protected int fuelEfficiency { get; set; }
protected double reliabilityFactor { get; set; }
protected double lifeSpan { get; set; }
class SmallCar : IVehicle
Here's where I'm stuck trying to add constructor logic
}
}
}
[/code]
Loading
VulpesPosted Aug 17, 2011, 11:27 AM
Jonathas SucupiraPosted Aug 17, 2011, 11:04 AM
Hope this helps.
public enum EngineTypes
{
InternalCombustionEngines = 0,
DieselEngines,
HybridVehicleEngines,
EletricEngine
}
public enum FuelTypes
{
Gasoline = 0,
Ethanol,
Methanol,
Eletric
}
public enum VehicleType
{
SmallCar = 0,
MidSize,
SUV,
PickupTruck,
Truck,
Motocycle
}
public class Vehicle
{
public int MaxSpeed { get; set; }
public double ReliabilityFactor { get; set; }
public string Manufacturer { get; set; }
public VehicleType CarType { get; set; }
public int FuelEfficiency { get; private set; }
public FuelTypes Fuel {get;set;}
public EngineTypes Engine { get; set; }
public void CalculateFuelEfficiency()
{
if (Fuel == FuelTypes.Gasoline)
{
switch (Engine)
{
case EngineTypes.InternalCombustionEngines:
if (CarType == VehicleType.SmallCar)
{
FuelEfficiency = 34;
}
break;
case EngineTypes.DieselEngines:
break;
case EngineTypes.HybridVehicleEngines:
break;
case EngineTypes.EletricEngine:
break;
default:
break;
}
}
}
}
public class SmallCar : Vehicle
{
public const double LifeSpan = 5;
public SmallCar()
{
Fuel = FuelTypes.Gasoline;
Engine = EngineTypes.InternalCombustionEngines;
MaxSpeed = -1;
ReliabilityFactor = -1;
Manufacturer = string.Empty;
CarType = VehicleType.SmallCar;
}
}
class Program
{
static void Main(string[] args)
{
var civic = new SmallCar
}