herencia en csharp#
DESCRIPTION
PROGRAMACIONTRANSCRIPT
![Page 1: Herencia en Csharp#](https://reader036.vdocument.in/reader036/viewer/2022082822/5695d1561a28ab9b02961b15/html5/thumbnails/1.jpg)
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace Evidencia2{
public class Titular {
private String nombre;
private String apellidos;
private int edad;
public Titular(String nombre, String apellidos, int edad) {
this.nombre = nombre;
this.apellidos = apellidos;
this.edad = edad;
}
public String getNombre() {
return this.nombre;
}
public String getApellidos() {
return this.apellidos;
}
public int getEdad() {
return this.edad;
}
public String toString() {
![Page 2: Herencia en Csharp#](https://reader036.vdocument.in/reader036/viewer/2022082822/5695d1561a28ab9b02961b15/html5/thumbnails/2.jpg)
return "Nombre: " + this.nombre + "\nApellidos: " + this.apellidos + "\nEdad: " + this.edad;
}
}
public static void main(String[] args) {
Titular paco = new Titular("Paco", "Ahorrors", 28);
Titular maria = new Titular("Maria", "Huertas", 32);
CuentaCorriente cuenta1 = new CuentaCorriente("paco", "2454", 2000);
CuentaCorriente cuenta2 = new CuentaCorriente("maria", "4352", 1500);
CuentaAhorro ahorro1 = new CuentaAhorro("maria", "4352", 1500, 3);
}
}}
class CuentaAhorro : CuentaCorriente{
public double interes { get; set; }
public CuentaAhorro(String titular, string nombreCuenta, double saldo, double interes) {
this.titularCuenta = titularCuenta;
this.numeroCuenta = nombreCuenta;
this.saldo = saldo;
this.interes = interes;
![Page 3: Herencia en Csharp#](https://reader036.vdocument.in/reader036/viewer/2022082822/5695d1561a28ab9b02961b15/html5/thumbnails/3.jpg)
}
public CuentaAhorro(String titular, string numeroCuenta, double interes) {
this.titularCuenta = titular;
this.numeroCuenta = numeroCuenta;
this.saldo = 15.3;
this.interes = interes;
}
public CuentaAhorro(String titular, string numeroCuenta) {
this.titularCuenta = titular;
this.numeroCuenta = numeroCuenta;
this.saldo = 15.3;
this.interes = 2.5;
}
public void CalcularIntereses() {
this.saldo += saldo * interes;
}
internal void calcularInteres() { throw new NotImplementedException(); }
internal string getSaldo() { throw new NotImplementedException(); }}
class CuentaCorriente{
![Page 4: Herencia en Csharp#](https://reader036.vdocument.in/reader036/viewer/2022082822/5695d1561a28ab9b02961b15/html5/thumbnails/4.jpg)
public String titularCuenta { get; set; }
public String numeroCuenta { get; set; }
public double saldo { get; set; }
/// Primer constructor con los tres parametros
public CuentaCorriente(string titular, string numeroCuenta, double saldo) {
this.titularCuenta = titular;
this.numeroCuenta = numeroCuenta;
this.saldo = saldo;
}
public CuentaCorriente() { }
/// Segundo constructor con solo 2 parametro
public CuentaCorriente(String titular, string numeroCuenta) {
this.titularCuenta = titular;
this.numeroCuenta = numeroCuenta;
this.saldo = 15.3;
}
/// Incrementa el saldo en una cantidad
public void Ingresar(double cantidad) {
this.saldo += cantidad;
}
/// Reduce el saldo en una cantidad
![Page 5: Herencia en Csharp#](https://reader036.vdocument.in/reader036/viewer/2022082822/5695d1561a28ab9b02961b15/html5/thumbnails/5.jpg)
/// Nota que el saldo si puede ser negativo, es lo que se conoce como numeros rojos :P
public void Reintegro(double cantidad) {
this.saldo -= cantidad;
}
public string ToString() {
return numeroCuenta + " " + saldo;
}
/// Devuelve si una cuenta es igual a otra introducida por parametro o no
public bool CompararCuentas(CuentaCorriente cuentaComparadora) {
return this.numeroCuenta.Equals(cuentaComparadora.numeroCuenta);
}
}