fork(71) download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public class Tarjeta {
  7. public /*required*/ int Num {
  8. get => this._num;
  9. init {
  10. Debug.Assert( value > 0, "num. de tarjeta debe ser positivo" );
  11. this._num = value;
  12. this.calculaCVC();
  13. }
  14. }
  15.  
  16. public /*required*/ DateOnly Caduca {
  17. get => this._caduca;
  18. init {
  19. Debug.Assert( value > DateOnly.FromDateTime( DateTime.Now ), "caducidad debe ser a futuro" );
  20. this._caduca = value;
  21. }
  22. }
  23.  
  24. public int CVC { get; private set; }
  25.  
  26. public Tarjeta(int num, DateOnly caduca)
  27. {
  28. Debug.Assert( num > 0, "num. de tarjeta debe ser positivo" );
  29. Debug.Assert( caduca > DateOnly.FromDateTime( DateTime.Now ), "caducidad debe ser a futuro" );
  30.  
  31. this.Num = num;
  32. this.Caduca = caduca;
  33. this.calculaCVC();
  34. }
  35.  
  36. private void calculaCVC()
  37. {
  38. this.CVC = this.Num % 1000;
  39. }
  40.  
  41. public override string ToString()
  42. {
  43. return $"{this.Num} ({this.Caduca}, {this.CVC})";
  44. }
  45.  
  46. private int _num;
  47. private DateOnly _caduca;
  48. }
  49.  
  50.  
  51. public class Test
  52. {
  53. public static void Main()
  54. {
  55. /*
  56. var t1 = new Tarjeta {
  57. Num = 548901687,
  58. Caduca = new DateOnly( 2034, 11, 5 )
  59. };
  60. */
  61. var t2 = new Tarjeta( 548901687, new DateOnly( 2034, 11, 5 ) );
  62.  
  63. // Console.WriteLine( t1 );
  64. Console.WriteLine( t2 );
  65. }
  66. }
  67.  
Success #stdin #stdout 0.07s 32560KB
stdin
Standard input is empty
stdout
548901687 (11/5/2034, 687)