Advertisement
fcamuso

ContoCorrente

Nov 15th, 2020
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ereditarieta_conto_corrente
  4. {
  5.   class ContoCorrenteException : Exception
  6.   {
  7.     public ContoCorrenteException(string messaggio) { }
  8.   }
  9.  
  10.   class ContoCorrente
  11.   {
  12.     //dati intestatario
  13.     public String Cognome { get; set; } = "";
  14.     public String Nome { get; set; } = "";
  15.  
  16.     //dati conto
  17.  
  18.     public string TipoConto { get; set; } = "normale";
  19.     private double saldo = 0;
  20.     private int NumeroConto { get; set; }
  21.     public static int ProgressivoNumeroConto { get; set; } = 0;
  22.    
  23.     //operazioni sul conto
  24.     public void SetSaldo(double nuovoSaldo)
  25.     {
  26.       if (nuovoSaldo >= 0)
  27.         saldo = nuovoSaldo;
  28.       else throw new ContoCorrenteException("Saldo negativo");
  29.     }
  30.  
  31.     public void Deposita(double cifra)
  32.     {
  33.       if (cifra > 0)
  34.         saldo += cifra;
  35.       else throw new ContoCorrenteException($"Valore deposito non valido: {cifra}");
  36.     }
  37.  
  38.     public bool Preleva(double cifra)
  39.     {
  40.       if (saldo >= cifra || TipoConto=="privilegiato")
  41.       {
  42.         saldo -= cifra;
  43.         return true;
  44.       }
  45.       else return false;
  46.     }
  47.  
  48.     //costruttore
  49.     public ContoCorrente(string tipoConto, string cognome, string nome, double saldo_iniziale=0)
  50.     {
  51.       TipoConto = tipoConto; //normale oppure privilegiato
  52.  
  53.       Cognome = cognome; Nome = nome;
  54.       SetSaldo(saldo_iniziale);
  55.       NumeroConto = ++ProgressivoNumeroConto;
  56.     }
  57.   }
  58.  
  59.   class Madre
  60.   {
  61.     public Madre() { Console.WriteLine("Classe Madre"); }
  62.   }
  63.  
  64.   class Figlia : Madre
  65.   {
  66.    
  67.   }
  68.  
  69.   class Program
  70.   {
  71.     static void Main(string[] args)
  72.     {
  73.      
  74.       ContoCorrente c1 = new ContoCorrente("privilegiato", "Gastone", "Paperone", 100);
  75.       //c1.Deposita(-9);
  76.       //Figlia f = new Figlia();
  77.  
  78.       if (c1.Preleva(101))
  79.         Console.WriteLine("ok");
  80.       else
  81.         Console.WriteLine("Non puoi andare in rosso!");
  82.  
  83.        
  84.     }
  85.   }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement