Doubt about moving from one class to another c # [closed]

-1

I have a base class called Vehiculos and apart I have another class called Alquiler . It turns out when you make the rent I have to show you what the total rental price would be, this is done by multiplying the daily cost of the vehicle (which is in the class Vehiculos ) by the number of days (it is in the class Alquiler ). To calculate would dia2 - dia1 * daily cost

How can I spend the daily cost for the rental class?

   public double Costodiario
    {
        get { return costodiario; }
        set
        {
            if (value < 25)
                throw new Exception("El costo diario minimo es de 25 dolares");
            else
                costodiario = value;
        }
    }

  public int Dia1
    {
        get { return dia1; }
        set { dia1 = value; }
    }
    public int Mes1
    {
        get { return mes1; }
        set { mes1 = value; }
    }
    public int Anio1
    {
        get { return anio1; }
        set { anio1 = value; }
    }
    public int Dia2
    {
        get { return dia2; }
        set { dia2 = value; }
    }
    public int Mes2
    {
        get { return mes2; }
        set { mes2 = value; }
    }
    public int Anio2
    {
        get { return anio2; }
        set { anio2 = value; }
    }
    
asked by Francop 26.07.2017 в 20:08
source

1 answer

2

In the following code I calculate the cost of renting a vehicle according to its daily cost and a range in days. I have not taken into account the issue of rental schedules but this would be the basic case:

using System;

namespace RentaCar
{
    class Program
    {
        static void Main(string[] args)
        {
            Vehiculo auto = new Vehiculo();
            auto.CostoDiario = 100;
            Alquiler alq = new Alquiler(auto, new DateTime(2017, 7, 1), new DateTime(2017, 7, 3));
            Console.WriteLine("Costo:" + alq.CalcularCosto().ToString());
            Console.ReadKey();
        }
    }

    public class Vehiculo
    {
        public double CostoDiario { get; set; }
    }

    public class Alquiler
    {
        Vehiculo _vehiculo;
        double _dias;

        public Alquiler(Vehiculo pVehiculo, DateTime desde, DateTime hasta)
        {
            this._vehiculo = pVehiculo;
            TimeSpan dif = hasta - desde;
            _dias = dif.TotalDays;
        }

        public double CalcularCosto()
        {
            double total = 0;
            total = _dias * _vehiculo.CostoDiario;
            return total;
        }
    }
}
    
answered by 26.07.2017 в 21:45