Created with <3 with dartpad.dev.
Created
October 26, 2023 02:32
-
-
Save leonus96/127b5f498db97825e8bd94bd28205824 to your computer and use it in GitHub Desktop.
POO: Cta.Bancaria
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Persona { | |
| String nombre; | |
| String dni; | |
| Persona(this.nombre, this.dni); | |
| } | |
| class CuentaBancaria { | |
| String numero; | |
| Persona titular; | |
| double _saldo; /// _ cuando queremos que un dato sea privado. | |
| CuentaBancaria(this.numero, this.titular, this._saldo); | |
| void depositar(double cantidad) { | |
| _saldo = _saldo + cantidad; | |
| } | |
| void retirar(double cantidad) { | |
| _saldo = _saldo - cantidad; | |
| } | |
| void imprimeSaldo() { | |
| print('El saldo de la cuenta $numero es S/$_saldo'); | |
| } | |
| } | |
| void main() { | |
| final Persona persona1 = Persona('Joseph', '73033257'); | |
| final CuentaBancaria cta1 = CuentaBancaria('123', persona1, 0); | |
| print('N. cuenta: ${cta1.numero}'); | |
| print('Titular de la cuenta: ${cta1.titular.nombre}'); | |
| cta1.imprimeSaldo(); | |
| cta1.depositar(100.0); | |
| cta1.imprimeSaldo(); | |
| cta1.retirar(30.0); | |
| cta1.imprimeSaldo(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment