Pass default values to child class functions in C # [closed]

1

I have a EmpleadoProgramador class that inherits from Empleado , with a CalcularSueldo() function that calculates the salary. I need it to have default values, without needing to pass them by argument.

I could only make it work by passing values to the function. With the constructor variables by default, it does not work for me. Also, it only takes the values that I assigned in the controller (first and last name). Why does not the constructor work well?

Controller:

using System.Web;
using System.Web.Mvc;
using Empresa2.Models;

namespace Empresa2.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        //public ActionResult Index()
        //{
        //    return View();
        //}

        public ActionResult Programador()
        {
            EmpleadoProgramador emp1prog = new EmpleadoProgramador();
            emp1prog.Nombre = "Ezequiel";
            emp1prog.Apellido = "Perez";
            emp1prog.SueldoFijo = 15000;
            float suel=emp1prog.CalcularSueldo("Adrian", "suarez",20,40,5000);
            float suel2 = emp1prog.CalcularSueldo(emp1prog.Nombre, "suarez", 20, 40, 5000); 
            emp1prog.SueldoFijo = suel;
            // emp1prog.ObtenerSueldo();
            return View(emp1prog);
        }    
    }    
}

Employee:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Empresa2.Models
{
    public abstract class Empleado
    {
        public string Nombre { set; get; }
        public string Apellido { set; get; }
        public Empleado() { }

        public Empleado(string Nombre, string Apellido)
        {
            Nombre = this.Nombre;
            Apellido = this.Apellido;
        }

        /*  public abstract float CalcularSueldo();
    } */
}

Programmer employee:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Empresa2.Models
{
    public class EmpleadoProgramador : Empleado
    {
        private float sueldoFijo;

        public float SueldoFijo
        {
            get { return sueldoFijo; }
            set { sueldoFijo = value; }
        }

        private EmpleadoProgramador(string Nombre, string Apellido, int horas, float valorHora, float incentivo)
            : base(Nombre, Apellido)
        {
            //Constructor por defecto
            valorHora = 50;
            incentivo = 5000;
            CalcularSueldo(Nombre, Apellido, horas, valorHora, incentivo);
        }
        public EmpleadoProgramador()
        {
        }
        public float CalcularSueldo(string Nombre, string Apellido, int horas, float valorHora, float incentivo)
        {

            float Sueldo = (valorHora * horas) + incentivo;
            return Sueldo;
        }
    }
}

View:

@model Empresa2.Models.EmpleadoProgramador

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Programador</title>
    </head>
    <body>
        <div>
            @Model.Nombre
            <br />
            @Model.Apellido
            <br />
            @Model.SueldoFijo
            <br />
        </div>
    </body>
</html>
    
asked by Andrés Oporto 09.05.2017 в 01:00
source

0 answers